# SPDX-License-Identifier: MIT """Milestone 1's acceptance: gilyon's cputest and krom's CPU and BANK ROMs. Tier: self-checking test ROMs (TEST ROM). gilyon (MIT) states its ROMs test the 65C816 instruction set as the console runs it; krom's tests are "only tested with a real SNES using a SD2SNES" (krom README). Fetch them with scripts/fetch_references.py; the tests skip when they are absent. """ from __future__ import annotations import re import pytest from roms import ROOT, gilyon, krom GILYON = ROOT / "gilyon" / "cputest" KROM_CPU = sorted((ROOT / "krom" / "CPUTest" / "CPU").glob("*/*.sfc")) KROM_BANK = sorted((ROOT / "krom" / "BANK").glob("*/*.sfc")) pytestmark = pytest.mark.slow def _expected_passes(rom) -> int: """How many checks the ROM's source prints PASS for.""" source = rom.with_suffix(".asm").read_text(encoding="latin-1") return len(re.findall(r"PrintText\(Pass", source)) or 1 @pytest.mark.parametrize( "name, count", [("cputest-full.sfc", 0x649), ("cputest-basic.sfc", 0x452)] ) def test_gilyon_cputest(name: str, count: int) -> None: rom = GILYON / name if not rom.exists(): pytest.skip("gilyon's ROMs are not fetched") verdict, number, _ = gilyon(rom) assert verdict == "Success" # The test number is printed in hex digits of the decimal count # ("0649" for 649 tests; MAME 0.285 and Mesen2 print the same). assert number == count @pytest.mark.parametrize("rom", KROM_CPU + KROM_BANK, ids=lambda p: p.stem) def test_krom(rom) -> None: passes, fails, _ = krom(rom, quiet=60) assert fails == 0 assert passes == _expected_passes(rom)