selftests/bpf: migrate a few bpftool testing scripts
Subsystems (3)
v4 cover selftests/bpf: migrate a few bpftool testing scripts
Hello,
this is the v4 for some bpftool tests conversion. The new tests are being integrated in test_progs so that they can be executed on each CI run.
- First commit introduces a few dedicated helpers to execute bpftool commands, with or without retrieving the generated stdout output
- Second commit integrates test_bpftool_metadata.sh into test_progs
- Third commit integrates test_bpftool_map.sh into test_progs
---
Changes in v4:
- Port missing map access test in bpftool_metadata
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Drop commit reordering objects in Makefile
- Rebased series on ci/bpf-next_base to fix conflict
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- drop standalone runner in favor of test_progs
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Alexis Lothoré (eBPF Foundation) (3):
bpf/selftests: add a few helpers for bpftool testing selftests/bpf: convert test_bpftool_metadata.sh into test_progs framework selftests/bpf: convert test_bpftool_map_access.sh into test_progs framework
tools/testing/selftests/bpf/Makefile | 5 +- tools/testing/selftests/bpf/bpftool_helpers.c | 74 ++++ tools/testing/selftests/bpf/bpftool_helpers.h | 11 + .../selftests/bpf/prog_tests/bpftool_maps_access.c | 371 +++++++++++++++++++ .../selftests/bpf/prog_tests/bpftool_metadata.c | 144 ++++++++ tools/testing/selftests/bpf/test_bpftool_map.sh | 398 --------------------- .../testing/selftests/bpf/test_bpftool_metadata.sh | 85 ----- 7 files changed, 602 insertions(+), 486 deletions(-)
---
base-commit: 5f0eb131037251b80c9a92af28c6be8f65d063d2
change-id: 20251212-bpftool-tests-bb165c4cceb8
Best regards,
Signature · 1 line
Alexis Lothoré (eBPF Foundation) <[email protected]>
PATCH v4 1/3 bpf/selftests: add a few helpers for bpftool testing
In order to integrate some bpftool tests into test_progs, define a few specific helpers that allow to execute bpftool commands, while possibly retrieving the command output. Those helpers most notably set the path to the bpftool binary under test. This version checks different possible paths relative to the directories where the different test_progs runners are executed, as we want to make sure not to accidentally use a bootstrap version of the binary.
---
Changes in v2:
- Drop the new runner from commit, keep only the new bpftool-specific helpers
- replace hardcoded path with a detected (and cached) path
--- tools/testing/selftests/bpf/Makefile | 3 +- tools/testing/selftests/bpf/bpftool_helpers.c | 74 +++++++++++++++++++++++++++ tools/testing/selftests/bpf/bpftool_helpers.h | 11 ++++ 3 files changed, 87 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +2 -1
@@ -747,7 +747,8 @@ TRUNNER_EXTRA_SOURCES := test_progs.c \ json_writer.c \ $(VERIFY_SIG_HDR) \ flow_dissector_load.h \ - ip_check_defrag_frags.h + ip_check_defrag_frags.h \ + bpftool_helpers.c TRUNNER_LIB_SOURCES := find_bit.c TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \ $(OUTPUT)/liburandom_read.so \
tools/testing/selftests/bpf/bpftool_helpers.c new file +74 -0
74 lines not on this page · raw message
tools/testing/selftests/bpf/bpftool_helpers.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#pragma once + +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> + +#define MAX_BPFTOOL_CMD_LEN (256) + +int run_bpftool_command (char *args); +int get_bpftool_command_output (char *args,char *output_buf,size_t output_max_len);
Signature · 1 line
2.52.0
PATCH v4 2/3 selftests/bpf: convert test_bpftool_metadata.sh into test_progs framework
In reply to Alexis Lothoré (eBPF Foundation)The test_bpftool_metadata.sh script validates that bpftool properly returns in its ouptput any metadata generated by bpf programs through some .rodata sections.
Port this test to the test_progs framework so that it can be executed automatically in CI. The new test, similarly to the former script, checks that valid data appears both for textual output and json output, as well as for both data not used at all and used data. For the json check part, the expected json string is hardcoded to avoid bringing a new external dependency (eg: a json deserializer) for test_progs. As the test is now converted into test_progs, remove the former script.
The newly converted test brings two new subtests:
#37/1 bpftool_metadata/metadata_unused:OK #37/2 bpftool_metadata/metadata_used:OK #37 bpftool_metadata:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
---
Changes in v4:
- add missing test checking access to the metadata map
Changes in v2:
- move the new test in prog_tests directory
- use power of 2 for bpftool output buffer size
- check snprintf return when building commands
- target program by pin path rather than prog name
- remove a few blank lines
--- tools/testing/selftests/bpf/Makefile | 1 - .../selftests/bpf/prog_tests/bpftool_metadata.c | 144 +++++++++++++++++++++ .../testing/selftests/bpf/test_bpftool_metadata.sh | 85 ------------ 3 files changed, 144 insertions(+), 86 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -1
@@ -109,7 +109,6 @@ TEST_PROGS := test_kmod.sh \ test_bpftool_build.sh \ test_bpftool.sh \ test_bpftool_map.sh \ - test_bpftool_metadata.sh \ test_doc_build.sh \ test_xsk.sh \ test_xdp_features.sh
tools/testing/selftests/bpf/prog_tests/bpftool_metadata.c new file +144 -0
144 lines not on this page · raw message
tools/testing/selftests/bpf/test_bpftool_metadata.sh deleted +0 -85
85 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v4 3/3 selftests/bpf: convert test_bpftool_map_access.sh into test_progs framework
In reply to Alexis Lothoré (eBPF Foundation)The test_bpftool_map.sh script tests that maps read/write accesses are being properly allowed/refused by the kernel depending on a specific fmod_ret program being attached on security_bpf_map function.
Rewrite this test to integrate it in the test_progs. The new test spawns a few subtests:
#36/1 bpftool_maps_access/unprotected_unpinned:OK #36/2 bpftool_maps_access/unprotected_pinned:OK #36/3 bpftool_maps_access/protected_unpinned:OK #36/4 bpftool_maps_access/protected_pinned:OK #36/5 bpftool_maps_access/nested_maps:OK #36/6 bpftool_maps_access/btf_list:OK #36 bpftool_maps_access:OK
Summary: 1/6 PASSED, 0 SKIPPED, 0 FAILED
---
Changes in v2:
- move the new test in prog_tests directory
- collect Quentin's AB
--- tools/testing/selftests/bpf/Makefile | 1 - .../selftests/bpf/prog_tests/bpftool_maps_access.c | 371 +++++++++++++++++++ tools/testing/selftests/bpf/test_bpftool_map.sh | 398 --------------------- 3 files changed, 371 insertions(+), 399 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -1
@@ -108,7 +108,6 @@ TEST_PROGS := test_kmod.sh \ test_xdping.sh \ test_bpftool_build.sh \ test_bpftool.sh \ - test_bpftool_map.sh \ test_doc_build.sh \ test_xsk.sh \ test_xdp_features.sh
tools/testing/selftests/bpf/prog_tests/bpftool_maps_access.c new file +371 -0
371 lines not on this page · raw message
tools/testing/selftests/bpf/test_bpftool_map.sh deleted +0 -398
398 lines not on this page · raw message
Signature · 1 line
2.52.0
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Fri, 23 Jan 2026 09:30:07 +0100 you wrote:
Hello,
this is the v4 for some bpftool tests conversion. The new tests are being integrated intest_progsso that they can be executed on each CI run.- First commit introduces a few dedicated helpers to execute bpftool commands, with or without retrieving the generated stdout output
- Second commit integratestest_bpftool_metadata.shintotest_progs
- Third commit integratestest_bpftool_map.shintotest_progs[...]
Here is the summary with links:
- [bpf-next,v4,1/3] bpf/selftests: add a few helpers for bpftool testing
https://git.kernel.org/bpf/bpf-next/c/f21fae577446 - [bpf-next,v4,2/3] selftests/bpf: convert test_bpftool_metadata.sh into test_progs framework https://git.kernel.org/bpf/bpf-next/c/1c0b505908a2 - [bpf-next,v4,3/3] selftests/bpf: convert test_bpftool_map_access.sh into test_progs framework https://git.kernel.org/bpf/bpf-next/c/2d96bbdfd3b5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html