# SPDX-License-Identifier: MIT """Rung 4: AcidSAP's ten POKEY tests (Avery Lee, MIT; Acid800 1.2) on the core. Each test runs in the test-only machine of ``tests/acidsap.py`` (6502-python, RAM, the POKEY core, WSYNC, VCOUNT and refresh DMA) and decides pass or fail by its own convention: the N flag when it reaches ``_sap_testEnd``. Every test runs on a machine with a 2-cycle and a 3-cycle IRQ delay (AHRM 5.7; the tests accept both). Needs ``python -I scripts/fetch_references.py`` (the built AcidSAP files) and the dev extra ``acid`` (6502-python). """ from __future__ import annotations import ast import os from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[1] REFERENCE = Path(os.environ.get("POKEY_REFERENCE") or ROOT / "reference") # seeded_faults.py sets it SAP = REFERENCE / "acid800" / "out" / "Release" / "AcidSAP" / "standalone" #: Tests that need the serial shift registers, which decision 2 leaves unbuilt. RUNG7 = { "twotone": "needs the output shift register (decision 2): spaces never reach two-tone", } TESTS = [ "addrmirror", "asyncrecv", "default", "inittiming", "irqtiming", "noise", "seroc", "timergranularity", "timerirq", "twotone", ] # fmt: skip def cases(): for name in TESTS: for lag in (0, 1): marks = [pytest.mark.xfail(strict=True, reason=RUNG7[name])] if name in RUNG7 else [] yield pytest.param(name, lag, marks=marks, id=f"{name}-{lag + 2}cycle") @pytest.mark.parametrize("name,lag", list(cases())) def test_acidsap(name, lag): pytest.importorskip("sixfiveohtwo", reason="the dev extra 'acid' (6502-python) is not installed") sap = SAP / f"pokey_{name}.sap" if not sap.is_file(): pytest.skip("AcidSAP not fetched (python -I scripts/fetch_references.py)") from acidsap import Machine machine = Machine(sap, lag=lag) verdict, text = machine.run(max_cycles=2_000_000) assert verdict is not None, f"did not finish in 2,000,000 cycles: {text!r}" assert verdict, text def test_src_never_imports_the_harness(): # decision 6: the harness and 6502-python stay in tests/ for path in (ROOT / "src").rglob("*.py"): tree = ast.parse(path.read_text(encoding="utf-8")) for node in ast.walk(tree): names = [] if isinstance(node, ast.Import): names = [alias.name for alias in node.names] elif isinstance(node, ast.ImportFrom) and node.module: names = [node.module] for name in names: assert name.split(".")[0] not in ("acidsap", "sixfiveohtwo", "tests"), path