# SPDX-License-Identifier: MIT """Rung 4: MAME 0.285 replays of real games (emulator tier, a detector; replay.py). Runs every ``scripts/mame_dsp_trace.py`` run directory under ``tests/mame_traces/`` (gitignored; remake them with the commands in docs/validation.md "Rung 4 results") and under the directories in ``UPD7725_TRACES`` (``os.pathsep``-separated). The MAME-switched core must match every traced instruction and host read; every difference of the default core must be named by a C-entry (or U10, an RT on an empty stack). """ from __future__ import annotations import os from pathlib import Path import pytest from conftest import HAVE_ROMPATH from upd7725_python.replay import replay_run HERE = Path(__file__).parent / "mame_traces" ROOTS = [HERE, *(Path(p) for p in os.environ.get("UPD7725_TRACES", "").split(os.pathsep) if p)] RUNS = sorted(run.parent for root in ROOTS if root.is_dir() for run in root.glob("*/dsp.log.gz")) NAMED = {"C1", "C4", "C5", "C11", "C16", "U10"} @pytest.mark.slow @pytest.mark.parametrize("run", RUNS, ids=[run.name for run in RUNS]) def test_replay(run): if not (run / "summary.json").exists(): pytest.skip("no summary.json") if not HAVE_ROMPATH: pytest.skip("BYOR program images absent (set MAME_ROMPATH)") try: result = replay_run(run) except FileNotFoundError as missing: pytest.skip(f"BYOR: {missing}") assert result.finding is None, result.finding assert set(result.divergences) <= NAMED assert result.reads_checked > 0 def test_traces_present_or_skip(): if not RUNS: pytest.skip("no MAME traces: run scripts/mame_dsp_trace.py (docs/validation.md)")