run_uart_bit_e2e.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python3
  2. """Run the repository UART-bit cocotb e2e (no hthd) with clean OSS CAD libexec shims."""
  3. from __future__ import annotations
  4. import os
  5. import subprocess
  6. import sys
  7. from pathlib import Path
  8. HERE = Path(__file__).resolve().parent
  9. HOST = HERE.parents[1]
  10. RTL_REPO = Path(os.environ.get("HTH_CPLD_ROOT", HOST.parent / "cpld-temperature-control"))
  11. RUNNER = RTL_REPO / "tests" / "cocotb" / "run_prod2u_door_temp_uart_e2e.py"
  12. OSS_CAD_POISON = ("PYTHONEXECUTABLE", "PYTHONHOME", "PYTHONNOUSERSITE")
  13. def _cad_root() -> Path | None:
  14. for root in (Path("/data/prod2u/oss-cad-suite/latest"), Path("/data/prod2u/oss-cad-suite")):
  15. if (root / "libexec" / "iverilog").is_file() and (root / "libexec" / "vvp").is_file():
  16. return root
  17. return None
  18. def _write_clean_cad_shims(shim: Path, cad: Path) -> None:
  19. shim.mkdir(parents=True, exist_ok=True)
  20. ld = cad / "lib" / "ld-linux-x86-64.so.2"
  21. lib = cad / "lib"
  22. iver = cad / "libexec" / "iverilog"
  23. vvp = cad / "libexec" / "vvp"
  24. vvp_shim = shim / "vvp"
  25. vvp_shim.write_text(
  26. f"#!/bin/bash\nexec {ld} --inhibit-cache --inhibit-rpath '' --library-path {lib} {vvp} \"$@\"\n",
  27. encoding="utf-8",
  28. )
  29. vvp_shim.chmod(0o755)
  30. iver_shim = shim / "iverilog"
  31. iver_shim.write_text(
  32. f"#!/bin/bash\nexec {ld} --inhibit-cache --inhibit-rpath '' --library-path {lib} {iver} -p VVP_EXECUTABLE={vvp_shim} \"$@\"\n",
  33. encoding="utf-8",
  34. )
  35. iver_shim.chmod(0o755)
  36. def main() -> int:
  37. skip = "--skip-missing" in sys.argv
  38. if not RUNNER.is_file():
  39. print("UART-bit e2e: NOT RUN (repo runner missing)")
  40. return 2 if skip else 1
  41. cad = _cad_root()
  42. py = Path(os.environ.get("PROD2U_P4_COCOTB_PYTHON", "/opt/hth-cocotb/bin/python"))
  43. if cad is None or not py.is_file():
  44. print("UART-bit e2e: NOT RUN")
  45. print("cad:", cad, "python:", py)
  46. return 2 if skip else 1
  47. shim = Path("/tmp/hth-uart-e2e-shim")
  48. _write_clean_cad_shims(shim, cad)
  49. env = {k: v for k, v in os.environ.items() if k not in OSS_CAD_POISON}
  50. env["PATH"] = os.pathsep.join([str(py.parent), str(shim), "/usr/bin", "/bin"])
  51. env["PROD2U_P4_COCOTB_PYTHON"] = str(py)
  52. r = subprocess.run([str(py), "-B", str(RUNNER)], cwd=str(RTL_REPO), env=env)
  53. if r.returncode == 0:
  54. print("RTL_UART_BIT_E2E_PASS")
  55. return r.returncode
  56. if __name__ == "__main__":
  57. raise SystemExit(main())