selftests: Fix seccomp to support relocatable build (O=objdir)
Subsystems (5)
Shuah Khan
maintainerPATCH v3 1/1 selftests: Fix seccomp to support relocatable build (O=objdir)
Fix seccomp relocatable builds. This is a simple fix to use the right lib.mk variable TEST_GEN_PROGS with dependency on kselftest_harness.h header, and defining LDFLAGS for pthread lib.
Removes custom clean rule which is no longer necessary with the use of TEST_GEN_PROGS.
Uses $(OUTPUT) defined in lib.mk to handle build relocation.
The following use-cases work with this change:
In seccomp directory:
make all and make clean
From top level from main Makefile:
make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccomp
---
Changes since v2:
-- Using TEST_GEN_PROGS is sufficient to generate objects.
Addresses review comments from Kees Cook.
tools/testing/selftests/seccomp/Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
tools/testing/selftests/seccomp/Makefile +8 -10
@@ -1,17 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 -all: - -include ../lib.mk +CFLAGS += -Wl,-no-as-needed -Wall +LDFLAGS += -lpthread .PHONY: all clean -BINARIES := seccomp_bpf seccomp_benchmark -CFLAGS += -Wl,-no-as-needed -Wall +include ../lib.mk + +# OUTPUT set by lib.mk +TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark -seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h - $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@ +$(TEST_GEN_PROGS): ../kselftest_harness.h -TEST_PROGS += $(BINARIES) -EXTRA_CLEAN := $(BINARIES) +all: $(TEST_GEN_PROGS) -all: $(BINARIES)
Signature · 1 line
2.20.1
Quoted 33 lines · Shuah Khan
Fix seccomp relocatable builds. This is a simple fix to use the right lib.mk variable
TEST_GEN_PROGSwith dependency onkselftest_harness.hheader, and defining LDFLAGS for pthread lib.Removes custom clean rule which is no longer necessary with the use of
TEST_GEN_PROGS.Uses $(OUTPUT) defined in lib.mk to handle build relocation.
The following use-cases work with this change:
In seccomp directory:
make all and make cleanFrom top level from main
Makefile:
make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccompSigned-off-by Shuah Khan <[email protected]>---
Changes since v2:
-- UsingTEST_GEN_PROGSis sufficient to generate objects.
Addresses review comments from Kees Cook.tools/testing/selftests/seccomp/Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)tools/testing/selftests/seccomp/Makefile +0
-0
tools/testing/selftests/seccomp/Makefile line 5
Quoted 8 lines
tools/testing/selftests/seccomp/Makefile +2
-3@@ -1,17 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 -all: - -include ../lib.mk +CFLAGS += -Wl,-no-as-needed -Wall +LDFLAGS += -lpthread .PHONY: all clean
Isn't this line redundant to ../lib.mk's?
Quoted 5 lines
tools/testing/selftests/seccomp/Makefile +2
-2-BINARIES := seccomp_bpf seccomp_benchmark -CFLAGS += -Wl,-no-as-needed -Wall +include ../lib.mk +
tools/testing/selftests/seccomp/Makefile line 14
Quoted 10 lines
tools/testing/selftests/seccomp/Makefile +4
-4+# OUTPUT set by lib.mk +TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark -seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h - $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@ +$(TEST_GEN_PROGS): ../kselftest_harness.h -TEST_PROGS += $(BINARIES) -EXTRA_CLEAN := $(BINARIES) +all: $(TEST_GEN_PROGS)
And isn't this one too?
I think if those are removed it should all still work? Regardless:
-Kees
Quoted 5 lines
tools/testing/selftests/seccomp/Makefile +0
-1-all: $(BINARIES)Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
Shuah Khan
maintainerQuoted 57 lines · Kees Cook
Quoted 33 lines · Shuah Khan
Fix seccomp relocatable builds. This is a simple fix to use the right lib.mk variable
TEST_GEN_PROGSwith dependency onkselftest_harness.hheader, and defining LDFLAGS for pthread lib.Removes custom clean rule which is no longer necessary with the use of
TEST_GEN_PROGS.Uses $(OUTPUT) defined in lib.mk to handle build relocation.
The following use-cases work with this change:
In seccomp directory:
make all and make cleanFrom top level from main
Makefile:
make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccompSigned-off-by Shuah Khan <[email protected]>---
Changes since v2:
-- UsingTEST_GEN_PROGSis sufficient to generate objects.
Addresses review comments from Kees Cook.tools/testing/selftests/seccomp/Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)tools/testing/selftests/seccomp/Makefile +0
-0tools/testing/selftests/seccomp/Makefile line 5
Quoted 8 lines
tools/testing/selftests/seccomp/Makefile +2
-3@@ -1,17 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 -all: - -include ../lib.mk +CFLAGS += -Wl,-no-as-needed -Wall +LDFLAGS += -lpthread .PHONY: all cleanIsn't this line redundant to ../lib.mk's?
Quoted 12 lines
tools/testing/selftests/seccomp/Makefile +5
-4-BINARIES := seccomp_bpf seccomp_benchmark -CFLAGS += -Wl,-no-as-needed -Wall +include ../lib.mk + +# OUTPUT set by lib.mk +TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark -seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h - $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@ +$(TEST_GEN_PROGS): ../kselftest_harness.h
Quoted 5 lines
tools/testing/selftests/seccomp/Makefile line 13
Quoted 3 lines
tools/testing/selftests/seccomp/Makefile +1
-2-TEST_PROGS += $(BINARIES) -EXTRA_CLEAN := $(BINARIES) +all: $(TEST_GEN_PROGS)And isn't this one too?
make in seccomp directory won't work. lib.mk won't build it. One reason why I wanted to clearly call this out as CUSTOM program.
But it does make sense to reduce additional EXTRA_CLEAN by just using TEST_GEN_PROGS.
Quoted 3 lines
I think if those are removed it should all still work? Regardless:
diff Makefile
tools/testing/selftests/seccomp/Makefile +2 -2
@@ -2,7 +2,7 @@ CFLAGS += -Wl,-no-as-needed -Wall LDFLAGS += -lpthread -.PHONY: all clean +#.PHONY: all clean include ../lib.mk
@@ -11,5 +11,5 @@ TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark $(TEST_GEN_PROGS): ../kselftest_harness.h -all: $(TEST_GEN_PROGS) +#$all: $(TEST_GEN_PROGS)
With this:
make
make: Nothing to be done for 'all'.
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>
I am addressing your comment about other tests that de[end on kselftest_harness.h. I have a few patches ready to be sent.
thanks,
-- Shuah
Quoted 48 lines · Shuah Khan
Fix seccomp relocatable builds. This is a simple fix to use the right lib.mk variable
TEST_GEN_PROGSwith dependency onkselftest_harness.hheader, and defining LDFLAGS for pthread lib.Removes custom clean rule which is no longer necessary with the use of
TEST_GEN_PROGS.Uses $(OUTPUT) defined in lib.mk to handle build relocation.
The following use-cases work with this change:
In seccomp directory:
make all and make cleanFrom top level from main
Makefile:
make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccompSigned-off-by Shuah Khan <[email protected]>---
Changes since v2:
-- UsingTEST_GEN_PROGSis sufficient to generate objects.
Addresses review comments from Kees Cook.tools/testing/selftests/seccomp/Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)tools/testing/selftests/seccomp/Makefile +6
-5@@ -1,17 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 -all: - -include ../lib.mk +CFLAGS += -Wl,-no-as-needed -Wall +LDFLAGS += -lpthread .PHONY: all clean -BINARIES := seccomp_bpf seccomp_benchmark -CFLAGS += -Wl,-no-as-needed -Wall +include ../lib.mk + +# OUTPUT set by lib.mk +TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark
tools/testing/selftests/seccomp/Makefile line 17
Quoted 10 lines
tools/testing/selftests/seccomp/Makefile +2
-5-seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h - $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@ +$(TEST_GEN_PROGS): ../kselftest_harness.h -TEST_PROGS += $(BINARIES) -EXTRA_CLEAN := $(BINARIES) +all: $(TEST_GEN_PROGS) -all: $(BINARIES)
It shouldn't be that complicated. We just need to define TEST_GEN_PROGS before including lib.mk, and then add the dependency on the harness after we include lib.mk (so that TEST_GEN_PROGS has been updated to prefix $(OUTPUT)).
eg:
# SPDX-License-Identifier: GPL-2.0
CFLAGS += -Wl,-no-as-needed -Wall
LDFLAGS += -lpthread
TEST_GEN_PROGS := seccomp_bpf seccomp_benchmark
include ../lib.mk
$(TEST_GEN_PROGS): ../kselftest_harness.h
Normal in-tree build:
selftests$ make TARGETS=seccomp
make[1]: Entering directory '/home/michael/linux/tools/testing/selftests/seccomp'
gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_bpf gcc -Wl,-no-as-needed -Wall -lpthread seccomp_benchmark.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_benchmark
make[1]: Leaving directory '/home/michael/linux/tools/testing/selftests/seccomp'
selftests$ ls -l seccomp/
total 388
-rw-rw-r-- 1 michael michael 41 Jan 9 12:00 config
-rw-rw-r-- 1 michael michael 201 Mar 16 23:04 Makefile
-rwxrwxr-x 1 michael michael 70824 Mar 16 23:07 seccomp_benchmark*
-rw-rw-r-- 1 michael michael 2289 Feb 17 21:39 seccomp_benchmark.c
-rwxrwxr-x 1 michael michael 290520 Mar 16 23:07 seccomp_bpf* -rw-rw-r-- 1 michael michael 94778 Mar 5 23:33 seccomp_bpf.c
O= build:
selftests$ make TARGETS=seccomp O=$PWD/build
make[1]: Entering directory '/home/michael/linux/tools/testing/selftests/seccomp'
gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/build/seccomp/seccomp_bpf gcc -Wl,-no-as-needed -Wall -lpthread seccomp_benchmark.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/build/seccomp/seccomp_benchmark
make[1]: Leaving directory '/home/michael/linux/tools/testing/selftests/seccomp'
selftests$ ls -l build/seccomp/
total 280
-rwxrwxr-x 1 michael michael 70824 Mar 16 23:05 seccomp_benchmark* -rwxrwxr-x 1 michael michael 290520 Mar 16 23:05 seccomp_bpf*
Build in the directory itself:
selftests$ cd seccomp
seccomp$ make
gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_bpf gcc -Wl,-no-as-needed -Wall -lpthread seccomp_benchmark.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_benchmark
seccomp$ ls -l
total 388
-rw-rw-r-- 1 michael michael 41 Jan 9 12:00 config
-rw-rw-r-- 1 michael michael 201 Mar 16 23:04 Makefile
-rwxrwxr-x 1 michael michael 70824 Mar 16 23:06 seccomp_benchmark*
-rw-rw-r-- 1 michael michael 2289 Feb 17 21:39 seccomp_benchmark.c
-rwxrwxr-x 1 michael michael 290520 Mar 16 23:06 seccomp_bpf* -rw-rw-r-- 1 michael michael 94778 Mar 5 23:33 seccomp_bpf.c
cheers
Quoted 72 lines · Michael Ellerman
Quoted 48 lines · Shuah Khan
Fix seccomp relocatable builds. This is a simple fix to use the right lib.mk variable
TEST_GEN_PROGSwith dependency onkselftest_harness.hheader, and defining LDFLAGS for pthread lib.Removes custom clean rule which is no longer necessary with the use of
TEST_GEN_PROGS.Uses $(OUTPUT) defined in lib.mk to handle build relocation.
The following use-cases work with this change:
In seccomp directory:
make all and make cleanFrom top level from main
Makefile:
make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccompSigned-off-by Shuah Khan <[email protected]>---
Changes since v2:
-- UsingTEST_GEN_PROGSis sufficient to generate objects.
Addresses review comments from Kees Cook.tools/testing/selftests/seccomp/Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)tools/testing/selftests/seccomp/Makefile +6
-5@@ -1,17 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 -all: - -include ../lib.mk +CFLAGS += -Wl,-no-as-needed -Wall +LDFLAGS += -lpthread .PHONY: all clean -BINARIES := seccomp_bpf seccomp_benchmark -CFLAGS += -Wl,-no-as-needed -Wall +include ../lib.mk + +# OUTPUT set by lib.mk +TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmarktools/testing/selftests/seccomp/Makefile line 17
Quoted 10 lines
tools/testing/selftests/seccomp/Makefile +2
-5-seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h - $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@ +$(TEST_GEN_PROGS): ../kselftest_harness.h -TEST_PROGS += $(BINARIES) -EXTRA_CLEAN := $(BINARIES) +all: $(TEST_GEN_PROGS) -all: $(BINARIES)It shouldn't be that complicated. We just need to define
TEST_GEN_PROGSbefore including lib.mk, and then add the dependency on the harness after we include lib.mk (so thatTEST_GEN_PROGShas been updated to prefix $(OUTPUT)).eg:
# SPDX-License-Identifier: GPL-2.0
CFLAGS += -Wl,-no-as-needed -Wall
LDFLAGS += -lpthread
Quoted 5 lines
TEST_GEN_PROGS:=seccomp_bpfseccomp_benchmarkinclude
../lib.mk$(TEST_GEN_PROGS): ../kselftest_harness.h
Exactly. This (with an extra comment) is precisely what I suggested during v2 review:
https://lore.kernel.org/lkml/202003041815.B8C73DEC@keescook/
-Kees
Quoted 51 lines
Normal in-tree build:
selftests$ make TARGETS=seccomp
make[1]: Entering directory '/home/michael/linux/tools/testing/selftests/seccomp'gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_bpf gcc -Wl,-no-as-needed -Wall -lpthread seccomp_benchmark.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_benchmarkmake[1]: Leaving directory '
/home/michael/linux/tools/testing/selftests/seccomp'selftests$ ls -l seccomp/
total 388
-rw-rw-r-- 1 michael michael 41 Jan 9 12:00 config
-rw-rw-r-- 1 michael michael 201 Mar 16 23:04Makefile
-rwxrwxr-x 1 michael michael 70824 Mar 16 23:07 seccomp_benchmark*
-rw-rw-r-- 1 michael michael 2289 Feb 17 21:39seccomp_benchmark.c
-rwxrwxr-x 1 michael michael 290520 Mar 16 23:07 seccomp_bpf* -rw-rw-r-- 1 michael michael 94778 Mar 5 23:33seccomp_bpf.cO= build:
selftests$ make TARGETS=seccomp O=$PWD/build
make[1]: Entering directory '/home/michael/linux/tools/testing/selftests/seccomp'gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/build/seccomp/seccomp_bpf gcc -Wl,-no-as-needed -Wall -lpthread seccomp_benchmark.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/build/seccomp/seccomp_benchmarkmake[1]: Leaving directory '
/home/michael/linux/tools/testing/selftests/seccomp'selftests$ ls -l build/seccomp/
total 280
-rwxrwxr-x 1 michael michael 70824 Mar 16 23:05 seccomp_benchmark* -rwxrwxr-x 1 michael michael 290520 Mar 16 23:05 seccomp_bpf*Build in the directory itself:
selftests$ cd seccomp
seccomp$ makegcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_bpf gcc -Wl,-no-as-needed -Wall -lpthread seccomp_benchmark.c ../kselftest_harness.h -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_benchmarkseccomp$ ls -l
total 388
-rw-rw-r-- 1 michael michael 41 Jan 9 12:00 config
-rw-rw-r-- 1 michael michael 201 Mar 16 23:04Makefile
-rwxrwxr-x 1 michael michael 70824 Mar 16 23:06 seccomp_benchmark*
-rw-rw-r-- 1 michael michael 2289 Feb 17 21:39seccomp_benchmark.c
-rwxrwxr-x 1 michael michael 290520 Mar 16 23:06 seccomp_bpf* -rw-rw-r-- 1 michael michael 94778 Mar 5 23:33seccomp_bpf.ccheers
Signature · 1 line
Kees Cook
Quoted 75 lines · Kees Cook
Quoted 74 lines · Michael Ellerman
Quoted 48 lines · Shuah Khan
Fix seccomp relocatable builds. This is a simple fix to use the right lib.mk variable
TEST_GEN_PROGSwith dependency onkselftest_harness.hheader, and defining LDFLAGS for pthread lib.Removes custom clean rule which is no longer necessary with the use of
TEST_GEN_PROGS.Uses $(OUTPUT) defined in lib.mk to handle build relocation.
The following use-cases work with this change:
In seccomp directory:
make all and make cleanFrom top level from main
Makefile:
make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccompSigned-off-by Shuah Khan <[email protected]>---
Changes since v2:
-- UsingTEST_GEN_PROGSis sufficient to generate objects.
Addresses review comments from Kees Cook.tools/testing/selftests/seccomp/Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)tools/testing/selftests/seccomp/Makefile +6
-5@@ -1,17 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 -all: - -include ../lib.mk +CFLAGS += -Wl,-no-as-needed -Wall +LDFLAGS += -lpthread .PHONY: all clean -BINARIES := seccomp_bpf seccomp_benchmark -CFLAGS += -Wl,-no-as-needed -Wall +include ../lib.mk + +# OUTPUT set by lib.mk +TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmarktools/testing/selftests/seccomp/Makefile line 17
Quoted 10 lines
tools/testing/selftests/seccomp/Makefile +2
-5-seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h - $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@ +$(TEST_GEN_PROGS): ../kselftest_harness.h -TEST_PROGS += $(BINARIES) -EXTRA_CLEAN := $(BINARIES) +all: $(TEST_GEN_PROGS) -all: $(BINARIES)It shouldn't be that complicated. We just need to define
TEST_GEN_PROGSbefore including lib.mk, and then add the dependency on the harness after we include lib.mk (so thatTEST_GEN_PROGShas been updated to prefix $(OUTPUT)).eg:
# SPDX-License-Identifier: GPL-2.0
CFLAGS += -Wl,-no-as-needed -Wall
LDFLAGS += -lpthread
TEST_GEN_PROGS:=seccomp_bpfseccomp_benchmark
Quoted 7 lines
Quoted 3 lines
include
../lib.mk$(TEST_GEN_PROGS): ../kselftest_harness.hExactly. This (with an extra comment) is precisely what I suggested during v2 review:
https://lore.kernel.org/lkml/202003041815.B8C73DEC@keescook/
Oh sorry, I missed that.
OK so I think we know what the right solution is.
cheers
Shuah Khan
maintainerHi Michael and Kees,
Quoted 78 lines · Michael Ellerman
Quoted 77 lines · Kees Cook
Quoted 76 lines · Michael Ellerman
Quoted 48 lines · Shuah Khan
Fix seccomp relocatable builds. This is a simple fix to use the right lib.mk variable
TEST_GEN_PROGSwith dependency onkselftest_harness.hheader, and defining LDFLAGS for pthread lib.Removes custom clean rule which is no longer necessary with the use of
TEST_GEN_PROGS.Uses $(OUTPUT) defined in lib.mk to handle build relocation.
The following use-cases work with this change:
In seccomp directory:
make all and make cleanFrom top level from main
Makefile:
make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccompSigned-off-by Shuah Khan <[email protected]>---
Changes since v2:
-- UsingTEST_GEN_PROGSis sufficient to generate objects.
Addresses review comments from Kees Cook.tools/testing/selftests/seccomp/Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)tools/testing/selftests/seccomp/Makefile +6
-5@@ -1,17 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 -all: - -include ../lib.mk +CFLAGS += -Wl,-no-as-needed -Wall +LDFLAGS += -lpthread .PHONY: all clean -BINARIES := seccomp_bpf seccomp_benchmark -CFLAGS += -Wl,-no-as-needed -Wall +include ../lib.mk + +# OUTPUT set by lib.mk +TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmarktools/testing/selftests/seccomp/Makefile line 17
Quoted 10 lines
tools/testing/selftests/seccomp/Makefile +2
-5-seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h - $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@ +$(TEST_GEN_PROGS): ../kselftest_harness.h -TEST_PROGS += $(BINARIES) -EXTRA_CLEAN := $(BINARIES) +all: $(TEST_GEN_PROGS) -all: $(BINARIES)It shouldn't be that complicated. We just need to define
TEST_GEN_PROGSbefore including lib.mk, and then add the dependency on the harness after we include lib.mk (so thatTEST_GEN_PROGShas been updated to prefix $(OUTPUT)).eg:
# SPDX-License-Identifier: GPL-2.0
CFLAGS += -Wl,-no-as-needed -Wall
LDFLAGS += -lpthread
TEST_GEN_PROGS:=seccomp_bpfseccomp_benchmarkinclude
../lib.mk
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
$(TEST_GEN_PROGS): ../kselftest_harness.hExactly. This (with an extra comment) is precisely what I suggested during v2 review:
https://lore.kernel.org/lkml/202003041815.B8C73DEC@keescook/Oh sorry, I missed that.
Sorry. I missed it as well.
Quoted 3 lines
OK so I think we know what the right solution is.
I am picking this back up after time off.
The proposed change by you works for seccomp. There are at least 10+ tests that have dependencies on kselftest_harness.h and several that have dependency on kselftest.h and kselftest_module.h
Enforcing this local header dependency in lib.mk makes sense so we don't have to change the test make files.
Add dependency to libk.mk on local headers. This enforces the dependency blindly even when a test doesn't include the file, with the benefit of a simpler enforcement without requiring individual tests to have special rule for it.
The following two changes work. You both have better make foo than I do. Can you see any issues with this proposal? I can send patch to do this, so we can do a larger test.
--------------------------------------------------------------
tools/testing/selftests/lib.mk +1 -1
@@ -137,7 +137,7 @@ endif # Selftest makefiles can override those targets by setting # OVERRIDE_TARGETS = 1. ifeq ($(OVERRIDE_TARGETS),) -$(OUTPUT)/%:%.c +$(OUTPUT)/%:%.c ../kselftest_harness.h ../kselftest.h $(LINK.c) $^ $(LDLIBS) -o $@ $(OUTPUT)/%.o:%.S
tools/testing/selftests/seccomp/Makefile +1 -10
@@ -2,14 +2,5 @@ CFLAGS += -Wl,-no-as-needed -Wall LDFLAGS += -lpthread -.PHONY: all clean - +TEST_GEN_PROGS := seccomp_bpf seccomp_benchmark include ../lib.mk - -# OUTPUT set by lib.mk -TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark - -$(TEST_GEN_PROGS): ../kselftest_harness.h - -all: $(TEST_GEN_PROGS) -
--------------------------------------------------------------
thanks,
-- Shuah
Quoted 10 lines · Shuah Khan
The following two changes work. You both have better make foo than I do. Can you see any issues with this proposal? I can send patch to do this, so we can do a larger test.
--------------------------------------------------------------
tools/testing/selftests/lib.mk +0
-0
tools/testing/selftests/lib.mk endif · line 141
Quoted 6 lines
tools/testing/selftests/lib.mk +1
-1@@ -137,7 +137,7 @@ endif # Selftest makefiles can override those targets by setting # OVERRIDE_TARGETS = 1. ifeq ($(OVERRIDE_TARGETS),) -$(OUTPUT)/%:%.c +$(OUTPUT)/%:%.c ../kselftest_harness.h ../kselftest.h $(LINK.c) $^ $(LDLIBS) -o $@
I don't think this will work because some tests are in subdirectories. The Makefile needs to know what the top-level directory of the selftest tree is (which I think is $(selfdir) ?) I think this might be more complete:
$(OUTPUT)/%: %.c $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
$(LINK.c) $^ $(LDLIBS) -o $@
Quoted 11 lines
tools/testing/selftests/seccomp/Makefile +0
-2@@ -2,14 +2,5 @@ CFLAGS += -Wl,-no-as-needed -Wall LDFLAGS += -lpthread -.PHONY: all clean -
tools/testing/selftests/seccomp/Makefile line 15
Quoted 10 lines
tools/testing/selftests/seccomp/Makefile +1
-8+TEST_GEN_PROGS := seccomp_bpf seccomp_benchmark include ../lib.mk - -# OUTPUT set by lib.mk -TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark - -$(TEST_GEN_PROGS): ../kselftest_harness.h - -all: $(TEST_GEN_PROGS) -
This part looks right. :)
Signature · 1 line
Kees Cook