run_6400_pi_differential.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. """Run L7 bit-exact thermal-control-lab versus production RTL differential."""
  3. from __future__ import annotations
  4. import os
  5. from pathlib import Path
  6. import tempfile
  7. import xml.etree.ElementTree as ET
  8. try:
  9. from cocotb_tools.runner import get_runner
  10. except ModuleNotFoundError:
  11. from cocotb.runner import get_runner
  12. ROOT = Path(__file__).resolve().parents[2]
  13. TEST_DIR = Path(__file__).resolve().parent
  14. def main() -> int:
  15. lab = ROOT.parent / "thermal-control-lab" / "thermal_control_lab" / "fixed_point" / "pi.py"
  16. if not lab.is_file():
  17. raise RuntimeError(f"thermal-control-lab reference model is missing: {lab}")
  18. with tempfile.TemporaryDirectory(prefix="prod2u-6400-pi-differential-") as directory:
  19. build_dir = Path(directory)
  20. os.environ["HYPOTHESIS_STORAGE_DIRECTORY"] = str(build_dir / "hypothesis")
  21. runner = get_runner("icarus")
  22. runner.build(
  23. sources=[
  24. ROOT / "src/common/ef2_bram_dp.v",
  25. ROOT / "src/control/thermal_output_banks.v",
  26. ROOT / "src/control/stimulus_atomic_bank.v",
  27. ROOT / "src/control/thermal_control_core.v",
  28. TEST_DIR / "thermal_control_core_cocotb_top.v",
  29. ],
  30. hdl_toplevel="thermal_control_core_cocotb_top",
  31. build_dir=build_dir,
  32. build_args=["-g2012"],
  33. always=True,
  34. )
  35. result = Path(runner.test(
  36. hdl_toplevel="thermal_control_core_cocotb_top",
  37. test_module="test_6400_pi_differential",
  38. test_dir=TEST_DIR,
  39. build_dir=build_dir,
  40. results_xml=str(build_dir / "results.xml"),
  41. ))
  42. root = ET.parse(result).getroot()
  43. cases = root.findall(".//testcase")
  44. failures = root.findall(".//failure") + root.findall(".//error")
  45. skipped = root.findall(".//skipped")
  46. if not cases or failures or skipped:
  47. raise RuntimeError(
  48. f"PI differential incomplete: cases={len(cases)} failures={len(failures)} "
  49. f"skipped={len(skipped)} results={result}"
  50. )
  51. print("PASS: L7 bit-exact Python/RTL PI differential")
  52. return 0
  53. if __name__ == "__main__":
  54. raise SystemExit(main())