run_6400_v1_integration.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  2. """Run focused single-product full-top cocotb test suites."""
  3. from __future__ import annotations
  4. import argparse
  5. import json
  6. import os
  7. from pathlib import Path
  8. import tempfile
  9. import xml.etree.ElementTree as ET
  10. try:
  11. from cocotb_tools.runner import get_runner
  12. except ModuleNotFoundError: # cocotb 1.9 compatibility in the pinned image
  13. from cocotb.runner import get_runner
  14. ROOT = Path(__file__).resolve().parents[2]
  15. TEST_DIR = Path(__file__).resolve().parent
  16. CLOSURE = ROOT / "products/6400-front-rear/source-closure.json"
  17. WRAPPER = TEST_DIR / "prod2u_6400_v1_cocotb_top.v"
  18. def rtl_sources() -> list[Path]:
  19. payload = json.loads(CLOSURE.read_text(encoding="utf-8"))
  20. return [ROOT / item for item in payload["sources"] if item.endswith(".v")]
  21. def run_suite(name: str, build_dir: Path) -> None:
  22. os.environ["HYPOTHESIS_STORAGE_DIRECTORY"] = str(build_dir / "hypothesis")
  23. runner = get_runner("icarus")
  24. runner.build(
  25. sources=[*rtl_sources(), WRAPPER],
  26. hdl_toplevel="prod2u_6400_v1_cocotb_top",
  27. build_dir=build_dir,
  28. build_args=["-g2012", "-I", str(ROOT)],
  29. always=True,
  30. )
  31. results_path = build_dir / "results.xml"
  32. result = Path(runner.test(
  33. hdl_toplevel="prod2u_6400_v1_cocotb_top",
  34. test_module=f"test_6400_v1_{name}_integration",
  35. test_dir=TEST_DIR,
  36. build_dir=build_dir,
  37. results_xml=str(results_path),
  38. ))
  39. root = ET.parse(result).getroot()
  40. cases = root.findall(".//testcase")
  41. failures = root.findall(".//failure") + root.findall(".//error")
  42. skipped = root.findall(".//skipped")
  43. if not cases or failures or skipped:
  44. raise RuntimeError(
  45. f"cocotb {name} profile incomplete: "
  46. f"cases={len(cases)} failures={len(failures)} skipped={len(skipped)} "
  47. f"results={result}"
  48. )
  49. def main(argv: list[str] | None = None) -> int:
  50. parser = argparse.ArgumentParser()
  51. parser.add_argument(
  52. "profiles",
  53. nargs="*",
  54. metavar="PROFILE",
  55. )
  56. args = parser.parse_args(argv)
  57. supported = {"control", "host_protocol", "pwm_boot"}
  58. invalid = [profile for profile in args.profiles if profile not in supported]
  59. if invalid:
  60. parser.error(f"unsupported profile: {invalid[0]}")
  61. profiles = args.profiles or ("host_protocol",)
  62. with tempfile.TemporaryDirectory(prefix="prod2u-6400-cocotb-") as directory:
  63. root = Path(directory)
  64. for profile in profiles:
  65. run_suite(profile, root / profile)
  66. print(f"PASS: 6400-front-rear cocotb suites: {', '.join(profiles)}")
  67. return 0
  68. if __name__ == "__main__":
  69. raise SystemExit(main())