#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Export pokey-python's own stimulus generators, run on the reference's interpreter. python scripts/export_streams.py kit REFERENCE OUT_DIR python scripts/export_streams.py streams REFERENCE OUT_DIR [--per 10] ``kit``: every case of the reference's conformance kit (``scripts/conformance.py``'s ``cases()``), one file per case, in the kit's own command language (``W reg value``, ``R reg``, ``N n``, ``K v``, ``P v``, ``S v``), consecutive identical commands written once with ``*COUNT``; plus a copy of ``validation/conformance.txt``. tests/conformance.rs replays them; scripts/rung3.sh checks that the committed copies in tests/conformance/ are what this writes from the reference at the pin. ``streams``: the reference's validation stream generators (``scripts/streams.py``: rung 2, 3, 4 and 6, with the seeds and options its docs/status.md records), ``--per`` streams of each kind, as lockstep scripts (scripts/lockstep_gen.py's language) for both cores. Played on the shipped ``POKEY`` only, never the closed box or the referee's ``BoxAligned``. """ from __future__ import annotations import argparse import sys from pathlib import Path def rle(lines: list[str]) -> list[str]: out: list[str] = [] last, count = None, 0 for line in lines: if line == last: count += 1 continue if last is not None: out.append(last if count == 1 else f"{last} *{count}") last, count = line, 1 if last is not None: out.append(last if count == 1 else f"{last} *{count}") return out def kit_lines(commands: list[tuple]) -> list[str]: return rle([" ".join(str(x) for x in command) for command in commands]) def lockstep_lines(commands: list[tuple]) -> list[str]: """streams.py's commands as a lockstep script: an access, then its cycle's tick (B0.1).""" lines = ["new C012294 0"] for command in commands: op = command[0] if op == "W": lines += [f"w {command[1]} {command[2]}", "t 1"] elif op == "R": lines += [f"r {command[1]}", "t 1"] elif op == "N": lines.append(f"t {command[1]}") elif op == "P": lines.append(f"P {command[1]}") elif op == "K": # streams.apply_pins: the testbench's pin levels v; asserted = ~v & 3, for every code lines.append(f"K {~command[1] & 3}") elif op == "S": lines.append(f"S {1 if command[1] else 0}") else: raise ValueError(op) return lines + ["state"] def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("what", choices=["kit", "streams"]) parser.add_argument("reference", type=Path) parser.add_argument("out_dir", type=Path) parser.add_argument("--per", type=int, default=10) args = parser.parse_args() ref = args.reference.resolve() sys.path.insert(0, str(ref / "src")) sys.path.insert(0, str(ref / "scripts")) args.out_dir.mkdir(parents=True, exist_ok=True) if args.what == "kit": import conformance for name, commands in conformance.cases().items(): text = "# SPDX-License-Identifier: MIT\n" + "\n".join(kit_lines(commands)) + "\n" (args.out_dir / f"{name}.txt").write_text(text, encoding="ascii") kit = (ref / "validation" / "conformance.txt").read_text(encoding="ascii") (args.out_dir / "conformance.txt").write_text(kit, encoding="ascii") print(f"{len(conformance.cases())} kit cases in {args.out_dir}") return 0 import streams n = args.per kinds = { # (generator, first seed, cycles), as the reference's docs/status.md runs them "rung2": (lambda s: streams.rung2_stream(s, 50000, False, False), 1), "rung2-init": (lambda s: streams.rung2_stream(s, 50000, False, True), 1001), "rung2-audctl": (lambda s: streams.rung2_stream(s, 50000, True, False), 2001), "rung3": (lambda s: streams.rung3_stream(s, 50000), 1), "rung3-stimers": (lambda s: streams.rung3_stream(s, 50000, stimers=True), 3001), "rung4": (lambda s: streams.rung4_stream(s, 50000), 1), "rung6": (lambda s: streams.rung6_stream(s, 20000), 1), } for kind, (make, first) in kinds.items(): for seed in range(first, first + n): lines = lockstep_lines(make(seed)) (args.out_dir / f"{kind}-{seed}.txt").write_text("\n".join(lines) + "\n") print(f"{n * len(kinds)} streams in {args.out_dir}") return 0 if __name__ == "__main__": sys.exit(main())