diff mbox series

[bpf-next,03/11] selftests/bpf: allow to generate per-flavor list of tests

Message ID 20211108061316.203217-4-andrii@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Future-proof more tricky libbpf APIs | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 8 maintainers not CCed: songliubraving@fb.com linux-kselftest@vger.kernel.org shuah@kernel.org john.fastabend@gmail.com yhs@fb.com kpsingh@kernel.org netdev@vger.kernel.org kafai@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 111 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary

Commit Message

Andrii Nakryiko Nov. 8, 2021, 6:13 a.m. UTC
Add per-flavor list of tests to test_progs/test_maps test runners. Allow
to filter out some tests. This is going to be used in the next patch to
filter out tests that are using internal libbpf APIs and thus are not
compatible with test_progs built with libbpf as a shared library.

The way this is achieved is by generating test headers with test
binary-specific name and passing it explicitly to compiled test runners
through TESTS_HDR compiler define.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/testing/selftests/bpf/.gitignore   |  7 ++++---
 tools/testing/selftests/bpf/Makefile     | 25 +++++++++++-------------
 tools/testing/selftests/bpf/test_maps.c  |  4 ++--
 tools/testing/selftests/bpf/test_progs.c |  6 +++---
 4 files changed, 20 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index 1dad8d617da8..b6bc56c8127a 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -9,9 +9,6 @@  test_tag
 FEATURE-DUMP.libbpf
 fixdep
 test_dev_cgroup
-/test_progs
-/test_progs-no_alu32
-/test_progs-bpf_gcc
 test_verifier_log
 feature
 test_sock
@@ -32,6 +29,10 @@  xdping
 test_cpp
 *.skel.h
 *.lskel.h
+*.tests.h
+/test_progs
+/test_progs-no_alu32
+/test_progs-bpf_gcc
 /no_alu32
 /bpf_gcc
 /tools
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 0470802c907c..33f153a9de4c 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -344,14 +344,15 @@  LINKED_BPF_SRCS := $(patsubst %.o,%.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-d
 # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
 define DEFINE_TEST_RUNNER
 
-TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
+TRUNNER_OUTPUT := $(if $(OUTPUT),$(OUTPUT),.)$(if $2,/)$2
 TRUNNER_BINARY := $1$(if $2,-)$2
-TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o,	\
-				 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
+TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o,	       \
+				 $$(filter-out $(TRUNNER_TESTS_BLACKLIST),     \
+					       $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c))))
 TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o,		\
 				 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
 TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
-TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
+TRUNNER_TESTS_HDR := $$(TRUNNER_OUTPUT)/$1.tests.h
 TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
 TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS))
 TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h,	\
@@ -418,16 +419,13 @@  $(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_BPF_OBJS) $(BPFTOOL) | $(TRUNNER_OUTPUT)
 	$(Q)$$(BPFTOOL) gen skeleton $$(@:.skel.h=.linked3.o) name $$(notdir $$(@:.skel.h=)) > $$@
 endif
 
-# ensure we set up tests.h header generation rule just once
-ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
-$(TRUNNER_TESTS_DIR)-tests-hdr := y
-$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
+$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c | $(TRUNNER_OUTPUT)
 	$$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
-	$$(shell (echo '/* Generated header, do not edit */';					\
+	$$(shell (echo '/* Generated header, do not edit */';						\
 		  sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p'	\
-			$(TRUNNER_TESTS_DIR)/*.c | sort ;	\
+			$(filter-out $(addprefix $(TRUNNER_TESTS_DIR)/,$(TRUNNER_TESTS_BLACKLIST)),	\
+				     $(wildcard $(TRUNNER_TESTS_DIR)/*.c)) | sort ;			\
 		 ) > $$@)
-endif
 
 # compile individual test files
 # Note: we cd into output directory to ensure embedded BPF object is found
@@ -448,7 +446,7 @@  $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o:				\
 		       $(TRUNNER_TESTS_HDR)				\
 		       $$(BPFOBJ) | $(TRUNNER_OUTPUT)
 	$$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
-	$(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
+	$(Q)$$(CC) $$(CFLAGS) -DTESTS_HDR=\"$(TRUNNER_TESTS_HDR)\" -c $$< $$(LDLIBS) -o $$@
 
 # non-flavored in-srctree builds receive special treatment, in particular, we
 # do not need to copy extra resources (see e.g. test_btf_dump_case())
@@ -543,8 +541,7 @@  $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
 	$(Q)$(CC) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
 
 EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)	\
-	prog_tests/tests.h map_tests/tests.h verifier/tests.h		\
-	feature								\
+	*.tests.h verifier/tests.h					\
 	$(addprefix $(OUTPUT)/,*.o *.skel.h *.lskel.h no_alu32 bpf_gcc bpf_testmod.ko)
 
 .PHONY: docs docs-clean
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index 8b31bc1a801d..daddaf4f3e5a 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -1887,7 +1887,7 @@  static void run_all_tests(void)
 }
 
 #define DEFINE_TEST(name) extern void test_##name(void);
-#include <map_tests/tests.h>
+#include TESTS_HDR
 #undef DEFINE_TEST
 
 int main(void)
@@ -1903,7 +1903,7 @@  int main(void)
 	run_all_tests();
 
 #define DEFINE_TEST(name) test_##name();
-#include <map_tests/tests.h>
+#include TESTS_HDR
 #undef DEFINE_TEST
 
 	printf("test_maps: OK, %d SKIPPED\n", skips);
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index c65986bd9d07..7c078565ee9d 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -461,7 +461,7 @@  static int load_bpf_testmod(void)
 #define DEFINE_TEST(name)				\
 	extern void test_##name(void) __weak;		\
 	extern void serial_test_##name(void) __weak;
-#include <prog_tests/tests.h>
+#include TESTS_HDR
 #undef DEFINE_TEST
 
 static struct prog_test_def prog_test_defs[] = {
@@ -470,7 +470,7 @@  static struct prog_test_def prog_test_defs[] = {
 	.run_test = &test_##name,		\
 	.run_serial_test = &serial_test_##name,	\
 },
-#include <prog_tests/tests.h>
+#include TESTS_HDR
 #undef DEFINE_TEST
 };
 const int prog_test_cnt = ARRAY_SIZE(prog_test_defs);
@@ -1377,7 +1377,7 @@  int main(int argc, char **argv)
 
 		if ((test->run_test == NULL && test->run_serial_test == NULL) ||
 		    (test->run_test != NULL && test->run_serial_test != NULL)) {
-			fprintf(stderr, "Test %d:%s must have either test_%s() or serial_test_%sl() defined.\n",
+			fprintf(stderr, "Test %d:%s must have either test_%s() or serial_test_%s() defined.\n",
 				test->test_num, test->test_name, test->test_name, test->test_name);
 			exit(EXIT_ERR_SETUP_INFRA);
 		}