test_prod2u_p4_minimal_snapshot_contract_rtl.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python3
  2. """Run the minimal independent-axis snapshot contract directly with Icarus."""
  3. from __future__ import annotations
  4. import subprocess
  5. import tempfile
  6. from pathlib import Path
  7. from tools import prod2u_p4_harness as harness
  8. ROOT = Path(__file__).resolve().parents[2]
  9. TESTBENCH = ROOT / "tests/sim/prod2u_p4_minimal_snapshot_contract_tb.v"
  10. SOURCES = (
  11. ROOT / "src/rtl/binary921_crc16.v",
  12. ROOT / "src/rtl/prod2u_p4_normal_v3_output_state.v",
  13. ROOT / "src/rtl/prod2u_p4_normal_v3_watchdog.v",
  14. ROOT / "src/rtl/prod2u_p4_axis_executor.v",
  15. ROOT / "src/rtl/prod2u_p4_motor_hub.v",
  16. ROOT / "src/rtl/prod2u_p4_response_scheduler.v",
  17. ROOT / "src/rtl/prod2u_p4_normal_v3_core.v",
  18. TESTBENCH,
  19. )
  20. def test_minimal_snapshot_contract_rtl() -> None:
  21. iverilog = harness.resolve_tool("iverilog")
  22. vvp = harness.resolve_tool("vvp")
  23. assert iverilog is not None, "Icarus Verilog is required"
  24. assert vvp is not None, "vvp is required"
  25. with tempfile.TemporaryDirectory(prefix="p4-minimal-snapshot-") as temporary:
  26. executable = Path(temporary) / "minimal_snapshot.vvp"
  27. compile_result = subprocess.run(
  28. [
  29. str(iverilog),
  30. "-g2005-sv",
  31. "-s",
  32. "prod2u_p4_minimal_snapshot_contract_tb",
  33. "-o",
  34. str(executable),
  35. *(str(path) for path in SOURCES),
  36. ],
  37. cwd=ROOT,
  38. env=harness.tool_env(),
  39. capture_output=True,
  40. text=True,
  41. timeout=60,
  42. check=False,
  43. )
  44. assert compile_result.returncode == 0, (
  45. compile_result.stdout + compile_result.stderr
  46. )
  47. run_result = subprocess.run(
  48. [str(vvp), str(executable)],
  49. cwd=ROOT,
  50. env=harness.tool_env(),
  51. capture_output=True,
  52. text=True,
  53. timeout=60,
  54. check=False,
  55. )
  56. output = run_result.stdout + run_result.stderr
  57. assert run_result.returncode == 0, output
  58. assert "PASS: prod2u_p4_minimal_snapshot_contract_tb" in output