run_6400_bmc_fuzz.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. """Run fail-closed byte-level BMC parser replay/fuzz coverage."""
  3. from __future__ import annotations
  4. import os
  5. from pathlib import Path
  6. import tempfile
  7. import xml.etree.ElementTree as ET
  8. try:
  9. from cocotb_tools.runner import get_runner
  10. except ModuleNotFoundError:
  11. from cocotb.runner import get_runner
  12. ROOT = Path(__file__).resolve().parents[2]
  13. TEST_DIR = Path(__file__).resolve().parent
  14. def main() -> int:
  15. with tempfile.TemporaryDirectory(prefix="prod2u-6400-bmc-fuzz-") as directory:
  16. build_dir = Path(directory)
  17. os.environ["HYPOTHESIS_STORAGE_DIRECTORY"] = str(build_dir / "hypothesis")
  18. runner = get_runner("icarus")
  19. runner.build(
  20. sources=[
  21. ROOT / "src/acquisition/bmc_ascii_snapshot.v",
  22. TEST_DIR / "bmc_ascii_snapshot_cocotb_top.v",
  23. ],
  24. hdl_toplevel="bmc_ascii_snapshot_cocotb_top",
  25. build_dir=build_dir,
  26. build_args=["-g2012"],
  27. always=True,
  28. )
  29. result = Path(runner.test(
  30. hdl_toplevel="bmc_ascii_snapshot_cocotb_top",
  31. test_module="test_6400_bmc_parser_fuzz",
  32. test_dir=TEST_DIR,
  33. build_dir=build_dir,
  34. results_xml=str(build_dir / "results.xml"),
  35. ))
  36. root = ET.parse(result).getroot()
  37. cases = root.findall(".//testcase")
  38. failures = root.findall(".//failure") + root.findall(".//error")
  39. skipped = root.findall(".//skipped")
  40. if not cases or failures or skipped:
  41. raise RuntimeError(
  42. f"BMC fuzz incomplete: cases={len(cases)} failures={len(failures)} "
  43. f"skipped={len(skipped)} results={result}"
  44. )
  45. print("PASS: 6400 BMC parser replay/fuzz")
  46. return 0
  47. if __name__ == "__main__":
  48. raise SystemExit(main())