"""pytest wrapper: build health_tests.sv with Icarus Verilog and run cocotb_health.py. Two builds: a binary source (H = 1, W = 1024) and a 4-bit source (H = 2, W = 512). Run: /Volumes/M2-Dev/conda/envs/toptech/bin/python -m pytest -q The simulator build goes into a temporary directory, never into this folder. """ from __future__ import annotations import os import sys import tempfile from pathlib import Path import pytest from cocotb_tools.check_results import get_results from cocotb_tools.runner import get_runner HERE = Path(__file__).resolve().parent if str(HERE) not in sys.path: sys.path.insert(0, str(HERE)) import sp80090b_health as H # noqa: E402 def run_health(sw: int, h: float, window: int) -> None: params = { "SW": sw, "RCT_C": H.rct_cutoff(h), "APT_W": window, "APT_C": H.apt_cutoff(h, window), "STARTUP": 1024, } env = {f"HT_{k}": str(v) for k, v in params.items()} env |= {"PYTHONDONTWRITEBYTECODE": "1", "PYTHONPATH": os.pathsep.join(sys.path)} with tempfile.TemporaryDirectory(prefix="cocotb_health_") as tmp: runner = get_runner("icarus") runner.build(sources=[HERE / "health_tests.sv"], hdl_toplevel="health_tests", parameters=params, build_dir=tmp, always=True) results = runner.test(hdl_toplevel="health_tests", test_module="cocotb_health", build_dir=tmp, test_dir=tmp, extra_env=env) n_tests, n_failed = get_results(Path(results)) assert n_tests > 0, "no cocotb tests ran" assert n_failed == 0, f"{n_failed} of {n_tests} cocotb tests failed" @pytest.mark.parametrize(("sw", "h", "window"), [(1, 1.0, 1024), (4, 2.0, 512)]) def test_health_tests(sw: int, h: float, window: int) -> None: run_health(sw, h, window)