Tests: USe namedtuple to pass verifier output for asserts

This commit is contained in:
Pragyansh Chaturvedi
2026-04-25 18:54:25 +05:30
parent 145e930389
commit 48fa8aec3f
2 changed files with 15 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import subprocess import subprocess
import uuid import uuid
from collections import namedtuple
from pathlib import Path from pathlib import Path
@ -17,7 +18,8 @@ def verify_object(obj_path: Path) -> tuple[bool, str]:
text=True, text=True,
timeout=30, timeout=30,
) )
output = result.stdout + result.stderr Output = namedtuple("Output", ["stdout", "stderr"])
output = Output(stdout=result.stdout, stderr=result.stderr)
return result.returncode == 0, output return result.returncode == 0, output
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
return False, "bpftool timed out after 30s" return False, "bpftool timed out after 30s"

View File

@ -40,6 +40,17 @@ def _passing_test_ids():
] ]
def _get_rejection_reason(verifier_test_file: Path, output) -> str:
# Extract the reason for rejection from the verifier output
errstr = f"Verifier rejected {verifier_test_file.name}:\n"
errstr += "=" * 80 + "\n"
errstr += f"stdout:\n{output.stdout}\n"
errstr += "=" * 80 + "\n"
errstr += f"stderr:\n{output.stderr}\n"
errstr += "=" * 80 + "\n"
return errstr
@pytest.mark.verifier @pytest.mark.verifier
@pytest.mark.parametrize( @pytest.mark.parametrize(
"verifier_test_file", "verifier_test_file",
@ -62,4 +73,4 @@ def test_kernel_verifier(verifier_test_file: Path, tmp_path, caplog):
assert obj_path.exists() and obj_path.stat().st_size > 0 assert obj_path.exists() and obj_path.stat().st_size > 0
ok, output = verify_object(obj_path) ok, output = verify_object(obj_path)
assert ok, f"Kernel verifier rejected {verifier_test_file.name}:\n{output}" assert ok, _get_rejection_reason(verifier_test_file, output)