Files
VCCPlusOSS/tests/toolchain/bank-demo/check.py
T

44 lines
2.1 KiB
Python

# SPDX-License-Identifier: GPL-3.0-or-later
"""Run the banked landscape lesson on both CoCo CPUs and capture the guest display."""
import argparse
import os
from pathlib import Path
import subprocess
import tempfile
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("runtime", type=Path, help="staged ToolchainBundle")
parser.add_argument("core", type=Path, help="libVCCCore.a")
parser.add_argument("roms", type=Path, help="CoCo 3 and Disk BASIC ROM directory")
parser.add_argument("--captures", type=Path, help="write ridge-earth.png and ridge-mars.png here")
args = parser.parse_args()
runtime, core, roms = [p.resolve(strict=True) for p in (args.runtime, args.core, args.roms)]
fixture = Path(__file__).resolve().parent
root = fixture.parents[2]
env = dict(os.environ, VCC_CMOC_COMPAT="0", PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"])
with tempfile.TemporaryDirectory(prefix="vcc-ridge-") as folder:
def run(*command):
subprocess.run(command, cwd=folder, env=env, check=True)
run("xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
"-I", root / "src", fixture / "run.cpp", core, "-o", "run")
for opt in ("-O0", "-O2"):
print("Checking", opt, flush=True)
run(runtime / "bin/cmoc", "--coco", "--org=2800", opt, "-Werror", "-o", "RIDGE.BIN",
root / "examples/cmoc/manual/ridge.c", "-lbank", "-lgime", "-lhirestxt")
(Path(folder) / "RIDGE.DSK").write_bytes(b"\xff" * (35 * 18 * 256))
run(runtime / "bin/writecocofile", "RIDGE.DSK", "RIDGE.BIN")
capture = args.captures and opt == "-O2"
run("./run", roms, "RIDGE.DSK", "RIDGE.BIN", *(["capture"] if capture else []))
if capture:
args.captures.mkdir(parents=True, exist_ok=True)
for planet in ("earth", "mars"):
png = args.captures.resolve() / f"ridge-{planet}.png"
run("sips", "-s", "format", "png", f"{planet}.ppm", "--out", png)
if __name__ == "__main__":
main()