feat: init mlkem project with Verilator test framework
- sync_rtl/common/: skid_buffer, pipeline_reg, defines (valid/ready) - sync_rtl/mod_add/: modular adder example with Verilator C++ TB - test_framework/: Python-driven Verilator compile/sim/compare pipeline - test_framework/modules/mod_add/: 50-vector test plan, full鏈路 PASS - .trellis/spec/: RTL and test_framework conventions documented
This commit is contained in:
45
test_framework/lib/result_checker.py
Normal file
45
test_framework/lib/result_checker.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""result_checker.py - Compares simulation output against expected values."""
|
||||
|
||||
|
||||
def check_results(got: list[str], expected_file: str) -> tuple[int, int]:
|
||||
"""Compare Verilator output against expected values.
|
||||
|
||||
Args:
|
||||
got: List of result strings from simulation (hex values).
|
||||
expected_file: Path to file containing expected hex values, one per line.
|
||||
|
||||
Returns:
|
||||
tuple[int, int]: (num_pass, num_fail).
|
||||
"""
|
||||
# Read expected values
|
||||
expected = []
|
||||
try:
|
||||
with open(expected_file, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#'):
|
||||
expected.append(line)
|
||||
except FileNotFoundError:
|
||||
print(f"[ERROR] Expected file not found: {expected_file}")
|
||||
return (0, len(got))
|
||||
|
||||
num_pass = 0
|
||||
num_fail = 0
|
||||
|
||||
max_len = max(len(got), len(expected))
|
||||
|
||||
for i in range(max_len):
|
||||
got_val = got[i].upper() if i < len(got) else 'MISSING'
|
||||
exp_val = expected[i].upper() if i < len(expected) else 'MISSING'
|
||||
|
||||
if got_val == exp_val:
|
||||
num_pass += 1
|
||||
else:
|
||||
num_fail += 1
|
||||
if num_fail <= 5: # Only show first 5 failures
|
||||
print(f" MISMATCH[{i}]: got={got_val}, expected={exp_val}")
|
||||
|
||||
if num_fail > 5:
|
||||
print(f" ... and {num_fail - 5} more mismatches")
|
||||
|
||||
return (num_pass, num_fail)
|
||||
Reference in New Issue
Block a user