| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #!/usr/bin/env python3
- """Run focused single-product full-top cocotb test suites."""
- from __future__ import annotations
- import argparse
- import json
- import os
- from pathlib import Path
- import tempfile
- import xml.etree.ElementTree as ET
- try:
- from cocotb_tools.runner import get_runner
- except ModuleNotFoundError: # cocotb 1.9 compatibility in the pinned image
- from cocotb.runner import get_runner
- ROOT = Path(__file__).resolve().parents[2]
- TEST_DIR = Path(__file__).resolve().parent
- CLOSURE = ROOT / "products/6400-front-rear/source-closure.json"
- WRAPPER = TEST_DIR / "prod2u_6400_v1_cocotb_top.v"
- def rtl_sources() -> list[Path]:
- payload = json.loads(CLOSURE.read_text(encoding="utf-8"))
- return [ROOT / item for item in payload["sources"] if item.endswith(".v")]
- def run_suite(name: str, build_dir: Path) -> None:
- os.environ["HYPOTHESIS_STORAGE_DIRECTORY"] = str(build_dir / "hypothesis")
- runner = get_runner("icarus")
- runner.build(
- sources=[*rtl_sources(), WRAPPER],
- hdl_toplevel="prod2u_6400_v1_cocotb_top",
- build_dir=build_dir,
- build_args=["-g2012", "-I", str(ROOT)],
- always=True,
- )
- results_path = build_dir / "results.xml"
- result = Path(runner.test(
- hdl_toplevel="prod2u_6400_v1_cocotb_top",
- test_module=f"test_6400_v1_{name}_integration",
- test_dir=TEST_DIR,
- build_dir=build_dir,
- results_xml=str(results_path),
- ))
- root = ET.parse(result).getroot()
- cases = root.findall(".//testcase")
- failures = root.findall(".//failure") + root.findall(".//error")
- skipped = root.findall(".//skipped")
- if not cases or failures or skipped:
- raise RuntimeError(
- f"cocotb {name} profile incomplete: "
- f"cases={len(cases)} failures={len(failures)} skipped={len(skipped)} "
- f"results={result}"
- )
- def main(argv: list[str] | None = None) -> int:
- parser = argparse.ArgumentParser()
- parser.add_argument(
- "profiles",
- nargs="*",
- metavar="PROFILE",
- )
- args = parser.parse_args(argv)
- # Only the active manual V1.1 fixture is present in this closure. The
- # former control/host_protocol module names were retired with the PID
- # protocol and must not be requested by the current runner.
- supported = {"pwm_boot"}
- invalid = [profile for profile in args.profiles if profile not in supported]
- if invalid:
- parser.error(f"unsupported profile: {invalid[0]}")
- profiles = args.profiles or ("pwm_boot",)
- with tempfile.TemporaryDirectory(prefix="prod2u-6400-cocotb-") as directory:
- root = Path(directory)
- for profile in profiles:
- run_suite(profile, root / profile)
- print(f"PASS: 6400-front-rear cocotb suites: {', '.join(profiles)}")
- return 0
- if __name__ == "__main__":
- raise SystemExit(main())
|