#!/usr/bin/env python3 """Run the repository UART-bit cocotb e2e (no hthd) with clean OSS CAD libexec shims.""" from __future__ import annotations import os import subprocess import sys from pathlib import Path HERE = Path(__file__).resolve().parent HOST = HERE.parents[1] RTL_REPO = Path(os.environ.get("HTH_CPLD_ROOT", HOST.parent / "cpld-temperature-control")) RUNNER = RTL_REPO / "tests" / "cocotb" / "run_prod2u_door_temp_uart_e2e.py" OSS_CAD_POISON = ("PYTHONEXECUTABLE", "PYTHONHOME", "PYTHONNOUSERSITE") def _cad_root() -> Path | None: for root in (Path("/data/prod2u/oss-cad-suite/latest"), Path("/data/prod2u/oss-cad-suite")): if (root / "libexec" / "iverilog").is_file() and (root / "libexec" / "vvp").is_file(): return root return None def _write_clean_cad_shims(shim: Path, cad: Path) -> None: shim.mkdir(parents=True, exist_ok=True) ld = cad / "lib" / "ld-linux-x86-64.so.2" lib = cad / "lib" iver = cad / "libexec" / "iverilog" vvp = cad / "libexec" / "vvp" vvp_shim = shim / "vvp" vvp_shim.write_text( f"#!/bin/bash\nexec {ld} --inhibit-cache --inhibit-rpath '' --library-path {lib} {vvp} \"$@\"\n", encoding="utf-8", ) vvp_shim.chmod(0o755) iver_shim = shim / "iverilog" iver_shim.write_text( f"#!/bin/bash\nexec {ld} --inhibit-cache --inhibit-rpath '' --library-path {lib} {iver} -p VVP_EXECUTABLE={vvp_shim} \"$@\"\n", encoding="utf-8", ) iver_shim.chmod(0o755) def main() -> int: skip = "--skip-missing" in sys.argv if not RUNNER.is_file(): print("UART-bit e2e: NOT RUN (repo runner missing)") return 2 if skip else 1 cad = _cad_root() py = Path(os.environ.get("PROD2U_P4_COCOTB_PYTHON", "/opt/hth-cocotb/bin/python")) if cad is None or not py.is_file(): print("UART-bit e2e: NOT RUN") print("cad:", cad, "python:", py) return 2 if skip else 1 shim = Path("/tmp/hth-uart-e2e-shim") _write_clean_cad_shims(shim, cad) env = {k: v for k, v in os.environ.items() if k not in OSS_CAD_POISON} env["PATH"] = os.pathsep.join([str(py.parent), str(shim), "/usr/bin", "/bin"]) env["PROD2U_P4_COCOTB_PYTHON"] = str(py) r = subprocess.run([str(py), "-B", str(RUNNER)], cwd=str(RTL_REPO), env=env) if r.returncode == 0: print("RTL_UART_BIT_E2E_PASS") return r.returncode if __name__ == "__main__": raise SystemExit(main())