#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """ay-die-model's smoke test: synthetic pin events only, no ROM. python3 -I tests/smoke.py Checks the version line and the usage and missing-input exit codes; then, if build.sh has built the testbench and vvp is found, plays a tone on channel A, reads a register back, and checks the manifest, the record counts, the byte read and that channel A's code moves. Exit 0 when every part that could run passed. """ from __future__ import annotations import json import os import shutil import struct 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) def main() -> int: done = run("--version") check(done.returncode == 0 and done.stdout.startswith("ay-die-model 0.1.0 (ay-3-8910_reverse_engineered cf8d14d)"), "--version names the tool and the pin") check(run().returncode == 2, "no arguments: exit 2") with tempfile.TemporaryDirectory(prefix="ay-die-model-smoke-") as scratch: work = Path(scratch) check(run("--input", str(work / "absent.jsonl"), "--cycles", "10", "--out", str(work / "o")).returncode == 3, "a missing event file: exit 3") bad = work / "bad.jsonl" bad.write_text('{"t": 0, "kind": 9}\n') check(run("--input", str(bad), "--cycles", "10", "--out", str(work / "o")).returncode == 2, "a malformed event: exit 2") suite = os.environ.get("OSS_CAD_SUITE") vvp = (shutil.which("vvp", path=f"{suite}/bin") if suite else None) or shutil.which("vvp") if not (HERE / "build" / "ay_ref").exists() or vvp is None: print("skip the run: build.sh has not been run, or vvp is not found") return 1 if failures else 0 # tone period 0x010 and full volume on channel A, tone A only; then read R0 back writes = [(0, 0x10), (1, 0x00), (7, 0x3E), (8, 0x0F)] rows = [{"t": 16 * (i + 1), "kind": 0, "a": r, "b": v} for i, (r, v) in enumerate(writes)] rows.append({"t": 16 * (len(writes) + 1), "kind": 1, "a": 0}) events = work / "tone.jsonl" events.write_text("".join(json.dumps(r) + "\n" for r in rows)) cycles = 3000 out = work / "run" done = run("--input", str(events), "--cycles", str(cycles), "--out", str(out)) check(done.returncode == 0, "the run completes") if done.returncode != 0: print(done.stderr) return 1 manifest = json.loads((out / "manifest.json").read_text()) check(manifest["evidence"] == "OBSERVED" and manifest["outputs"][0]["records"] == cycles, "manifest: OBSERVED, one record per clock") reads = (out / "reads.bin").read_bytes() check(len(reads) == 4 and struct.unpack(" 1, "channel A's code moves (the tone)") return 1 if failures else 0 if __name__ == "__main__": raise SystemExit(main())