#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only """atari800's smoke test: no cartridge or BIOS needed. python3 -I "$EMU_TOOLS_GPL2/tools/atari800/tests/smoke.py" Checks build.py's version line and its usage-error exit status (2); then, if the library is built, that build-info.json names the pin and that the library exports the public entry points the driver declares (loaded with ctypes, nothing called). Under a second. Runs of the driver need a cartridge and the player's 5200 BIOS (MAME_ROMPATH), so they are the consumer's. """ from __future__ import annotations import ctypes import json import subprocess import sys from pathlib import Path HERE = Path(__file__).resolve().parents[1] sys.path.insert(0, str(HERE)) import build # noqa: E402 failures: list[str] = [] def check(ok: bool, what: str) -> None: print(("ok " if ok else "FAIL ") + what) if not ok: failures.append(what) def main() -> int: script = [sys.executable, "-I", str(HERE / "build.py")] done = subprocess.run([*script, "--version"], capture_output=True, text=True) check(done.returncode == 0 and done.stdout.startswith("atari800-build 0.1.0 (Atari800 98cc2dc)"), "--version names the tool and the pin") # fmt: skip done = subprocess.run([*script, "--bogus"], capture_output=True, text=True) check(done.returncode == 2, "an unknown argument: exit 2") if not build.LIBRARY.exists(): print("skip: not built (build.py)") else: info = json.loads((build.BUILD / "build-info.json").read_text()) check(info["upstream"]["commit"] == build.PIN, "built from the pin") lib = ctypes.CDLL(str(build.LIBRARY)) names = ("libatari800_init", "libatari800_next_frame", "libatari800_get_screen_ptr", "libatari800_get_current_state", "libatari800_exit") # fmt: skip check(all(hasattr(lib, name) for name in names), "the driver's entry points are exported") print(f"{len(failures)} failed" if failures else "smoke passed") return 1 if failures else 0 if __name__ == "__main__": raise SystemExit(main())