Skip to contentSkip to conversation

selftests: fix header dependency for pid_namespace selftests

PATCH In review Axel Rasmussen 3 participants 6 messages Mar 24, 2022 – Mar 25, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 selftests: fix header dependency for pid_namespace selftests

The way the test target was defined before, when building with clang we get a command line like this:

clang -Wall -Werror -g -I../../../../usr/include/ \
regression_enomem.c ../pidfd/pidfd.h -o regression_enomem

This yields an error, because clang thinks we want to produce both a *.o file, as well as a precompiled header:

clang: error: cannot specify -o when generating multiple output files

gcc, for whatever reason, doesn't exhibit the same behavior which I suspect is why the problem wasn't noticed before.

This can be fixed simply by using the LOCAL_HDRS infrastructure the selftests lib.mk provides. It does the right think and marks the target as depending on the header (so if the header changes, we rebuild), but it filters the header out of the compiler command line, so we don't get the error described above.

---
 tools/testing/selftests/pid_namespace/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/pid_namespace/Makefile +3 -3
index dcaefa224ca0..edafaca1aeb3 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 CFLAGS += -g -I../../../../usr/include/
 
-TEST_GEN_PROGS := regression_enomem
+TEST_GEN_PROGS = regression_enomem
 
-include ../lib.mk
+LOCAL_HDRS += $(selfdir)/pidfd/pidfd.h
 
-$(OUTPUT)/regression_enomem: regression_enomem.c ../pidfd/pidfd.h
+include ../lib.mk
Signature · 1 line
2.35.1.1021.g381101b075-goog
#1 lore raw

PATCH 2/2 selftests: fix an unused variable warning in pidfd selftest

I fixed a few warnings like this in commit e2aa5e650b07 ("selftests: fixup build warnings in pidfd / clone3 tests"), but I missed this one by mistake. Since this variable is unused, remove it.

---
 tools/testing/selftests/pidfd/pidfd_wait.c | 1 -
 1 file changed, 1 deletion(-)
tools/testing/selftests/pidfd/pidfd_wait.c +0 -1
index 17999e082aa7..070c1c876df1 100644
@@ -95,7 +95,6 @@ TEST(wait_states)
 		.flags = CLONE_PIDFD | CLONE_PARENT_SETTID,
 		.exit_signal = SIGCHLD,
 	};
-	int ret;
 	pid_t pid;
 	siginfo_t info = {
 		.si_signo = 0,
Signature · 1 line
2.35.1.1021.g381101b075-goog
maintainer
#3 lore raw

Re: [PATCH 2/2] selftests: fix an unused variable warning in pidfd selftest

Quoted 11 lines · Christian Brauner
Quoted 6 lines · Axel Rasmussen

I fixed a few warnings like this in commit e2aa5e650b07 ("selftests: fixup build warnings in pidfd / clone3 tests"), but I missed this one by mistake. Since this variable is unused, remove it.

---

Looks good,

Thank you both. Will apply it for Linux 5.18-rc2.

thanks,
-- Shuah

Reviewed-by on v1 1/2
#4 lore raw
In reply to Axel Rasmussen
Quoted 14 lines · Axel Rasmussen

The way the test target was defined before, when building with clang we get a command line like this:

clang -Wall -Werror -g -I../../../../usr/include/ \
regression_enomem.c ../pidfd/pidfd.h -o regression_enomem

This yields an error, because clang thinks we want to produce both a *.o file, as well as a precompiled header:

clang: error: cannot specify -o when generating multiple output files

gcc, for whatever reason, doesn't exhibit the same behavior which I suspect is why the problem wasn't noticed before.

Quoted 8 lines

This can be fixed simply by using the LOCAL_HDRS infrastructure the selftests lib.mk provides. It does the right think and marks the target as depending on the header (so if the header changes, we rebuild), but it filters the header out of the compiler command line, so we don't get the error described above.

---

Looks good,

maintainer
#5 lore raw
In reply to Axel Rasmussen
Quoted 6 lines · Axel Rasmussen

The way the test target was defined before, when building with clang we get a command line like this:

clang -Wall -Werror -g -I../../../../usr/include/ \
regression_enomem.c ../pidfd/pidfd.h -o regression_enomem

Quoted 8 lines

This yields an error, because clang thinks we want to produce both a *.o file, as well as a precompiled header:

clang: error: cannot specify -o when generating multiple output files

gcc, for whatever reason, doesn't exhibit the same behavior which I suspect is why the problem wasn't noticed before.

Thank you fixing this.

Quoted 18 lines

This can be fixed simply by using the LOCAL_HDRS infrastructure the selftests lib.mk provides. It does the right think and marks the target as depending on the header (so if the header changes, we rebuild), but it filters the header out of the compiler command line, so we don't get the error described above.

---
  tools/testing/selftests/pid_namespace/Makefile | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/pid_namespace/Makefile +0 -0
index dcaefa224ca0..edafaca1aeb3 100644
@@ -1,8 +1,8 @@
  # SPDX-License-Identifier: GPL-2.0

tools/testing/selftests/pid_namespace/Makefile line 8

Quoted 10 lines
tools/testing/selftests/pid_namespace/Makefile +3 -3
  CFLAGS += -g -I../../../../usr/include/
 
-TEST_GEN_PROGS := regression_enomem
+TEST_GEN_PROGS = regression_enomem
 
-include ../lib.mk
+LOCAL_HDRS += $(selfdir)/pidfd/pidfd.h
 
-$(OUTPUT)/regression_enomem: regression_enomem.c ../pidfd/pidfd.h
+include ../lib.mk

Will apply this for Linux 5.18-rc2

thanks,
-- Shuah