selftests/bpf: migrate a few bpftool testing scripts
Subsystems (3)
v2 cover selftests/bpf: migrate a few bpftool testing scripts
Hello,
this is the v2 for some bpftool tests conversion. This new version drops a large part of the previous version, as it eventually integrates the converted tests into test_progs rather than into a new dedicated runner. The new tests however are almost identical to those in v1, as the dropped test_bpftool runner was exposing the same kind of features as those in test_progs.
- First commit is just a small cleanup, reordering files in the selftests Makefile
- Second commit introduces a few dedicated helpers to execute bpftool commands, with or without retrieving the generated stdout output
- Third commit integrates test_bpftool_metadata.sh into test_progs
- Fourth commit integrates test_bpftool_map.sh into test_progs
---
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) (4):
selftests/bpf: reorder test_progs sources alphabetically 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 | 39 +- 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 | 134 +++++++ tools/testing/selftests/bpf/test_bpftool_map.sh | 398 --------------------- .../testing/selftests/bpf/test_bpftool_metadata.sh | 85 ----- 7 files changed, 609 insertions(+), 503 deletions(-)
---
base-commit: cb353e9f65bd5eb7025211f36bdab6c43d27f6f4
change-id: 20251212-bpftool-tests-bb165c4cceb8
Best regards,
Signature · 1 line
Alexis Lothoré (eBPF Foundation) <[email protected]>
PATCH v2 1/4 selftests/bpf: reorder test_progs sources alphabetically
Update test_progs sources listing to make those sorted alphabetically
---
Changes in v2:
- new commit
--- tools/testing/selftests/bpf/Makefile | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
tools/testing/selftests/bpf/Makefile +18 -18
@@ -729,25 +729,25 @@ $(VERIFY_SIG_HDR): $(VERIFICATION_CERT) # Define test_progs test runner. TRUNNER_TESTS_DIR := prog_tests TRUNNER_BPF_PROGS_DIR := progs -TRUNNER_EXTRA_SOURCES := test_progs.c \ - cgroup_helpers.c \ - trace_helpers.c \ - network_helpers.c \ - testing_helpers.c \ - btf_helpers.c \ - cap_helpers.c \ - unpriv_helpers.c \ - netlink_helpers.c \ - jit_disasm_helpers.c \ - io_helpers.c \ - test_loader.c \ - xsk.c \ - disasm.c \ - disasm_helpers.c \ - json_writer.c \ +TRUNNER_EXTRA_SOURCES := btf_helpers.c \ + cap_helpers.c \ + cgroup_helpers.c \ + disasm.c \ + disasm_helpers.c \ + flow_dissector_load.h \ + ip_check_defrag_frags.h \ + io_helpers.c \ + jit_disasm_helpers.c \ + json_writer.c \ + netlink_helpers.c \ + network_helpers.c \ + test_loader.c \ + test_progs.c \ + testing_helpers.c \ + trace_helpers.c \ + unpriv_helpers.c \ $(VERIFY_SIG_HDR) \ - flow_dissector_load.h \ - ip_check_defrag_frags.h + xsk.c TRUNNER_LIB_SOURCES := find_bit.c TRUNNER_EXTRA_FILES := \ $(OUTPUT)/xdp_synproxy \
Signature · 1 line
2.52.0
Re: [PATCH bpf-next v2 1/4] selftests/bpf: reorder test_progs sources alphabetically
Quoted 2 lines · Alexis Lothoré (eBPF Foundation)
Update
test_progssources listing to make those sorted alphabetically
...
Quoted 9 lines
tools/testing/selftests/bpf/Makefile +0
-9-TRUNNER_EXTRA_SOURCES := test_progs.c \ - cgroup_helpers.c \ - trace_helpers.c \ - network_helpers.c \ - testing_helpers.c \ - btf_helpers.c \ - cap_helpers.c \ - unpriv_helpers.c \ - netlink_helpers.c \
tools/testing/selftests/bpf/Makefile $(VERIFY_SIG_HDR): $(VERIFICATION_CERT) · line 734
Quoted 10 lines
tools/testing/selftests/bpf/Makefile +3
-7- jit_disasm_helpers.c \ - io_helpers.c \ - test_loader.c \ - xsk.c \ - disasm.c \ - disasm_helpers.c \ - json_writer.c \ +TRUNNER_EXTRA_SOURCES := btf_helpers.c \ + cap_helpers.c \ + cgroup_helpers.c \
no need. Even if we sort it now it will not stick. Files might get renamed, new files added to the end, etc. Just add whatever you need to the end.
Also see that there is a merge conflict. Pls respin.
Re: [PATCH bpf-next v2 1/4] selftests/bpf: reorder test_progs sources alphabetically
Hi Alexei,
Quoted 22 lines · Alexei Starovoitov
Quoted 2 lines · Alexis Lothoré (eBPF Foundation)
Update
test_progssources listing to make those sorted alphabetically...
Quoted 16 lines
tools/testing/selftests/bpf/Makefile +0
-16-TRUNNER_EXTRA_SOURCES := test_progs.c \ - cgroup_helpers.c \ - trace_helpers.c \ - network_helpers.c \ - testing_helpers.c \ - btf_helpers.c \ - cap_helpers.c \ - unpriv_helpers.c \ - netlink_helpers.c \ - jit_disasm_helpers.c \ - io_helpers.c \ - test_loader.c \ - xsk.c \ - disasm.c \ - disasm_helpers.c \ - json_writer.c \
Quoted 8 lines
tools/testing/selftests/bpf/Makefile $(VERIFY_SIG_HDR): $(VERIFICATION_CERT) · line 734
Quoted 3 lines
tools/testing/selftests/bpf/Makefile +3
-0+TRUNNER_EXTRA_SOURCES := btf_helpers.c \ + cap_helpers.c \ + cgroup_helpers.c \no need. Even if we sort it now it will not stick. Files might get renamed, new files added to the end, etc. Just add whatever you need to the end.
Ok, I'll remove it and just add bpftool_helpers at the end.
Quoted 1 line
Also see that there is a merge conflict. Pls respin.
ACK, will do.
Thanks,
Alexis
Signature · 3 lines
Alexis Lothoré, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v2 2/4 bpf/selftests: add a few helpers for bpftool testing
In reply to Alexis Lothoré (eBPF Foundation)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 | 1 + tools/testing/selftests/bpf/bpftool_helpers.c | 74 +++++++++++++++++++++++++++ tools/testing/selftests/bpf/bpftool_helpers.h | 11 ++++ 3 files changed, 86 insertions(+)
tools/testing/selftests/bpf/Makefile +1 -0
@@ -730,6 +730,7 @@ $(VERIFY_SIG_HDR): $(VERIFICATION_CERT) TRUNNER_TESTS_DIR := prog_tests TRUNNER_BPF_PROGS_DIR := progs TRUNNER_EXTRA_SOURCES := btf_helpers.c \ + bpftool_helpers.c \ cap_helpers.c \ cgroup_helpers.c \ disasm.c \
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 v2 3/4 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 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 | 134 +++++++++++++++++++++ .../testing/selftests/bpf/test_bpftool_metadata.sh | 85 ------------- 3 files changed, 134 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 +134 -0
134 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 v2 4/4 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