mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 18:08:36 +00:00
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>
103 lines
3.5 KiB
Python
103 lines
3.5 KiB
Python
"""
|
|
pytest configuration for the PythonBPF test suite.
|
|
|
|
Test discovery:
|
|
All .py files under tests/passing_tests/ and tests/failing_tests/ are
|
|
collected as parametrized BPF test cases.
|
|
|
|
Markers applied automatically from test_config.toml:
|
|
- xfail (strict=True): failing_tests/ entries that are expected to fail
|
|
- skip: vmlinux tests when vmlinux.py is not importable
|
|
|
|
Run the suite:
|
|
pytest tests/ -v -m "not verifier" # IR + LLC only (no sudo)
|
|
pytest tests/ -v --cov=pythonbpf # with coverage
|
|
pytest tests/test_verifier.py -m verifier # kernel verifier (sudo required)
|
|
"""
|
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from tests.framework.bpf_test_case import level_index
|
|
from tests.framework.collector import collect_all_test_files
|
|
|
|
# ── vmlinux availability ────────────────────────────────────────────────────
|
|
|
|
try:
|
|
import vmlinux # noqa: F401
|
|
|
|
VMLINUX_AVAILABLE = True
|
|
except ImportError:
|
|
VMLINUX_AVAILABLE = False
|
|
|
|
|
|
# ── pytest_generate_tests: parametrize on bpf_test_file ───────────────────
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
if "bpf_test_file" in metafunc.fixturenames:
|
|
cases = collect_all_test_files()
|
|
metafunc.parametrize(
|
|
"bpf_test_file",
|
|
[c.path for c in cases],
|
|
ids=[c.rel_path for c in cases],
|
|
)
|
|
|
|
|
|
# ── pytest_collection_modifyitems: apply xfail / skip markers ─────────────
|
|
|
|
|
|
def pytest_collection_modifyitems(items):
|
|
case_map = {c.rel_path: c for c in collect_all_test_files()}
|
|
|
|
for item in items:
|
|
# Resolve the test case from the parametrize ID embedded in the node id.
|
|
# Node id format: tests/test_foo.py::test_bar[passing_tests/helpers/pid.py]
|
|
case = None
|
|
for bracket in (item.callspec.id,) if hasattr(item, "callspec") else ():
|
|
case = case_map.get(bracket)
|
|
break
|
|
|
|
if case is None:
|
|
continue
|
|
|
|
# vmlinux skip
|
|
if case.needs_vmlinux and not VMLINUX_AVAILABLE:
|
|
item.add_marker(
|
|
pytest.mark.skip(reason="vmlinux.py not available for current kernel")
|
|
)
|
|
continue
|
|
|
|
# xfail (strict: XPASS counts as a test failure, alerting us to fixed bugs)
|
|
if case.is_expected_fail:
|
|
# A failure at one level implies failure at every later one, so mark
|
|
# this item xfail whenever the declared level is at or before it:
|
|
# "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"
|
|
|
|
if level_index(case.xfail_level) <= level_index(item_level):
|
|
item.add_marker(
|
|
pytest.mark.xfail(
|
|
reason=case.xfail_reason,
|
|
strict=True,
|
|
raises=Exception,
|
|
)
|
|
)
|
|
|
|
|
|
# ── caplog level fixture: capture ERROR+ from pythonbpf ───────────────────
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def set_log_level(caplog):
|
|
with caplog.at_level(logging.ERROR, logger="pythonbpf"):
|
|
yield
|