| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/usr/bin/env python3
- """Run control and identification full-top cocotb integration profiles."""
- 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-control/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_profile(name: str, enable_stimulus: int, 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)],
- parameters={"ENABLE_STIMULUS": enable_stimulus},
- 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)
- supported = {"control", "identification", "host_protocol"}
- 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 ("control", "identification", "host_protocol")
- stimulus = {"control": 0, "identification": 1, "host_protocol": 0}
- with tempfile.TemporaryDirectory(prefix="prod2u-6400-cocotb-") as directory:
- root = Path(directory)
- for profile in profiles:
- run_profile(profile, stimulus[profile], root / profile)
- print(f"PASS: 6400 cocotb integration profiles: {', '.join(profiles)}")
- return 0
- if __name__ == "__main__":
- raise SystemExit(main())
|