# SPDX-License-Identifier: GPL-3.0-or-later """Run the compatibility smoke test, including nested tokenization, on both guest CPUs.""" 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) parser.add_argument("core", type=Path) parser.add_argument("rom", type=Path) args = parser.parse_args() runtime, core, rom = [p.resolve(strict=True) for p in (args.runtime, args.core, args.rom)] tests = Path(__file__).resolve().parent runner = tests.parents[3] / "tests/toolchain/run-compiled.cpp" env = dict(os.environ, VCC_CMOC_COMPAT="1") with tempfile.TemporaryDirectory(prefix="vcc-compat-") as tmp: def run(*args): subprocess.run(args, cwd=tmp, env=env, check=True) run("xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0", runner, core, "-o", "run") for opt in ("-O0", "-O2"): cc = [runtime / "bin/cmoc", "--coco", opt, "-Werror"] caller = [*cc, "--org=2800", "-o", "TEST.BIN", tests / "compat-check.c"] print(f"{opt} caller with staged library", flush=True) run(*caller, "-lvcccompat") run("./run", rom, "TEST.BIN", "COMPAT PASS") if opt == "-O0": # The staged archive always contains the optimized implementation. print("Checking the unoptimized compatibility routines as well", flush=True) units = ["tokenize", "ctype", "format"] for unit in units: run(*cc, "-c", "-o", unit + ".o", tests.parent / (unit + ".c")) run(*caller, *(unit + ".o" for unit in units)) run("./run", rom, "TEST.BIN", "COMPAT PASS") if __name__ == "__main__": main()