diff mbox series

[v2] selftests: uevent: use shared makefile library

Message ID 20231221204908.341677-2-antonio.terceiro@linaro.org
State New
Headers show
Series [v2] selftests: uevent: use shared makefile library | expand

Commit Message

Antonio Terceiro Dec. 21, 2023, 8:49 p.m. UTC
This makes the uevent selftests build not write to the source tree
unconditionally, as that breaks out of tree builds when the source tree
is read-only. It also avoids leaving a git repository in a dirty state
after a build.

v2: drop spurious extra SPDX-License-Identifier

Signed-off-by: Antonio Terceiro <antonio.terceiro@linaro.org>
---
 tools/testing/selftests/uevent/Makefile | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

Comments

Shuah Khan Dec. 21, 2023, 9:44 p.m. UTC | #1
On 12/21/23 13:49, Antonio Terceiro wrote:
> This makes the uevent selftests build not write to the source tree
> unconditionally, as that breaks out of tree builds when the source tree
> is read-only. It also avoids leaving a git repository in a dirty state
> after a build.
> 

Why can't you do that using make O= directive.

> v2: drop spurious extra SPDX-License-Identifier
> 
> Signed-off-by: Antonio Terceiro <antonio.terceiro@linaro.org>
> ---
>   tools/testing/selftests/uevent/Makefile | 15 +++------------
>   1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/testing/selftests/uevent/Makefile b/tools/testing/selftests/uevent/Makefile
> index f7baa9aa2932..872969f42694 100644
> --- a/tools/testing/selftests/uevent/Makefile
> +++ b/tools/testing/selftests/uevent/Makefile
> @@ -1,17 +1,8 @@
>   # SPDX-License-Identifier: GPL-2.0
>   all:
>   
> -include ../lib.mk
> -
> -.PHONY: all clean
> -
> -BINARIES := uevent_filtering
> -CFLAGS += -Wl,-no-as-needed -Wall
> +CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
>   
> -uevent_filtering: uevent_filtering.c ../kselftest.h ../kselftest_harness.h
> -	$(CC) $(CFLAGS) $< -o $@
> +TEST_GEN_PROGS = uevent_filtering
>   
> -TEST_PROGS += $(BINARIES)
> -EXTRA_CLEAN := $(BINARIES)
> -
> -all: $(BINARIES)
> +include ../lib.mk

This change doesn't get the intended result of not writing to
source tree. Binaries will still be written to the source
tree unless O= is specified.

thanks,
-- Shuah
Antonio Terceiro Dec. 22, 2023, 11:50 a.m. UTC | #2
On Thu, Dec 21, 2023 at 02:44:52PM -0700, Shuah Khan wrote:
> On 12/21/23 13:49, Antonio Terceiro wrote:
> > This makes the uevent selftests build not write to the source tree
> > unconditionally, as that breaks out of tree builds when the source tree
> > is read-only. It also avoids leaving a git repository in a dirty state
> > after a build.
> > 
> 
> Why can't you do that using make O= directive.

That's what I meant by out of tree builds. When using O=, the uevent
selftests build still writes to the source directory. Maybe my wording
in the commit message is not clear enough, I will try to improve it.

> > v2: drop spurious extra SPDX-License-Identifier
> > 
> > Signed-off-by: Antonio Terceiro <antonio.terceiro@linaro.org>
> > ---
> >   tools/testing/selftests/uevent/Makefile | 15 +++------------
> >   1 file changed, 3 insertions(+), 12 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/uevent/Makefile b/tools/testing/selftests/uevent/Makefile
> > index f7baa9aa2932..872969f42694 100644
> > --- a/tools/testing/selftests/uevent/Makefile
> > +++ b/tools/testing/selftests/uevent/Makefile
> > @@ -1,17 +1,8 @@
> >   # SPDX-License-Identifier: GPL-2.0
> >   all:
> > -include ../lib.mk
> > -
> > -.PHONY: all clean
> > -
> > -BINARIES := uevent_filtering
> > -CFLAGS += -Wl,-no-as-needed -Wall
> > +CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
> > -uevent_filtering: uevent_filtering.c ../kselftest.h ../kselftest_harness.h
> > -	$(CC) $(CFLAGS) $< -o $@
> > +TEST_GEN_PROGS = uevent_filtering
> > -TEST_PROGS += $(BINARIES)
> > -EXTRA_CLEAN := $(BINARIES)
> > -
> > -all: $(BINARIES)
> > +include ../lib.mk
> 
> This change doesn't get the intended result of not writing to
> source tree. Binaries will still be written to the source
> tree unless O= is specified.

It does in my tests. Maybe I am missing something.

mainline without the patch:

----------------8<----------------8<----------------8<-----------------
$ make -s defconfig O=/tmp/output && make -s kselftest-all TARGETS=uevent O=/tmp/output
make[4]: Entrando no diretório '/home/terceiro/src/linaro/linux/tools/testing/selftests/uevent'

make[4]: Nada a ser feito para 'all'.
make[4]: Saindo do diretório '/home/terceiro/src/linaro/linux/tools/testing/selftests/uevent'

$ git status --ignored
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	tools/testing/selftests/uevent/uevent_filtering

nothing added to commit but untracked files present (use "git add" to track)
$ git clean -dxf
Removing tools/testing/selftests/uevent/uevent_filtering
----------------8<----------------8<----------------8<-----------------

mainline with the patch:

----------------8<----------------8<----------------8<-----------------
$ git branch -m kselftest-uvent kselftest-uvent-o
$ rm -rf /tmp/output/
$ make -s defconfig O=/tmp/output && make -s kselftest-all TARGETS=uevent O=/tmp/output
make[4]: Entrando no diretório '/home/terceiro/src/linaro/linux/tools/testing/selftests/uevent'

gcc -Wl,-no-as-needed -Wall -isystem /tmp/output/usr/include     uevent_filtering.c  -o /tmp/output/kselftest/uevent/uevent_filtering
make[4]: Saindo do diretório '/home/terceiro/src/linaro/linux/tools/testing/selftests/uevent'

$ git status --ignored
On branch kselftest-uvent-o
nothing to commit, working tree clean
$ git clean -dxf
$
----------------8<----------------8<----------------8<-----------------
Muhammad Usama Anjum Dec. 30, 2023, 7:16 a.m. UTC | #3
On 12/22/23 1:49 AM, Antonio Terceiro wrote:
> This makes the uevent selftests build not write to the source tree
> unconditionally, as that breaks out of tree builds when the source tree
> is read-only. It also avoids leaving a git repository in a dirty state
> after a build.
I can see what you are trying to do. The makefile has issues such as lib.mk
should be included at the end of the file. Please just clarify this in the
message.

> 
> v2: drop spurious extra SPDX-License-Identifier
> 
> Signed-off-by: Antonio Terceiro <antonio.terceiro@linaro.org>
> ---
>  tools/testing/selftests/uevent/Makefile | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/testing/selftests/uevent/Makefile b/tools/testing/selftests/uevent/Makefile
> index f7baa9aa2932..872969f42694 100644
> --- a/tools/testing/selftests/uevent/Makefile
> +++ b/tools/testing/selftests/uevent/Makefile
> @@ -1,17 +1,8 @@
>  # SPDX-License-Identifier: GPL-2.0
>  all:
>  
> -include ../lib.mk
> -
> -.PHONY: all clean
> -
> -BINARIES := uevent_filtering
> -CFLAGS += -Wl,-no-as-needed -Wall
> +CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
>  
> -uevent_filtering: uevent_filtering.c ../kselftest.h ../kselftest_harness.h
> -	$(CC) $(CFLAGS) $< -o $@
> +TEST_GEN_PROGS = uevent_filtering
>  
> -TEST_PROGS += $(BINARIES)
> -EXTRA_CLEAN := $(BINARIES)
> -
> -all: $(BINARIES)
> +include ../lib.mk
diff mbox series

Patch

diff --git a/tools/testing/selftests/uevent/Makefile b/tools/testing/selftests/uevent/Makefile
index f7baa9aa2932..872969f42694 100644
--- a/tools/testing/selftests/uevent/Makefile
+++ b/tools/testing/selftests/uevent/Makefile
@@ -1,17 +1,8 @@ 
 # SPDX-License-Identifier: GPL-2.0
 all:
 
-include ../lib.mk
-
-.PHONY: all clean
-
-BINARIES := uevent_filtering
-CFLAGS += -Wl,-no-as-needed -Wall
+CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
 
-uevent_filtering: uevent_filtering.c ../kselftest.h ../kselftest_harness.h
-	$(CC) $(CFLAGS) $< -o $@
+TEST_GEN_PROGS = uevent_filtering
 
-TEST_PROGS += $(BINARIES)
-EXTRA_CLEAN := $(BINARIES)
-
-all: $(BINARIES)
+include ../lib.mk