"""Rung 4: real games, replayed through the core against MAME 0.285's trace. Each directory under ``tests/mame_traces/`` that ``scripts/mame_trace.py GAME --io`` made (gitignored: never commit ROMs or traces) is one case: from reset to the end of the trace, the core's registers after every instruction are MAME's, and every instruction's length in master clocks is MAME's or differs from it exactly by MAME's own cycle rules (mame_replay.py, ``mame_extra_cycles``). Emulator-derived: a failure here is a lead for a higher tier, not a verdict (docs/validation.md). """ from pathlib import Path import pytest from mame_replay import replay TRACES = Path(__file__).resolve().parent / "mame_traces" CASES = sorted( d.name for d in TRACES.glob("*") if (d / "error.log").is_file() and (d / "cart.sfc").is_file() ) @pytest.mark.slow @pytest.mark.parametrize("game", CASES or ["(none)"]) def test_replay_agrees_with_mame(game: str) -> None: if not CASES: pytest.skip("no MAME traces: python -I scripts/mame_trace.py GAME --io --seconds 10") folder = TRACES / game report = replay((folder / "cart.sfc").read_bytes(), folder / "error.log") print(f"{game}\n{report.summary()}") assert report.instructions > 0 assert not report.divergences, report.summary() assert report.unexplained == 0, report.summary()