[Devel] [PATCH vz10 3/4] selftests/bpf: use the bpftool built with the tests in test_bpftool_map

Eva Kurchatova eva.kurchatova at virtuozzo.com
Fri Aug 21 18:09:59 MSK 2026


The test loads a program that denies write access to a map and then
checks that reading it still works.  Reading it through a bpftool that
opens the map for writing therefore fails:

  Error: can't get map by id (68627): Operation not permitted
   Read access to 0 0 0 0 in prot_map failed

which is what the bpftool of the distribution does here, v7.5.0 against
the v7.7.0 built from this tree.  Prefer the one next to the test, and
fall back to $PATH when it is not there.

https://virtuozzo.atlassian.net/browse/VSTOR-139677
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
---
 tools/testing/selftests/bpf/test_bpftool_map.sh | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_bpftool_map.sh b/tools/testing/selftests/bpf/test_bpftool_map.sh
index 515b1df0501e..e5f5e3b8dc02 100755
--- a/tools/testing/selftests/bpf/test_bpftool_map.sh
+++ b/tools/testing/selftests/bpf/test_bpftool_map.sh
@@ -18,7 +18,16 @@ BPF_DIR="$BPF_FS_PARENT/test_$TESTNAME"
 SCRIPT_DIR=$(dirname $(realpath "$0"))
 BPF_FILE_PATH="$SCRIPT_DIR/$BPF_FILE"
 BPF_ITER_FILE_PATH="$SCRIPT_DIR/$BPF_ITER_FILE"
-BPFTOOL_PATH="bpftool"
+# Prefer the bpftool that was built together with these tests.  The
+# protection checked here needs one that opens a map read only to look
+# it up, and the bpftool of the distribution can be too old for that:
+# it opens the map for writing, the fmod_ret program denies that, and
+# the read is reported as failed.
+if [ -x "$SCRIPT_DIR/bpftool" ]; then
+	BPFTOOL_PATH="$SCRIPT_DIR/bpftool"
+else
+	BPFTOOL_PATH="bpftool"
+fi
 # Assume the script is located under tools/testing/selftests/bpf/
 KDIR_ROOT_DIR=$(realpath "$SCRIPT_DIR"/../../../../)
 
-- 
2.55.0



More information about the Devel mailing list