Skip to content

Commit 48fa8ae

Browse files
committed
Tests: USe namedtuple to pass verifier output for asserts
1 parent 145e930 commit 48fa8ae

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

tests/framework/verifier.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import subprocess
22
import uuid
3+
from collections import namedtuple
34
from pathlib import Path
45

56

@@ -17,7 +18,8 @@ def verify_object(obj_path: Path) -> tuple[bool, str]:
1718
text=True,
1819
timeout=30,
1920
)
20-
output = result.stdout + result.stderr
21+
Output = namedtuple("Output", ["stdout", "stderr"])
22+
output = Output(stdout=result.stdout, stderr=result.stderr)
2123
return result.returncode == 0, output
2224
except subprocess.TimeoutExpired:
2325
return False, "bpftool timed out after 30s"

tests/test_verifier.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ def _passing_test_ids():
4040
]
4141

4242

43+
def _get_rejection_reason(verifier_test_file: Path, output) -> str:
44+
# Extract the reason for rejection from the verifier output
45+
errstr = f"Verifier rejected {verifier_test_file.name}:\n"
46+
errstr += "=" * 80 + "\n"
47+
errstr += f"stdout:\n{output.stdout}\n"
48+
errstr += "=" * 80 + "\n"
49+
errstr += f"stderr:\n{output.stderr}\n"
50+
errstr += "=" * 80 + "\n"
51+
return errstr
52+
53+
4354
@pytest.mark.verifier
4455
@pytest.mark.parametrize(
4556
"verifier_test_file",
@@ -62,4 +73,4 @@ def test_kernel_verifier(verifier_test_file: Path, tmp_path, caplog):
6273
assert obj_path.exists() and obj_path.stat().st_size > 0
6374

6475
ok, output = verify_object(obj_path)
65-
assert ok, f"Kernel verifier rejected {verifier_test_file.name}:\n{output}"
76+
assert ok, _get_rejection_reason(verifier_test_file, output)

0 commit comments

Comments
 (0)