BPF List
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>
Subject: [PATCH bpf-next 03/11] selftests/bpf: allow to generate per-flavor list of tests
Date: Sun, 7 Nov 2021 22:13:08 -0800	[thread overview]
Message-ID: <20211108061316.203217-4-andrii@kernel.org> (raw)
In-Reply-To: <20211108061316.203217-1-andrii@kernel.org>

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 --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);
 		}
-- 
2.30.2


  parent reply	other threads:[~2021-11-08  6:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08  6:13 [PATCH bpf-next 00/11] Future-proof more tricky libbpf APIs Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 01/11] bpftool: normalize compile rules to specify output file last Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 02/11] selftests/bpf: minor cleanups and normalization of Makefile Andrii Nakryiko
2021-11-08  6:13 ` Andrii Nakryiko [this message]
2021-11-08  6:13 ` [PATCH bpf-next 04/11] selftests/bpf: add test_progs flavor using libbpf as a shared lib Andrii Nakryiko
2021-11-09  3:44   ` Alexei Starovoitov
2021-11-09 15:42     ` Andrii Nakryiko
2021-11-09 17:53       ` Alexei Starovoitov
2021-11-10  0:52         ` Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 05/11] libbpf: turn btf_dedup_opts into OPTS-based struct Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 06/11] libbpf: ensure btf_dump__new() and btf_dump_opts are future-proof Andrii Nakryiko
2021-11-09  3:38   ` Alexei Starovoitov
2021-11-09 15:37     ` Andrii Nakryiko
2021-11-09 17:40       ` Alexei Starovoitov
2021-11-10  0:10         ` Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 07/11] libbpf: make perf_buffer__new() use OPTS-based interface Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 08/11] selftests/bpf: migrate all deprecated perf_buffer uses Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 09/11] selftests/bpf: update btf_dump__new() uses to v1.0+ variant Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 10/11] tools/runqslower: update perf_buffer__new() calls Andrii Nakryiko
2021-11-08  6:13 ` [PATCH bpf-next 11/11] bpftool: update btf_dump__new() and perf_buffer__new_raw() calls Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211108061316.203217-4-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox