#!/usr/bin/env python3 """Run L7 bit-exact thermal-control-lab versus production RTL differential.""" from __future__ import annotations import os from pathlib import Path import tempfile import xml.etree.ElementTree as ET try: from cocotb_tools.runner import get_runner except ModuleNotFoundError: from cocotb.runner import get_runner ROOT = Path(__file__).resolve().parents[2] TEST_DIR = Path(__file__).resolve().parent LAB_ROOT = Path(os.environ.get( "THERMAL_CONTROL_LAB_ROOT", "/root/workspaces/thermal-system/thermal-control-lab" )) def main() -> int: lab = LAB_ROOT / "thermal_control_lab" / "fixed_point" / "pi.py" if not lab.is_file(): raise RuntimeError(f"thermal-control-lab reference model is missing: {lab}") with tempfile.TemporaryDirectory(prefix="prod2u-6400-pi-differential-") as directory: build_dir = Path(directory) os.environ["HYPOTHESIS_STORAGE_DIRECTORY"] = str(build_dir / "hypothesis") os.environ["THERMAL_CONTROL_LAB_ROOT"] = str(LAB_ROOT) runner = get_runner("icarus") runner.build( sources=[ ROOT / "src/common/ef2_bram_dp.v", ROOT / "src/control/thermal_output_banks.v", ROOT / "src/control/manual_set_all_bank.v", ROOT / "src/control/thermal_control_core.v", TEST_DIR / "thermal_control_core_cocotb_top.v", ], hdl_toplevel="thermal_control_core_cocotb_top", build_dir=build_dir, includes=[ROOT], build_args=["-g2012"], always=True, ) result = Path(runner.test( hdl_toplevel="thermal_control_core_cocotb_top", test_module="test_6400_pi_differential", test_dir=TEST_DIR, build_dir=build_dir, results_xml=str(build_dir / "results.xml"), )) root = ET.parse(result).getroot() cases = root.findall(".//testcase") failures = root.findall(".//failure") + root.findall(".//error") skipped = root.findall(".//skipped") if not cases or failures or skipped: raise RuntimeError( f"PI differential incomplete: cases={len(cases)} failures={len(failures)} " f"skipped={len(skipped)} results={result}" ) print("PASS: L7 bit-exact Python/RTL PI differential") return 0 if __name__ == "__main__": raise SystemExit(main())