| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #!/usr/bin/env python3
- """Run the minimal independent-axis snapshot contract directly with Icarus."""
- from __future__ import annotations
- import subprocess
- import tempfile
- from pathlib import Path
- from tools import prod2u_p4_harness as harness
- ROOT = Path(__file__).resolve().parents[2]
- TESTBENCH = ROOT / "tests/sim/prod2u_p4_minimal_snapshot_contract_tb.v"
- SOURCES = (
- ROOT / "src/rtl/binary921_crc16.v",
- ROOT / "src/rtl/prod2u_p4_normal_v3_output_state.v",
- ROOT / "src/rtl/prod2u_p4_normal_v3_watchdog.v",
- ROOT / "src/rtl/prod2u_p4_axis_executor.v",
- ROOT / "src/rtl/prod2u_p4_motor_hub.v",
- ROOT / "src/rtl/prod2u_p4_response_scheduler.v",
- ROOT / "src/rtl/prod2u_p4_normal_v3_core.v",
- TESTBENCH,
- )
- def test_minimal_snapshot_contract_rtl() -> None:
- iverilog = harness.resolve_tool("iverilog")
- vvp = harness.resolve_tool("vvp")
- assert iverilog is not None, "Icarus Verilog is required"
- assert vvp is not None, "vvp is required"
- with tempfile.TemporaryDirectory(prefix="p4-minimal-snapshot-") as temporary:
- executable = Path(temporary) / "minimal_snapshot.vvp"
- compile_result = subprocess.run(
- [
- str(iverilog),
- "-g2005-sv",
- "-s",
- "prod2u_p4_minimal_snapshot_contract_tb",
- "-o",
- str(executable),
- *(str(path) for path in SOURCES),
- ],
- cwd=ROOT,
- env=harness.tool_env(),
- capture_output=True,
- text=True,
- timeout=60,
- check=False,
- )
- assert compile_result.returncode == 0, (
- compile_result.stdout + compile_result.stderr
- )
- run_result = subprocess.run(
- [str(vvp), str(executable)],
- cwd=ROOT,
- env=harness.tool_env(),
- capture_output=True,
- text=True,
- timeout=60,
- check=False,
- )
- output = run_result.stdout + run_result.stderr
- assert run_result.returncode == 0, output
- assert "PASS: prod2u_p4_minimal_snapshot_contract_tb" in output
|