run_prod2u_p4_fast_jog_top.py 1.7 KB

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