Compare commits

..

5 Commits

Author SHA1 Message Date
a7e2bc39ef Tests: Add a verifier level to the expected-failure tiers
test_config.toml could only declare a failure at the "ir" or "llc" level, and
test_verifier.py dropped every declared-xfail case from the level-3 run
outright. A program that generates IR and compiles cleanly but that the kernel
verifier rejects therefore had no way to be declared: it was silently treated
as must-pass at all three levels.

Levels now form an ordered pipeline (ir < llc < verifier) and a declared level
marks that level and every later one xfail, which is what the old
ir-implies-llc special case was expressing. Level 3 runs every test file and
reports declared failures as expected ones rather than skipping them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 17:07:23 +05:30
edefe626d0 Tests: Use a real program section in return, var_rval and if
These three declared @section("sometag1"), which is not a section name libbpf
can map to a program type:

    libbpf: failed to guess program type from ELF section 'sometag1'

so they were rejected before the kernel verifier ever saw them. They generate
IR and compile fine; only the section was wrong. Switch to
tracepoint/syscalls/sys_enter_execve, matching the other tracepoint tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 17:07:23 +05:30
f796338245 Tests: Silence deprecation warnings in test-cov and test-verifier
c2de7da added -W ignore::DeprecationWarning to the 'test' target only, so
'make test-cov' and 'make test-verifier' still drown in warnings from the
generated vmlinux.py.

Also correct the test-verifier note: the suite does not run pytest under sudo,
tests/framework/verifier.py shells out to 'sudo bpftool' itself.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 17:07:23 +05:30
c2de7dad96 Temporarily ignore deprecation warnings for vmlinux.py 2026-05-27 14:53:54 +05:30
d1bb0191c9 Merge pull request #84 from pythonbpf/testing-framework
Automated testing framework which will give us regression and coverage reports, meant to run in a GH Action and locally
2026-04-25 23:02:00 +05:30
8 changed files with 57 additions and 23 deletions

View File

@ -7,15 +7,16 @@ clean:
rm -rf htmlcov .coverage rm -rf htmlcov .coverage
test: test:
pytest tests/ -v --tb=short -m "not verifier" pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier"
test-cov: test-cov:
pytest tests/ -v --tb=short -m "not verifier" \ pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier" \
--cov=pythonbpf --cov-report=term-missing --cov-report=html --cov=pythonbpf --cov-report=term-missing --cov-report=html
test-verifier: test-verifier:
@echo "NOTE: verifier tests require sudo and bpftool. Uses sudo .venv/bin/python3." @echo "NOTE: verifier tests shell out to 'sudo bpftool'; run 'sudo -v' first so"
pytest tests/test_verifier.py -v --tb=short -m verifier @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 all: clean install

View File

@ -69,8 +69,16 @@ Known-broken tests are declared in `tests/test_config.toml`:
"failing_tests/my_test.py" = {reason = "...", level = "ir"} "failing_tests/my_test.py" = {reason = "...", level = "ir"}
``` ```
- `level = "ir"` — fails during IR generation; both IR and LLC tests are marked xfail. - `level = "ir"` — fails during IR generation.
- `level = "llc"` — IR generates fine but `llc` rejects it; only the LLC test is marked xfail. - `level = "llc"` — IR generates fine but `llc` rejects it.
- `level = "verifier"` — IR and `llc` both succeed, but the kernel verifier rejects the object.
A failure at one level implies failure at every later one, so the declared level marks
that level **and all later ones** xfail. An `"ir"` entry is xfail at all three levels; a
`"verifier"` entry is xfail at level 3 only and must still pass levels 1 and 2.
Every test file runs at every level, including the ones declared here — level 3 does not
skip declared failures, it reports them as expected ones.
All xfails use `strict = True`: if a test starts **passing** it shows up as **XPASS** and is treated as a test failure. This is intentional — it means the bug was fixed and the test should be promoted to `passing_tests/`. All xfails use `strict = True`: if a test starts **passing** it shows up as **XPASS** and is treated as a test failure. This is intentional — it means the bug was fixed and the test should be promoted to `passing_tests/`.

View File

@ -19,6 +19,7 @@ import logging
import pytest import pytest
from tests.framework.bpf_test_case import level_index
from tests.framework.collector import collect_all_test_files from tests.framework.collector import collect_all_test_files
# ── vmlinux availability ──────────────────────────────────────────────────── # ── vmlinux availability ────────────────────────────────────────────────────
@ -70,14 +71,19 @@ def pytest_collection_modifyitems(items):
# xfail (strict: XPASS counts as a test failure, alerting us to fixed bugs) # xfail (strict: XPASS counts as a test failure, alerting us to fixed bugs)
if case.is_expected_fail: if case.is_expected_fail:
# Level "ir" → fails at IR generation: xfail both IR and LLC tests # A failure at one level implies failure at every later one, so mark
# Level "llc" → IR succeeds but LLC fails: only xfail the LLC test # this item xfail whenever the declared level is at or before it:
is_llc_test = item.nodeid.startswith("tests/test_llc_compilation.py") # "ir" → IR, LLC and verifier
# "llc" → LLC and verifier (IR is expected to succeed)
# "verifier" → verifier only
if item.nodeid.startswith("tests/test_verifier.py"):
item_level = "verifier"
elif item.nodeid.startswith("tests/test_llc_compilation.py"):
item_level = "llc"
else:
item_level = "ir"
apply_xfail = (case.xfail_level == "ir") or ( if level_index(case.xfail_level) <= level_index(item_level):
case.xfail_level == "llc" and is_llc_test
)
if apply_xfail:
item.add_marker( item.add_marker(
pytest.mark.xfail( pytest.mark.xfail(
reason=case.xfail_reason, reason=case.xfail_reason,

View File

@ -3,7 +3,7 @@ from ctypes import c_void_p, c_int64
@bpf @bpf
@section("sometag1") @section("tracepoint/syscalls/sys_enter_execve")
def sometag(ctx: c_void_p) -> c_int64: def sometag(ctx: c_void_p) -> c_int64:
if 3 + 2 == 5: if 3 + 2 == 5:
return c_int64(5) return c_int64(5)

View File

@ -1,6 +1,20 @@
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
# The three test levels, in pipeline order. A test declared as failing at one
# level is also expected to fail at every later level: a program that cannot
# generate IR cannot reach llc, and one that llc rejects never reaches the
# kernel. Used by conftest to decide which items to mark xfail.
LEVELS = ("ir", "llc", "verifier")
def level_index(level: str) -> int:
"""Position of a level in the pipeline. Unknown levels sort first ("ir")."""
try:
return LEVELS.index(level)
except ValueError:
return 0
@dataclass @dataclass
class BpfTestCase: class BpfTestCase:
@ -8,7 +22,7 @@ class BpfTestCase:
rel_path: str rel_path: str
is_expected_fail: bool = False is_expected_fail: bool = False
xfail_reason: str = "" xfail_reason: str = ""
xfail_level: str = "ir" # "ir" or "llc" xfail_level: str = "ir" # one of LEVELS
needs_vmlinux: bool = False needs_vmlinux: bool = False
skip_reason: str = "" skip_reason: str = ""

View File

@ -3,7 +3,7 @@ from ctypes import c_void_p, c_int64
@bpf @bpf
@section("sometag1") @section("tracepoint/syscalls/sys_enter_execve")
def sometag(ctx: c_void_p) -> c_int64: def sometag(ctx: c_void_p) -> c_int64:
return c_int64(1 - 1) return c_int64(1 - 1)

View File

@ -5,7 +5,7 @@ from ctypes import c_void_p, c_int64
@bpf @bpf
@section("sometag1") @section("tracepoint/syscalls/sys_enter_execve")
def sometag(ctx: c_void_p) -> c_int64: def sometag(ctx: c_void_p) -> c_int64:
a = 1 - 1 a = 1 - 1
return c_int64(a) return c_int64(a)

View File

@ -24,12 +24,12 @@ from tests.framework.compiler import run_ir_generation, run_llc
from tests.framework.verifier import verify_object from tests.framework.verifier import verify_object
def _passing_test_files(): def _verifier_test_files():
return [c.path for c in collect_all_test_files() if not c.is_expected_fail] return [c.path for c in collect_all_test_files()]
def _passing_test_ids(): def _verifier_test_ids():
return [c.rel_path for c in collect_all_test_files() if not c.is_expected_fail] return [c.rel_path for c in collect_all_test_files()]
def _get_rejection_reason(verifier_test_file: Path, output) -> str: def _get_rejection_reason(verifier_test_file: Path, output) -> str:
@ -43,11 +43,16 @@ def _get_rejection_reason(verifier_test_file: Path, output) -> str:
return errstr return errstr
# Every test file runs at this level, including the ones declared in
# test_config.toml. conftest marks those xfail, so an "ir"- or "llc"-level
# failure is still reported as an expected failure rather than being silently
# dropped from the level-3 run — and a "verifier"-level entry becomes possible
# at all.
@pytest.mark.verifier @pytest.mark.verifier
@pytest.mark.parametrize( @pytest.mark.parametrize(
"verifier_test_file", "verifier_test_file",
_passing_test_files(), _verifier_test_files(),
ids=_passing_test_ids(), ids=_verifier_test_ids(),
) )
def test_kernel_verifier(verifier_test_file: Path, tmp_path, caplog): def test_kernel_verifier(verifier_test_file: Path, tmp_path, caplog):
"""Compile the BPF test and verify it passes the kernel verifier.""" """Compile the BPF test and verify it passes the kernel verifier."""