run_6400_pi_differential.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. LAB_ROOT = Path(os.environ.get(
  15. "THERMAL_CONTROL_LAB_ROOT", "/root/workspaces/thermal-system/thermal-control-lab"
  16. ))
  17. def main() -> int:
  18. lab = LAB_ROOT / "thermal_control_lab" / "fixed_point" / "pi.py"
  19. if not lab.is_file():
  20. raise RuntimeError(f"thermal-control-lab reference model is missing: {lab}")
  21. with tempfile.TemporaryDirectory(prefix="prod2u-6400-pi-differential-") as directory:
  22. build_dir = Path(directory)
  23. os.environ["HYPOTHESIS_STORAGE_DIRECTORY"] = str(build_dir / "hypothesis")
  24. os.environ["THERMAL_CONTROL_LAB_ROOT"] = str(LAB_ROOT)
  25. runner = get_runner("icarus")
  26. runner.build(
  27. sources=[
  28. ROOT / "src/common/ef2_bram_dp.v",
  29. ROOT / "src/control/thermal_output_banks.v",
  30. ROOT / "src/control/manual_set_all_bank.v",
  31. ROOT / "src/control/thermal_control_core.v",
  32. TEST_DIR / "thermal_control_core_cocotb_top.v",
  33. ],
  34. hdl_toplevel="thermal_control_core_cocotb_top",
  35. build_dir=build_dir,
  36. includes=[ROOT],
  37. build_args=["-g2012"],
  38. always=True,
  39. )
  40. result = Path(runner.test(
  41. hdl_toplevel="thermal_control_core_cocotb_top",
  42. test_module="test_6400_pi_differential",
  43. test_dir=TEST_DIR,
  44. build_dir=build_dir,
  45. results_xml=str(build_dir / "results.xml"),
  46. ))
  47. root = ET.parse(result).getroot()
  48. cases = root.findall(".//testcase")
  49. failures = root.findall(".//failure") + root.findall(".//error")
  50. skipped = root.findall(".//skipped")
  51. if not cases or failures or skipped:
  52. raise RuntimeError(
  53. f"PI differential incomplete: cases={len(cases)} failures={len(failures)} "
  54. f"skipped={len(skipped)} results={result}"
  55. )
  56. print("PASS: L7 bit-exact Python/RTL PI differential")
  57. return 0
  58. if __name__ == "__main__":
  59. raise SystemExit(main())