"""pytest wrapper: build lfsr.sv as a 32-bit LFSR and run the cocotb test in cocotb_lfsr.py.""" from __future__ import annotations import sys import tempfile from pathlib import Path from cocotb_tools.check_results import get_results from cocotb_tools.runner import get_runner HERE = Path(__file__).resolve().parent def test_lfsr32() -> None: if str(HERE) not in sys.path: sys.path.insert(0, str(HERE)) with tempfile.TemporaryDirectory() as tmp: build = Path(tmp) runner = get_runner("icarus") runner.build(sources=[HERE / "lfsr.sv"], hdl_toplevel="lfsr", build_dir=build, parameters={"W": 32, "MASK": "32'h80200003", "SEED": "32'hACE1ACE1"}, timescale=("1ns", "1ps")) xml = runner.test(test_module="cocotb_lfsr", hdl_toplevel="lfsr", build_dir=build, test_dir=build, results_xml=str(build / "results.xml")) n_tests, n_failed = get_results(Path(xml)) assert n_tests == 1 and n_failed == 0