"""The test-ROM judges: the board must keep passing every ROM it passes today. The pass lists (``tests/_pass.txt``) and the mGBA suite's scores (``tests/mgba_scores.txt``) are written by ``scripts/run_test_roms.py --write``; each ROM here reruns through the same functions. They need the fetched references and a BIOS; judge runs use the retail BIOS (user decision 1), and a run with the free BIOS is skipped rather than compared, because the BIOS changes timing results (C3). """ from __future__ import annotations import sys from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "scripts")) from run_test_roms import run_one # noqa: E402 from gba_python import bios as bios_module # noqa: E402 TESTS = Path(__file__).parent def _lines(name: str) -> list[str]: path = TESTS / name return [line for line in path.read_text().splitlines() if line] if path.exists() else [] def _retail() -> bool: try: return bios_module.find(allow_free=False).is_retail except FileNotFoundError: return False pytestmark = [ pytest.mark.slow, pytest.mark.skipif(not (ROOT / "reference" / "src").exists(), reason="run fetch_references"), pytest.mark.skipif(not _retail(), reason="judge runs need the retail BIOS (decision 1)"), ] ROMS = [ (suite, key) for suite in ( "jsmolka", "alyosha", "hwtest", "hades", "ags", "aging", "armwrestler", "fuzzarm", "krom", "retaddr", "keyirq", "backuplib", ) for key in _lines(f"{suite}_pass.txt") ] HANDOFF_ROM = "reference/src/gba-tests/arm/arm.gba" SCORES = [line.split("\t") for line in _lines("mgba_scores.txt")] FRAMES = [ f"{rom}@{frames}" for rom, frames, _ in (row.split("\t") for row in _lines("frames_pass.txt")) ] @pytest.mark.parametrize(("suite", "key"), ROMS, ids=[f"{s}:{k.split('/')[-1]}" for s, k in ROMS]) def test_rom_passes(suite, key): if ( key.startswith("nointro:") or suite == "backuplib" ) and not bios_module.nointro_dir().exists(): pytest.skip("the cartridge is not in the local No-Intro set") if suite == "keyirq" and not (ROOT / key.split("#")[0]).exists(): pytest.skip("run scripts/build_test_roms.py") result = run_one((suite, key), None, None) assert result["passed"], result["detail"] @pytest.mark.parametrize(("group", "score"), SCORES, ids=[g for g, _ in SCORES]) def test_mgba_suite_group(group, score): floor = int(score.split("/")[0]) result = run_one(("mgba", group), None, None) assert result["passes"] is not None and result["passes"] >= floor, result["fails"][:10] @pytest.mark.parametrize("key", FRAMES, ids=[k.split("/")[-1] for k in FRAMES]) def test_frame_matches(key): if key.startswith("nointro:") and not bios_module.nointro_dir().exists(): pytest.skip("the game is not in the local No-Intro set") result = run_one(("frames", key), None, None) assert result["passed"], result["detail"] def test_skip_bios_leaves_what_the_bios_leaves(): result = run_one(("handoff", HANDOFF_ROM), None, None) assert result["passed"], result["detail"]