#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only """ym2608-lle's smoke test: no ROM, synthetic inputs only. python3 -I tests/smoke.py Checks the version line and the usage and missing-input exit codes; then, if build.sh has built the harnesses, runs the probe's clock measurement and the YM2612 referee on a keyed tone, and checks the manifests, the record counts and that the tone is heard (the DAC pins are not constant). Exit 0 when every part that could run passed. """ from __future__ import annotations import json import subprocess import sys import tempfile from pathlib import Path HERE = Path(__file__).resolve().parents[1] RUN = [sys.executable, "-I", str(HERE / "run.py")] failures: list[str] = [] def check(ok: bool, what: str) -> None: print(("ok " if ok else "FAIL ") + what) if not ok: failures.append(what) def run(*args: str) -> subprocess.CompletedProcess: return subprocess.run([*RUN, *args], capture_output=True, text=True) # Channel 1 of part I: algorithm 7 (four carriers), both outputs, multiple 1, no attenuation, # the fastest attack, a middle pitch, then key on all four operators. Address then data, # 64 chip clocks apart (each write is held 16). REGISTERS = [(0xB0, 0x07), (0xB4, 0xC0), *[(r, 0x01) for r in (0x30, 0x34, 0x38, 0x3C)], *[(r, 0x00) for r in (0x40, 0x44, 0x48, 0x4C)], *[(r, 0x1F) for r in (0x50, 0x54, 0x58, 0x5C)], (0xA4, 0x22), (0xA0, 0x69), (0x28, 0xF0)] def tone(path: Path) -> Path: rows, t = [], 64 for address, data in REGISTERS: rows += [{"t": t, "port": 0, "data": address}, {"t": t + 64, "port": 1, "data": data}] t += 128 path.write_text("".join(json.dumps(r) + "\n" for r in rows)) return path def main() -> int: done = run("--version") check(done.returncode == 0 and done.stdout.startswith("ym2608-lle 0.1.0 (YM2608-LLE 7a2aca7)"), "--version names the tool and the pin") check(run().returncode == 2, "no arguments: exit 2") check(run("--machine", "ym2610", "--out", "x", "--measure", "nonsense").returncode == 2, "an unknown measurement: exit 2") with tempfile.TemporaryDirectory(prefix="ym2608-lle-smoke-") as scratch: work = Path(scratch) check(run("--machine", "ym2612", "--input", str(work / "absent.jsonl"), "--cycles", "10", "--out", str(work / "o")).returncode == 3, "a missing write script: exit 3") if not (HERE / "build" / "lle2610_probe").exists() or not (HERE / "build" / "lle2612_ref").exists(): print("skip the runs: build.sh has not been run") return 1 if failures else 0 out = work / "probe" done = run("--machine", "ym2610", "--measure", "clock", "--out", str(out)) manifest = json.loads((out / "manifest.json").read_text()) if done.returncode == 0 else {} check(done.returncode == 0 and manifest.get("evidence") == "OBSERVED" and manifest["upstream"]["patches"] == ["ym2610-build-fix.patch"] and (out / "probe.txt").stat().st_size > 0, "ym2610 probe, clock: manifest and text") out = work / "ym2612" cycles = 120_000 done = run("--machine", "ym2612", "--input", str(tone(work / "tone.jsonl")), "--cycles", str(cycles), "--out", str(out)) manifest = json.loads((out / "manifest.json").read_text()) if done.returncode == 0 else {} body = (out / "ym2612.bin").read_bytes() if done.returncode == 0 else b"" check(manifest.get("outputs", [{}])[0].get("records") == cycles and len(body) == 4 * cycles, "ym2612: one record per chip clock") tail = body[len(body) // 2 :] check(len({tail[i : i + 4] for i in range(0, len(tail), 4)}) > 8, "ym2612: the tone is heard") return 1 if failures else 0 if __name__ == "__main__": raise SystemExit(main())