btf_module test verifies that loading split BTF from bpf_testmod.ko is successful. To test standalone BTF, add a test that loads BTF from bpf_testmod_standalone.ko and verifies we can look up BTF, just as we could for real split BTF. Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx> --- tools/testing/selftests/bpf/Makefile | 8 ++++---- .../selftests/bpf/prog_tests/btf_module.c | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 9c27b67bc7b1..5a4421238d5b 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -106,7 +106,7 @@ TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \ flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \ xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_hw_metadata \ - xdp_features + xdp_features btf_testmod_standalone.ko TEST_GEN_FILES += liburandom_read.so urandom_read sign-file uprobe_multi @@ -225,9 +225,9 @@ $(OUTPUT)/sign-file: ../../../../scripts/sign-file.c $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch]) $(call msg,MOD,,$@) - $(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation + $(Q)$(RM) bpf_testmod/bpf_testmod*.ko # force re-compilation $(Q)$(MAKE) $(submake_extras) RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) -C bpf_testmod - $(Q)cp bpf_testmod/bpf_testmod.ko $@ + $(Q)cp bpf_testmod/bpf_testmod*.ko $(OUTPUT) DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool ifneq ($(CROSS_COMPILE),) @@ -728,7 +728,7 @@ EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \ prog_tests/tests.h map_tests/tests.h verifier/tests.h \ feature bpftool \ $(addprefix $(OUTPUT)/,*.o *.skel.h *.lskel.h *.subskel.h \ - no_alu32 cpuv4 bpf_gcc bpf_testmod.ko \ + no_alu32 cpuv4 bpf_gcc bpf_testmod*.ko \ liburandom_read.so) .PHONY: docs docs-clean diff --git a/tools/testing/selftests/bpf/prog_tests/btf_module.c b/tools/testing/selftests/bpf/prog_tests/btf_module.c index 2239d1fe0332..5470342a1d08 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf_module.c +++ b/tools/testing/selftests/bpf/prog_tests/btf_module.c @@ -5,11 +5,13 @@ #include <bpf/btf.h> static const char *module_name = "bpf_testmod"; +static const char *standalone_module_name = "bpf_testmod_standalone"; static const char *symbol_name = "bpf_testmod_test_read"; +static const char *standalone_symbol_name = "bpf_testmod_standalone_test_read"; void test_btf_module() { - struct btf *vmlinux_btf, *module_btf; + struct btf *vmlinux_btf, *module_btf, *standalone_module_btf = NULL; __s32 type_id; if (!env.has_testmod) { @@ -26,9 +28,22 @@ void test_btf_module() goto cleanup; type_id = btf__find_by_name(module_btf, symbol_name); - ASSERT_GT(type_id, 0, "func not found"); + if (!ASSERT_GT(type_id, 0, "func not found")) + goto cleanup; + + if (!ASSERT_OK(load_bpf_testmod(standalone_module_name, false), "load standalone BTF module")) + goto cleanup; + + standalone_module_btf = btf__load_module_btf(standalone_module_name, vmlinux_btf); + if (!ASSERT_OK_PTR(standalone_module_btf, "could not load standalone module BTF")) + goto cleanup; + + type_id = btf__find_by_name(standalone_module_btf, standalone_symbol_name); + ASSERT_GT(type_id, 0, "func not found in standalone"); cleanup: + btf__free(standalone_module_btf); btf__free(module_btf); btf__free(vmlinux_btf); + unload_bpf_testmod(standalone_module_name, false); } -- 2.31.1