| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/usr/bin/env python3
- """Run the RX/core fast-JOG cocotb RED tests."""
- from __future__ import annotations
- import os
- from pathlib import Path
- import xml.etree.ElementTree as ET
- ROOT = Path(__file__).resolve().parents[2]
- TEST_DIR = Path(__file__).resolve().parent
- TEMP_ROOT = Path(os.environ.get("TEMP", ROOT / "tmp"))
- BUILD_DIR = TEMP_ROOT / "cocotb" / "prod2u_p4_fast_jog_top"
- RESULTS_XML = BUILD_DIR / "results.xml"
- def rtl_sources() -> list[Path]:
- return sorted(path for path in (ROOT / "src" / "rtl").glob("*.v") if path.is_file())
- def results_xml_has_failures(results: Path) -> bool:
- root = ET.parse(results).getroot()
- return bool(
- root.findall(".//failure")
- or root.findall(".//error")
- or sum(int(node.attrib.get("failures", "0")) for node in root.findall(".//testsuite"))
- or sum(int(node.attrib.get("errors", "0")) for node in root.findall(".//testsuite"))
- or int(root.attrib.get("failures", "0"))
- or int(root.attrib.get("errors", "0"))
- )
- def main() -> int:
- from cocotb_tools.runner import get_runner
- runner = get_runner("icarus")
- runner.build(
- sources=[*rtl_sources(), TEST_DIR / "prod2u_p4_fast_jog_top.v"],
- hdl_toplevel="prod2u_p4_fast_jog_top",
- build_dir=BUILD_DIR,
- always=True,
- verbose=False,
- )
- results = Path(
- runner.test(
- hdl_toplevel="prod2u_p4_fast_jog_top",
- test_module="test_prod2u_p4_fast_jog_top",
- build_dir=BUILD_DIR,
- test_dir=TEST_DIR,
- results_xml=str(RESULTS_XML),
- )
- )
- return 1 if not results.is_file() or results_xml_has_failures(results) else 0
- if __name__ == "__main__":
- raise SystemExit(main())
|