run_6400_bmc_fuzz.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/common/ef2_bram_dp.v",
  22. ROOT / "src/acquisition/bmc_ascii_snapshot.v",
  23. TEST_DIR / "bmc_ascii_snapshot_cocotb_top.v",
  24. ],
  25. hdl_toplevel="bmc_ascii_snapshot_cocotb_top",
  26. build_dir=build_dir,
  27. build_args=["-g2012"],
  28. always=True,
  29. )
  30. result = Path(runner.test(
  31. hdl_toplevel="bmc_ascii_snapshot_cocotb_top",
  32. test_module="test_6400_bmc_parser_fuzz",
  33. test_dir=TEST_DIR,
  34. build_dir=build_dir,
  35. results_xml=str(build_dir / "results.xml"),
  36. ))
  37. root = ET.parse(result).getroot()
  38. cases = root.findall(".//testcase")
  39. failures = root.findall(".//failure") + root.findall(".//error")
  40. skipped = root.findall(".//skipped")
  41. if not cases or failures or skipped:
  42. raise RuntimeError(
  43. f"BMC fuzz incomplete: cases={len(cases)} failures={len(failures)} "
  44. f"skipped={len(skipped)} results={result}"
  45. )
  46. print("PASS: 6400 BMC parser replay/fuzz")
  47. return 0
  48. if __name__ == "__main__":
  49. raise SystemExit(main())