selftests/bpf: Resolve bpftool through bpftool_helpers in core_reloc
Subsystems (3)
Kumar Kartikeya Dwivedi
maintainerPATCH 1/1 selftests/bpf: Resolve bpftool through bpftool_helpers in core_reloc
run_btfgen() shells out to a hardcoded "./bpftool". That path only exists in the build tree, where DEFINE_TEST_RUNNER_RULES symlinks bpftool next to each runner binary. After "make install" it is not
there: commit 0b236ac75d04 ("selftests/bpf: Fix make install target") dropped bpftool from TEST_GEN_PROGS_EXTENDED, which used to flatten it into $(INSTALL_PATH), and installs it under $(INSTALL_PATH)/tools/sbin/ instead, matching detect_bpftool_path().
Running test_progs from the install tree therefore fails all 64 core_reloc_btfgen subtests:
run_core_reloc_tests:FAIL:run_btfgen unexpected error: 32512 (errno 95)
sh: line 1: ./bpftool: No such file or directory
32512 is 127 << 8, i.e. the shell could not find the binary.
Use run_bpftool_command() from bpftool_helpers.h, which locates bpftool via $BPFTOOL, ./tools/sbin/bpftool or ../tools/sbin/bpftool, the last of which also covers the test_progs flavors. bpftool_helpers.c is already in TRUNNER_EXTRA_SOURCES, so no build change is needed.
--- tools/testing/selftests/bpf/prog_tests/core_reloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/prog_tests/core_reloc.c +5 -5
@@ -7,6 +7,7 @@#include <sys/mman.h> #include <sys/syscall.h> #include <bpf/btf.h> +#include "bpftool_helpers.h" static int duration =0 ;
@@ -985,16 +986,15 @@ static size_t roundup_page(size_t sz)static int run_btfgen (const char *src_btf,const char *dst_btf,const char *objpath) { -char command[4096 ]; +char args[4096 ];int n; - n =snprintf (command,sizeof (command), -"./bpftool gen min_core_btf %s %s %s" , + n =snprintf (args,sizeof (args),"gen min_core_btf %s %s %s" , src_btf, dst_btf, objpath); -if (n <0 || n >=sizeof (command)) +if (n <0 || n >=sizeof (args))return -1 ; -return system (command); +return run_bpftool_command (args); }static void run_core_reloc_tests (bool use_btfgen)
--
2.53.0-Meta
Quoted 14 lines · Kumar Kartikeya Dwivedi
run_btfgen()shells out to a hardcoded "./bpftool". That path only exists in the build tree, whereDEFINE_TEST_RUNNER_RULESsymlinks bpftool next to each runner binary. After "make install" it is not
there: commit0b236ac75d04("selftests/bpf: Fix make install target") dropped bpftool fromTEST_GEN_PROGS_EXTENDED, which used to flatten it into $(INSTALL_PATH), and installs it under $(INSTALL_PATH)/tools/sbin/ instead, matchingdetect_bpftool_path().Running
test_progsfrom the install tree therefore fails all 64core_reloc_btfgensubtests:run_core_reloc_tests:FAIL:run_btfgen unexpected error: 32512 (errno 95)
sh: line 1: ./bpftool: No such file or directory
Quoted 8 lines
32512 is 127 << 8, i.e. the shell could not find the binary.
Use
run_bpftool_command()frombpftool_helpers.h, which locates bpftool via $BPFTOOL,./tools/sbin/bpftoolor ../tools/sbin/bpftool, the last of which also covers thetest_progsflavors.bpftool_helpers.cis already inTRUNNER_EXTRA_SOURCES, so no build change is needed.Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>
jirka
Quoted 41 lines
--- tools/testing/selftests/bpf/prog_tests/core_reloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)tools/testing/selftests/bpf/prog_tests/core_reloc.c +5
-6@@ -7,6 +7,7 @@#include <sys/mman.h> #include <sys/syscall.h> #include <bpf/btf.h> +#include "bpftool_helpers.h" static int duration =0 ;@@ -985,16 +986,15 @@ static size_t roundup_page(size_t sz)static int run_btfgen (const char *src_btf,const char *dst_btf,const char *objpath) { -char command[4096 ]; +char args[4096 ];int n; - n =snprintf (command,sizeof (command), -"./bpftool gen min_core_btf %s %s %s" , + n =snprintf (args,sizeof (args),"gen min_core_btf %s %s %s" , src_btf, dst_btf, objpath); -if (n <0 || n >=sizeof (command)) +if (n <0 || n >=sizeof (args))return -1 ; -return system (command); +return run_bpftool_command (args); }static void run_core_reloc_tests (bool use_btfgen) --2.53.0-Meta