Skip to content

selftests/bpf: add a new runner for bpftool tests#10712

Closed
kernel-patches-daemon-bpf[bot] wants to merge 4 commits intobpf-next_basefrom
series/1042188=>bpf-next
Closed

selftests/bpf: add a new runner for bpftool tests#10712
kernel-patches-daemon-bpf[bot] wants to merge 4 commits intobpf-next_basefrom
series/1042188=>bpf-next

Conversation

@kernel-patches-daemon-bpf
Copy link
Copy Markdown

Pull request for series with
subject: selftests/bpf: add a new runner for bpftool tests
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1042188

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 46c7676
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1042188
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: e3d0dbb
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1042188
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 9a403a4
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1042188
version: 1

The test_progs runner defines a large set of convenient assert macros to
perform all the tests. Writing a new runner involves rewriting some
macros if we want some basic testing features like standardized failure
log.

Export those assert macros from test_progs into a dedicated header so
that we can use those in any test_runner. The sole requirement to be
able to use those macros is to define a test__fail function in the
runner that will be called whenever an assert fails.

Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
Acked-by: Quentin Monnet <qmo@kernel.org>
@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 9a403a4
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1042188
version: 1

The tools/testing/selftests/bpf directory contains multiple scripts
(shell, python, c code, etc) that aim to test some specific features
from bpftool. Those isolated tests are currently not executed by any CI
automation. Create a dedicated runner for any bpftool-related test that
can then be added to the list of executed runners in bpf CI automation.
This new runner (and the corresponding Makefile tooling) is highly
inspired from test_progs, but kept a bit simpler. This version supports
the following features:

- autodetection of bpftool test stored in the in bpftool_tests
  directory
- bpftool binary under test is passed as runner argument
- a few helpers to allow to easily run abpftool commands while possibly
  collecting the output
- usage of assert macros shared with test_progs
- basic sub-tests management
- logs collection, logs being dumped only for failed tests
- exit code reflecting whether all tests have passed or not

As this runner needs at least one test to be implemented to properly
compile, also bring bpftool_metadata, which is the conversion of
test_bpftool_metadata.sh: this test validates that the output of some
basic prog/map listings done with bpftool properly returns the metadata
collected from the .rodata section of eBPF programs.

This new runner gives an output similar to the one generated by
test_progs:

  #2/1	metadata/metadata_unused: OK
  #2/2	metadata/metadata_used: OK
  #2	metadata: OK
  Summary: 1 PASSED, 0 FAILED

Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
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 new test_bpftool runner. The
new test spawns a few subtests:

  #1/1	maps_access/unprotected_unpinned: OK
  #1/2	maps_access/unprotected_pinned: OK
  #1/3	maps_access/protected_unpinned: OK
  #1/4	maps_access/protected_pinned: OK
  #1/5	maps_access/nested_maps: OK
  #1/6	maps_access/btf_list: OK
  #1	maps_access: OK
  #2/1	metadata/metadata_unused: OK
  #2/2	metadata/metadata_used: OK
  #2	metadata: OK
  Summary: 2 PASSED, 0 FAILED

Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
Acked-by: Quentin Monnet <qmo@kernel.org>
Now that test_bpftool_map.sh and test_bpftool_metadata.sh are integrated
into test_bpftool runner, remove those.

Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
Acked-by: Quentin Monnet <qmo@kernel.org>
@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1042188 expired. Closing PR.

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot deleted the series/1042188=>bpf-next branch January 17, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant