"""pytest wrapper: build sobel_pipeline.sv with Icarus Verilog and run cocotb_sobel.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 SOURCES = ["rgb_to_gray.sv", "line_buffer.sv", "window3x3.sv", "sobel.sv", "sobel_pipeline.sv"] def test_sobel_pipeline() -> None: if str(HERE) not in sys.path: sys.path.insert(0, str(HERE)) # the runner passes sys.path on as PYTHONPATH with tempfile.TemporaryDirectory() as tmp: build = Path(tmp) runner = get_runner("icarus") runner.build(sources=[HERE / s for s in SOURCES], hdl_toplevel="sobel_pipeline", parameters={"W": 32, "H": 20, "THRESH": 400}, build_dir=build, timescale=("1ns", "1ps")) xml = runner.test(test_module="cocotb_sobel", hdl_toplevel="sobel_pipeline", 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, f"{n_failed} of {n_tests} cocotb tests failed"