run_prod2u_door_temp_uart_e2e.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. """Run the current project's real-UART cocotb scenario."""
  3. from __future__ import annotations
  4. import os
  5. from pathlib import Path
  6. import sys
  7. import xml.etree.ElementTree as ET
  8. ROOT = Path(__file__).resolve().parents[2]
  9. TEST_DIR = Path(__file__).resolve().parent
  10. sys.path.insert(0, str(ROOT))
  11. TEMP_ROOT = Path(os.environ.get("TEMP", ROOT / "tmp"))
  12. BUILD_DIR = TEMP_ROOT / "cocotb" / "prod2u_door_temp_uart_e2e"
  13. RESULTS_XML = BUILD_DIR / "results.xml"
  14. def rtl_sources() -> list[Path]:
  15. from tools.prod2u_p4_normal_v3_build import PRODUCTION_RTL_SOURCES
  16. return [ROOT / relative for relative in PRODUCTION_RTL_SOURCES]
  17. def results_xml_has_failures(results: Path) -> bool:
  18. root = ET.parse(results).getroot()
  19. return bool(
  20. root.findall(".//failure")
  21. or root.findall(".//error")
  22. or sum(int(node.attrib.get("failures", "0")) for node in root.findall(".//testsuite"))
  23. or sum(int(node.attrib.get("errors", "0")) for node in root.findall(".//testsuite"))
  24. or int(root.attrib.get("failures", "0"))
  25. or int(root.attrib.get("errors", "0"))
  26. )
  27. def main() -> int:
  28. from cocotb_tools.runner import get_runner
  29. runner = get_runner("icarus")
  30. runner.build(
  31. sources=[*rtl_sources(), TEST_DIR / "prod2u_door_temp_uart_top.v"],
  32. hdl_toplevel="prod2u_door_temp_uart_top",
  33. build_dir=BUILD_DIR,
  34. build_args=["-I", str(ROOT)],
  35. always=True,
  36. verbose=False,
  37. )
  38. results = Path(
  39. runner.test(
  40. hdl_toplevel="prod2u_door_temp_uart_top",
  41. test_module="test_prod2u_door_temp_uart_e2e",
  42. build_dir=BUILD_DIR,
  43. test_dir=TEST_DIR,
  44. results_xml=str(RESULTS_XML),
  45. )
  46. )
  47. return 1 if not results.is_file() or results_xml_has_failures(results) else 0
  48. if __name__ == "__main__":
  49. raise SystemExit(main())