run_uart_bit_e2e.py 2.3 KB

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