run_6400_v1_integration.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python3
  2. """Run control and identification full-top cocotb integration profiles."""
  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-control/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_profile(name: str, enable_stimulus: int, 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. parameters={"ENABLE_STIMULUS": enable_stimulus},
  30. always=True,
  31. )
  32. results_path = build_dir / "results.xml"
  33. result = Path(runner.test(
  34. hdl_toplevel="prod2u_6400_v1_cocotb_top",
  35. test_module=f"test_6400_v1_{name}_integration",
  36. test_dir=TEST_DIR,
  37. build_dir=build_dir,
  38. results_xml=str(results_path),
  39. ))
  40. root = ET.parse(result).getroot()
  41. cases = root.findall(".//testcase")
  42. failures = root.findall(".//failure") + root.findall(".//error")
  43. skipped = root.findall(".//skipped")
  44. if not cases or failures or skipped:
  45. raise RuntimeError(
  46. f"cocotb {name} profile incomplete: "
  47. f"cases={len(cases)} failures={len(failures)} skipped={len(skipped)} "
  48. f"results={result}"
  49. )
  50. def main(argv: list[str] | None = None) -> int:
  51. parser = argparse.ArgumentParser()
  52. parser.add_argument(
  53. "profiles",
  54. nargs="*",
  55. metavar="PROFILE",
  56. )
  57. args = parser.parse_args(argv)
  58. supported = {"control", "identification", "host_protocol"}
  59. invalid = [profile for profile in args.profiles if profile not in supported]
  60. if invalid:
  61. parser.error(f"unsupported profile: {invalid[0]}")
  62. profiles = args.profiles or ("control", "identification", "host_protocol")
  63. stimulus = {"control": 0, "identification": 1, "host_protocol": 0}
  64. with tempfile.TemporaryDirectory(prefix="prod2u-6400-cocotb-") as directory:
  65. root = Path(directory)
  66. for profile in profiles:
  67. run_profile(profile, stimulus[profile], root / profile)
  68. print(f"PASS: 6400 cocotb integration profiles: {', '.join(profiles)}")
  69. return 0
  70. if __name__ == "__main__":
  71. raise SystemExit(main())