#!/usr/bin/env python3 """Run fail-closed byte-level BMC parser replay/fuzz coverage.""" from __future__ import annotations import os from pathlib import Path import tempfile import xml.etree.ElementTree as ET try: from cocotb_tools.runner import get_runner except ModuleNotFoundError: from cocotb.runner import get_runner ROOT = Path(__file__).resolve().parents[2] TEST_DIR = Path(__file__).resolve().parent def main() -> int: with tempfile.TemporaryDirectory(prefix="prod2u-6400-bmc-fuzz-") as directory: build_dir = Path(directory) os.environ["HYPOTHESIS_STORAGE_DIRECTORY"] = str(build_dir / "hypothesis") runner = get_runner("icarus") runner.build( sources=[ ROOT / "src/common/ef2_bram_dp.v", ROOT / "src/acquisition/bmc_ascii_snapshot.v", TEST_DIR / "bmc_ascii_snapshot_cocotb_top.v", ], hdl_toplevel="bmc_ascii_snapshot_cocotb_top", build_dir=build_dir, build_args=["-g2012"], always=True, ) result = Path(runner.test( hdl_toplevel="bmc_ascii_snapshot_cocotb_top", test_module="test_6400_bmc_parser_fuzz", test_dir=TEST_DIR, build_dir=build_dir, results_xml=str(build_dir / "results.xml"), )) 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"BMC fuzz incomplete: cases={len(cases)} failures={len(failures)} " f"skipped={len(skipped)} results={result}" ) print("PASS: 6400 BMC parser replay/fuzz") return 0 if __name__ == "__main__": raise SystemExit(main())