Skip to contentSkip to conversation

selftests/landlock: Fix out-of-tree builds

PATCH In review Mickaël Salaün 2 participants 5 messages Sep 9, 2022 – Sep 23, 2022

Subsystems (3)
lore
Share & tools
lore

Mickaël Salaün

author maintainer
#0 lore raw

PATCH 1/1 selftests/landlock: Fix out-of-tree builds

These changes simplify the Makefile and handle these 5 ways to build Landlock tests:
- make -C tools/testing/selftests/landlock
- make -C tools/testing/selftests TARGETS=landlock gen_tar
- make TARGETS=landlock kselftest-gen_tar
- make TARGETS=landlock O=build kselftest-gen_tar
- make -C /tmp/linux TARGETS=landlock O=/tmp/build kselftest-gen_tar

This also makes $(KHDR_INCLUDES) available to other test collections when building in their directory.

Fixes f1227dc7d041 ("selftests/landlock: fix broken include of linux/landlock.h")
Fixes 3bb267a36185 ("selftests: drop khdr make target")
Cc Anders Roxell <[email protected]>
Cc Guillaume Tucker <[email protected]>
Cc Mark Brown <[email protected]>
Cc Shuah Khan <[email protected]>
---
 tools/testing/selftests/landlock/Makefile | 19 ++++++++++---------
 tools/testing/selftests/lib.mk            |  4 ++++
 2 files changed, 14 insertions(+), 9 deletions(-)
tools/testing/selftests/landlock/Makefile +10 -9
index 02868ac3bc71..6632bfff486b 100644
@@ -1,6 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0
+#
+# First run: make -C ../../../.. headers_install
 
 CFLAGS += -Wall -O2 $(KHDR_INCLUDES)
+LDLIBS += -lcap
+
+LOCAL_HDRS += common.h
 
 src_test := $(wildcard *_test.c)
 
@@ -8,14 +13,10 @@ TEST_GEN_PROGS := $(src_test:.c=)
 
 TEST_GEN_PROGS_EXTENDED := true
 
-OVERRIDE_TARGETS := 1
-top_srcdir := ../../../..
-include ../lib.mk
-
-khdr_dir = $(top_srcdir)/usr/include
+# Static linking for short targets:
+$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
 
-$(OUTPUT)/true: true.c
-	$(LINK.c) $< $(LDLIBS) -o $@ -static
+include ../lib.mk
 
-$(OUTPUT)/%_test: %_test.c $(khdr_dir)/linux/landlock.h ../kselftest_harness.h common.h
-	$(LINK.c) $< $(LDLIBS) -o $@ -lcap -I$(khdr_dir)
+# Static linking for targets with $(OUTPUT)/ prefix:
+$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
tools/testing/selftests/lib.mk +4 -0
index d44c72b3abe3..9d4cb94cf437 100644
@@ -42,6 +42,10 @@ endif
 selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
 top_srcdir = $(selfdir)/../../..
 
+ifeq ($(KHDR_INCLUDES),)
+KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
+endif
+
 # The following are built by lib.mk common compile rules.
 # TEST_CUSTOM_PROGS should be used by tests that require
 # custom build rule and prevent common build rule use.

base-commit: 7e18e42e4b280c85b76967a9106a13ca61c16179

Signature · 1 line
2.37.2
author maintainer
#1 lore raw

Shuah, could you please merge this patch (and the USERCFLAGS/USERLDFLAGS one if that's OK) to -next? This is fixing an issue in the current 6.0-rc5 .

Anders, can you please check that this fixes your issue? https://lore.kernel.org/r/CADYN=9JM1nnjC9LypHqrz7JJjbZLpm8rArDUy4zgYYrajErBnA@mail.gmail.com

Quoted 77 lines · Mickaël Salaün

These changes simplify the Makefile and handle these 5 ways to build Landlock tests:
- make -C tools/testing/selftests/landlock
- make -C tools/testing/selftests TARGETS=landlock gen_tar
- make TARGETS=landlock kselftest-gen_tar
- make TARGETS=landlock O=build kselftest-gen_tar
- make -C /tmp/linux TARGETS=landlock O=/tmp/build kselftest-gen_tar

This also makes $(KHDR_INCLUDES) available to other test collections when building in their directory.

Fixes f1227dc7d041 ("selftests/landlock: fix broken include of linux/landlock.h")
Fixes 3bb267a36185 ("selftests: drop khdr make target")
Cc Anders Roxell <[email protected]>
Cc Guillaume Tucker <[email protected]>
Cc Mark Brown <[email protected]>
Cc Shuah Khan <[email protected]>
---
  tools/testing/selftests/landlock/Makefile | 19 ++++++++++---------
  tools/testing/selftests/lib.mk            |  4 ++++
  2 files changed, 14 insertions(+), 9 deletions(-)
tools/testing/selftests/landlock/Makefile +10 -9
index 02868ac3bc71..6632bfff486b 100644
@@ -1,6 +1,11 @@
  # SPDX-License-Identifier: GPL-2.0
+#
+# First run: make -C ../../../.. headers_install
 
  CFLAGS += -Wall -O2 $(KHDR_INCLUDES)
+LDLIBS += -lcap
+
+LOCAL_HDRS += common.h
 
  src_test := $(wildcard *_test.c)
 
@@ -8,14 +13,10 @@ TEST_GEN_PROGS := $(src_test:.c=)
 
  TEST_GEN_PROGS_EXTENDED := true
 
-OVERRIDE_TARGETS := 1
-top_srcdir := ../../../..
-include ../lib.mk
-
-khdr_dir = $(top_srcdir)/usr/include
+# Static linking for short targets:
+$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
 
-$(OUTPUT)/true: true.c
-	$(LINK.c) $< $(LDLIBS) -o $@ -static
+include ../lib.mk
 
-$(OUTPUT)/%_test: %_test.c $(khdr_dir)/linux/landlock.h ../kselftest_harness.h common.h
-	$(LINK.c) $< $(LDLIBS) -o $@ -lcap -I$(khdr_dir)
+# Static linking for targets with $(OUTPUT)/ prefix:
+$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
tools/testing/selftests/lib.mk +4 -0
index d44c72b3abe3..9d4cb94cf437 100644
@@ -42,6 +42,10 @@ endif
  selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
  top_srcdir = $(selfdir)/../../..
 
+ifeq ($(KHDR_INCLUDES),)
+KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
+endif
+
  # The following are built by lib.mk common compile rules.
  # TEST_CUSTOM_PROGS should be used by tests that require
  # custom build rule and prevent common build rule use.

base-commit: 7e18e42e4b280c85b76967a9106a13ca61c16179

author maintainer
#2 lore raw

I took the liberty to pushed it in -next with my tree: https://git.kernel.org/mic/c/a52540522c9541bfa3e499d2edba7bc0ca73a4ca

Please let me know when you can take it in your tree to include it in the next -rc.

Regards,
Mickaël

Quoted 85 lines · Mickaël Salaün

Shuah, could you please merge this patch (and the USERCFLAGS/USERLDFLAGS one if that's OK) to -next? This is fixing an issue in the current 6.0-rc5 .

Anders, can you please check that this fixes your issue?
https://lore.kernel.org/r/CADYN=9JM1nnjC9LypHqrz7JJjbZLpm8rArDUy4zgYYrajErBnA@mail.gmail.com

Quoted 77 lines · Mickaël Salaün

These changes simplify the Makefile and handle these 5 ways to build Landlock tests:
- make -C tools/testing/selftests/landlock
- make -C tools/testing/selftests TARGETS=landlock gen_tar
- make TARGETS=landlock kselftest-gen_tar
- make TARGETS=landlock O=build kselftest-gen_tar
- make -C /tmp/linux TARGETS=landlock O=/tmp/build kselftest-gen_tar

This also makes $(KHDR_INCLUDES) available to other test collections when building in their directory.

Fixes f1227dc7d041 ("selftests/landlock: fix broken include of linux/landlock.h")
Fixes 3bb267a36185 ("selftests: drop khdr make target")
Cc Anders Roxell <[email protected]>
Cc Guillaume Tucker <[email protected]>
Cc Mark Brown <[email protected]>
Cc Shuah Khan <[email protected]>
---
   tools/testing/selftests/landlock/Makefile | 19 ++++++++++---------
   tools/testing/selftests/lib.mk            |  4 ++++
   2 files changed, 14 insertions(+), 9 deletions(-)
tools/testing/selftests/landlock/Makefile +10 -9
index 02868ac3bc71..6632bfff486b 100644
@@ -1,6 +1,11 @@
   # SPDX-License-Identifier: GPL-2.0
+#
+# First run: make -C ../../../.. headers_install
 
   CFLAGS += -Wall -O2 $(KHDR_INCLUDES)
+LDLIBS += -lcap
+
+LOCAL_HDRS += common.h
 
   src_test := $(wildcard *_test.c)
 
@@ -8,14 +13,10 @@ TEST_GEN_PROGS := $(src_test:.c=)
 
   TEST_GEN_PROGS_EXTENDED := true
 
-OVERRIDE_TARGETS := 1
-top_srcdir := ../../../..
-include ../lib.mk
-
-khdr_dir = $(top_srcdir)/usr/include
+# Static linking for short targets:
+$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
 
-$(OUTPUT)/true: true.c
-	$(LINK.c) $< $(LDLIBS) -o $@ -static
+include ../lib.mk
 
-$(OUTPUT)/%_test: %_test.c $(khdr_dir)/linux/landlock.h ../kselftest_harness.h common.h
-	$(LINK.c) $< $(LDLIBS) -o $@ -lcap -I$(khdr_dir)
+# Static linking for targets with $(OUTPUT)/ prefix:
+$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
tools/testing/selftests/lib.mk +4 -0
index d44c72b3abe3..9d4cb94cf437 100644
@@ -42,6 +42,10 @@ endif
   selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
   top_srcdir = $(selfdir)/../../..
 
+ifeq ($(KHDR_INCLUDES),)
+KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
+endif
+
   # The following are built by lib.mk common compile rules.
   # TEST_CUSTOM_PROGS should be used by tests that require
   # custom build rule and prevent common build rule use.

base-commit: 7e18e42e4b280c85b76967a9106a13ca61c16179

author maintainer
#3 lore raw

I plan to push it to Linus tomorrow, I'd like to get some feedback by then though.

Quoted 95 lines · Mickaël Salaün

I took the liberty to pushed it in -next with my tree:
https://git.kernel.org/mic/c/a52540522c9541bfa3e499d2edba7bc0ca73a4ca

Please let me know when you can take it in your tree to include it in the next -rc.

Regards,
Mickaël

Quoted 85 lines · Mickaël Salaün

Shuah, could you please merge this patch (and the USERCFLAGS/USERLDFLAGS one if that's OK) to -next? This is fixing an issue in the current 6.0-rc5 .

Anders, can you please check that this fixes your issue?
https://lore.kernel.org/r/CADYN=9JM1nnjC9LypHqrz7JJjbZLpm8rArDUy4zgYYrajErBnA@mail.gmail.com

Quoted 77 lines · Mickaël Salaün

These changes simplify the Makefile and handle these 5 ways to build Landlock tests:
- make -C tools/testing/selftests/landlock
- make -C tools/testing/selftests TARGETS=landlock gen_tar
- make TARGETS=landlock kselftest-gen_tar
- make TARGETS=landlock O=build kselftest-gen_tar
- make -C /tmp/linux TARGETS=landlock O=/tmp/build kselftest-gen_tar

This also makes $(KHDR_INCLUDES) available to other test collections when building in their directory.

Fixes f1227dc7d041 ("selftests/landlock: fix broken include of linux/landlock.h")
Fixes 3bb267a36185 ("selftests: drop khdr make target")
Cc Anders Roxell <[email protected]>
Cc Guillaume Tucker <[email protected]>
Cc Mark Brown <[email protected]>
Cc Shuah Khan <[email protected]>
---
    tools/testing/selftests/landlock/Makefile | 19 ++++++++++---------
    tools/testing/selftests/lib.mk            |  4 ++++
    2 files changed, 14 insertions(+), 9 deletions(-)
tools/testing/selftests/landlock/Makefile +10 -9
index 02868ac3bc71..6632bfff486b 100644
@@ -1,6 +1,11 @@
    # SPDX-License-Identifier: GPL-2.0
+#
+# First run: make -C ../../../.. headers_install
 
    CFLAGS += -Wall -O2 $(KHDR_INCLUDES)
+LDLIBS += -lcap
+
+LOCAL_HDRS += common.h
 
    src_test := $(wildcard *_test.c)
 
@@ -8,14 +13,10 @@ TEST_GEN_PROGS := $(src_test:.c=)
 
    TEST_GEN_PROGS_EXTENDED := true
 
-OVERRIDE_TARGETS := 1
-top_srcdir := ../../../..
-include ../lib.mk
-
-khdr_dir = $(top_srcdir)/usr/include
+# Static linking for short targets:
+$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
 
-$(OUTPUT)/true: true.c
-	$(LINK.c) $< $(LDLIBS) -o $@ -static
+include ../lib.mk
 
-$(OUTPUT)/%_test: %_test.c $(khdr_dir)/linux/landlock.h ../kselftest_harness.h common.h
-	$(LINK.c) $< $(LDLIBS) -o $@ -lcap -I$(khdr_dir)
+# Static linking for targets with $(OUTPUT)/ prefix:
+$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
tools/testing/selftests/lib.mk +4 -0
index d44c72b3abe3..9d4cb94cf437 100644
@@ -42,6 +42,10 @@ endif
    selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
    top_srcdir = $(selfdir)/../../..
 
+ifeq ($(KHDR_INCLUDES),)
+KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
+endif
+
    # The following are built by lib.mk common compile rules.
    # TEST_CUSTOM_PROGS should be used by tests that require
    # custom build rule and prevent common build rule use.

base-commit: 7e18e42e4b280c85b76967a9106a13ca61c16179

maintainer
#4 lore raw
Quoted 13 lines · Mickaël Salaün

I plan to push it to Linus tomorrow, I'd like to get some feedback by then though.

Quoted 9 lines · Mickaël Salaün

I took the liberty to pushed it in -next with my tree:
https://git.kernel.org/mic/c/a52540522c9541bfa3e499d2edba7bc0ca73a4ca

Please let me know when you can take it in your tree to include it in the next -rc.

Regards,
   Mickaël

Looks good to me. Thanks for doing this. Linux Plumbers travel and subsequent being under the weather caused the delay in a response to this patch.

I also saw your pull request to Linus.

thanks,
-- Shuah