From 559d0570ff2b7f5e4bfbb0be62b0ab89594018f9 Mon Sep 17 00:00:00 2001 From: Varun R Mallya Date: Sun, 30 Aug 2026 19:49:23 +0530 Subject: [PATCH] regenerate and symlink a single master vmlinux.py for make test - make test/test-cov/test-verifier now depend on a 'vmlinux' target that regenerates vmlinux.py from the running kernel's BTF and symlinks it into every directory under tests/, replacing the stale, duplicated vmlinux.py fixtures that used to be committed there. - collector.py now skips the 'vmlinux.py' filename when collecting BPF test cases, since it's a fixture module, not a test program - it was previously being mis-collected and compiled as a bogus test. - functions_pass.py: llvmlite >=0.49 renamed the 'nocapture' argument attribute to 'captures(none)'. --- Makefile | 19 +++++++++++++++---- pythonbpf/functions/functions_pass.py | 2 +- tests/framework/collector.py | 4 ++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 5e3be67..fe3332e 100644 --- a/Makefile +++ b/Makefile @@ -6,18 +6,29 @@ clean: rm -rf examples/*.ll examples/*.o rm -rf htmlcov .coverage -test: +# Regenerate the master vmlinux.py from the running kernel's BTF, then +# symlink it into every directory under tests/ so both pytest (which +# resolves "import vmlinux" via pythonpath=["."]) and any test file run +# standalone from its own directory see the same, always-fresh fixture. +vmlinux: + python3 tools/vmlinux-gen.py -o vmlinux.py + @find tests -type d -not -path '*/__pycache__*' | while read -r d; do \ + target=$$(python3 -c "import os,sys; print(os.path.relpath('vmlinux.py', sys.argv[1]))" "$$d"); \ + ln -sf "$$target" "$$d/vmlinux.py"; \ + done + +test: vmlinux pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier" -test-cov: +test-cov: vmlinux pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier" \ --cov=pythonbpf --cov-report=term-missing --cov-report=html -test-verifier: +test-verifier: vmlinux @echo "NOTE: verifier tests shell out to 'sudo bpftool'; run 'sudo -v' first so" @echo " the timestamp does not lapse mid-run. bpftool must be installed." pytest tests/test_verifier.py -W ignore::DeprecationWarning -v --tb=short -m verifier all: clean install -.PHONY: all clean install test test-cov test-verifier +.PHONY: all clean install test test-cov test-verifier vmlinux diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 89e87af..69be323 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -403,7 +403,7 @@ def process_bpf_chunk(func_node, compilation_context, return_type): if func_node.args.args: # Only look at the first argument for now param = func.args[0] - param.add_attribute("nocapture") + param.add_attribute("captures(none)") probe_string = get_probe_string(func_node) if probe_string is not None: diff --git a/tests/framework/collector.py b/tests/framework/collector.py index c40da23..bdafc14 100644 --- a/tests/framework/collector.py +++ b/tests/framework/collector.py @@ -35,6 +35,10 @@ def collect_all_test_files() -> list[BpfTestCase]: cases = [] for subdir in ("passing_tests", "failing_tests"): for py_file in sorted((TESTS_DIR / subdir).rglob("*.py")): + if py_file.name == "vmlinux.py": + # Not a test case: the per-directory symlink to the master + # vmlinux fixture module, kept alongside tests that import it. + continue rel = str(py_file.relative_to(TESTS_DIR)) needs_vmlinux = _is_vmlinux_test(rel)