# SPDX-License-Identifier: MIT """Replay the closed-box Mesen2 probe recordings (``scripts/cx4_probe.py``). Each recording under ``tests/mesen_probes/-/`` (gitignored: ``probe.sfc`` is the homebrew cartridge, ``host.txt.gz`` and ``cx4.trace.gz`` Mesen2's output) is replayed twice: on the defaults, where the expected divergences are the C entries the probe was built to show, and on every OBSERVED switch position, where nothing may differ except the entries that have no switch (C2, C3). Mesen2 is a detector, not the judge: these tests pin what the observations were, so a change to the core or a new run is noticed. Absent recordings skip. """ from __future__ import annotations from pathlib import Path import pytest from hg51b_python import HG51B from hg51b_python.replay import replay PROBES = Path(__file__).parent / "mesen_probes" class Observed(HG51B): SHIFT_LIMIT = "mesen2-observed" STACK_MODEL = "ring-observed" FAR_SELECT = "either-observed" BUS_DELAY_EXTRA = 1 INTERNAL_ACCESS_COST = 1 CLEAR_IS_NOP = True LD_P_SOURCE = "operand-observed" STATUS_MIRROR = "all-observed" IRQ_DISABLE_SETS_FLAG = True # probe -> (divergences on the defaults, divergences left with the observed positions) EXPECTED = { "shift-0": ({"C1": 8}, {}), "shift-1": ({}, {}), "shift-2": ({"C1": 4}, {}), "truncate-0": ({"C2": 42}, {"C2": 42}), "truncate-1": ({"C2": 22}, {"C2": 22}), "stack-0": ({"C4": 1}, {}), "far-0": ({"C5/C17": 1}, {}), "ldp-0": ({"C11": 9}, {}), "clear-0": ({"C10": 3}, {}), "bus-0": ({}, {}), "dma-rom-ram-0": ({}, {}), "dma-rom-rom-0": ({}, {}), "dma-ram-ram-0": ({"start": 1}, {"start": 1}), # C3: Mesen2 locks, the core does not "dma-ram-rom-0": ({"start": 1}, {"start": 1}), "dma-none-ram-0": ({"start": 1}, {"start": 1}), "dma-cost-w0-0": ({}, {}), "dma-cost-w7-0": ({}, {}), "mirror-0": ({}, {}), "preload-0": ({}, {}), "preload-cold-0": ({}, {}), } @pytest.mark.parametrize("name", sorted(EXPECTED)) def test_probe_replay(name: str) -> None: directory = PROBES / name if not (directory / "host.txt.gz").exists(): pytest.skip(f"no recording: run scripts/cx4_probe.py ({directory})") rom = (directory / "probe.sfc").read_bytes() default, observed = EXPECTED[name] assert dict(replay(rom, directory).entries()) == default report = replay(rom, directory, core=Observed) assert dict(report.entries()) == observed assert not report.read_mismatches # C18's flag is the only S-CPU-visible difference