Skip to content

Commit a2714e7

Browse files
theihorAlexei Starovoitov
authored andcommitted
selftests/bpf: Check BPFTOOL env var in detect_bpftool_path()
The bpftool_maps_access and bpftool_metadata tests may fail on BPF CI with "command not found", depending on a workflow. This happens because detect_bpftool_path() only checks two hardcoded relative paths: - ./tools/sbin/bpftool - ../tools/sbin/bpftool Add support for a BPFTOOL environment variable that allows specifying the exact path to the bpftool binary. Acked-by: Mykyta Yatsenko <yatsenko@meta.com> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20260223191118.655185-2-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent ad90ece commit a2714e7

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

tools/testing/selftests/bpf/bpftool_helpers.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
static int detect_bpftool_path(char *buffer, size_t size)
1515
{
1616
char tmp[BPFTOOL_PATH_MAX_LEN];
17+
const char *env_path;
18+
19+
/* First, check if BPFTOOL environment variable is set */
20+
env_path = getenv("BPFTOOL");
21+
if (env_path && access(env_path, X_OK) == 0) {
22+
strscpy(buffer, env_path, size);
23+
return 0;
24+
} else if (env_path) {
25+
fprintf(stderr, "bpftool '%s' doesn't exist or is not executable\n", env_path);
26+
return 1;
27+
}
1728

1829
/* Check default bpftool location (will work if we are running the
1930
* default flavor of test_progs)
@@ -33,7 +44,7 @@ static int detect_bpftool_path(char *buffer, size_t size)
3344
return 0;
3445
}
3546

36-
/* Failed to find bpftool binary */
47+
fprintf(stderr, "Failed to detect bpftool path, use BPFTOOL env var to override\n");
3748
return 1;
3849
}
3950

0 commit comments

Comments
 (0)