Skip to contentSkip to conversation

selftests/bpf: Resolve bpftool through bpftool_helpers in core_reloc

PATCH In review Kumar Kartikeya Dwivedi 2 participants 2 messages Aug 24 – Aug 25

Subsystems (3)
lore
Share & tools
lore

Kumar Kartikeya Dwivedi

author maintainer
#0 lore raw

PATCH 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
index 08963c82f30b..80432c4656b5 100644
@@ -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

Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Kumar Kartikeya Dwivedi

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

Quoted 8 lines

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.

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
index 08963c82f30b..80432c4656b5 100644
@@ -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