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 04/11] selftests/bpf: add test_progs flavor using libbpf as a shared lib
Date: Sun, 7 Nov 2021 22:13:09 -0800 [thread overview]
Message-ID: <20211108061316.203217-5-andrii@kernel.org> (raw)
In-Reply-To: <20211108061316.203217-1-andrii@kernel.org>
Add test_progs-shared flavor to compile against libbpf as a shared
library. This is useful to make sure that libbpf's backwards/forward
compatibility guarantees are upheld. Currently this has to be checked
locally, but in the future we'll automate at least some scenarios as
part of libbpf CI runs.
Biggest change is how either libbpf.a or libbpf.so is passed to the
compiler, which is controled on per-flavor through a new TRUNNER_LIBBPF
parameter. All the places that depend on libbpf artifacts (headers,
library itself, etc) to be built are moved to order-only dependency on
$(BPFOBJ). rpath is used to specify relative location to where libbpf.so
should be so that when test_progs-shared is run under QEMU, libbpf.so is
still going to be discovered correctly.
Few selftests are using or testing internal libbpf APIs, so are not
compatible with shared library use of libbpf. Filter them out for shared
flavor.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/testing/selftests/bpf/.gitignore | 2 ++
tools/testing/selftests/bpf/Makefile | 36 +++++++++++++++++++-------
2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index b6bc56c8127a..5adfac44c478 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -32,8 +32,10 @@ test_cpp
*.tests.h
/test_progs
/test_progs-no_alu32
+/test_progs-shared
/test_progs-bpf_gcc
/no_alu32
+/shared
/bpf_gcc
/tools
/runqslower
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 33f153a9de4c..42bc7913cc1a 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -32,16 +32,19 @@ ifneq ($(LLVM),)
CFLAGS += -Wno-unused-command-line-argument
endif
+TEST_RUNNERS = test_maps test_progs test_progs-no_alu32 test_progs-shared
+
# Order correspond to 'make run_tests' order
-TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
+TEST_GEN_PROGS = test_verifier test_tag test_lru_map test_lpm_map \
test_verifier_log test_dev_cgroup \
test_sock test_sockmap get_cgroup_id_user \
test_cgroup_storage \
test_tcpnotify_user test_sysctl \
- test_progs-no_alu32
+ $(TEST_RUNNERS)
# Also test bpf-gcc, if present
ifneq ($(BPF_GCC),)
+TEST_RUNNERS += test_progs-bpf_gcc
TEST_GEN_PROGS += test_progs-bpf_gcc
endif
@@ -190,7 +193,9 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT)
TEST_GEN_PROGS_EXTENDED += $(DEFAULT_BPFTOOL)
-$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(BPFOBJ)
+# Add libbpf.a dependency to all the test binaries but those in $(TEST_RUNNERS)
+$(filter-out $(addprefix %,$(TEST_RUNNERS)),$(TEST_GEN_PROGS)): $(BPFOBJ)
+$(TEST_GEN_PROGS_EXTENDED): $(BPFOBJ)
$(OUTPUT)/test_dev_cgroup: cgroup_helpers.c testing_helpers.o
$(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c testing_helpers.o
@@ -436,7 +441,7 @@ $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
$(TRUNNER_BPF_SKELS) \
$(TRUNNER_BPF_LSKELS) \
$(TRUNNER_BPF_SKELS_LINKED) \
- $$(BPFOBJ) | $(TRUNNER_OUTPUT)
+ | $$(BPFOBJ) $(TRUNNER_OUTPUT)
$$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
$(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
@@ -444,7 +449,7 @@ $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \
%.c \
$(TRUNNER_EXTRA_HDRS) \
$(TRUNNER_TESTS_HDR) \
- $$(BPFOBJ) | $(TRUNNER_OUTPUT)
+ | $$(BPFOBJ) $(TRUNNER_OUTPUT)
$$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
$(Q)$$(CC) $$(CFLAGS) -DTESTS_HDR=\"$(TRUNNER_TESTS_HDR)\" -c $$< $$(LDLIBS) -o $$@
@@ -457,11 +462,11 @@ ifneq ($2:$(OUTPUT),:$(shell pwd))
endif
$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \
- $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \
+ $(TRUNNER_EXTRA_OBJS) \
$(RESOLVE_BTFIDS) \
- | $(TRUNNER_BINARY)-extras
+ | $$(BPF_OBJ) $(TRUNNER_BINARY)-extras
$$(call msg,BINARY,,$$@)
- $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
+ $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $(TRUNNER_LIBBPF) $$(LDLIBS) $(TRUNNER_EXTRA_CFLAGS) -o $$@
$(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.o $$@
endef
@@ -477,17 +482,29 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \
$(wildcard progs/btf_dump_test_case_*.c)
TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
+TRUNNER_LIBBPF := $(BPFOBJ)
$(eval $(call DEFINE_TEST_RUNNER,test_progs))
# Define test_progs-no_alu32 test runner.
TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
+TRUNNER_LIBBPF := $(BPFOBJ)
$(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
+# Define test_progs-shared test runner.
+TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
+TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
+TRUNNER_EXTRA_CFLAGS := -Wl,-rpath=$(subst $(CURDIR)/,,$(dir $(BPFOBJ)))
+TRUNNER_LIBBPF := $(patsubst %libbpf.a,%libbpf.so,$(BPFOBJ))
+TRUNNER_TESTS_BLACKLIST := cpu_mask.c hashmap.c perf_buffer.c raw_tp_test_run.c
+$(eval $(call DEFINE_TEST_RUNNER,test_progs,shared))
+TRUNNER_TESTS_BLACKLIST :=
+
# Define test_progs BPF-GCC-flavored test runner.
ifneq ($(BPF_GCC),)
TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
+TRUNNER_LIBBPF := $(BPFOBJ)
$(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
endif
@@ -542,6 +559,7 @@ $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \
*.tests.h verifier/tests.h \
- $(addprefix $(OUTPUT)/,*.o *.skel.h *.lskel.h no_alu32 bpf_gcc bpf_testmod.ko)
+ $(addprefix $(OUTPUT)/,*.o *.skel.h *.lskel.h) \
+ $(addprefix $(OUTPUT)/,no_alu32 shared bpf_gcc bpf_testmod.ko)
.PHONY: docs docs-clean
--
2.30.2
next prev 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 ` [PATCH bpf-next 03/11] selftests/bpf: allow to generate per-flavor list of tests Andrii Nakryiko
2021-11-08 6:13 ` Andrii Nakryiko [this message]
2021-11-09 3:44 ` [PATCH bpf-next 04/11] selftests/bpf: add test_progs flavor using libbpf as a shared lib 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-5-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