aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/test_portable_startup.py (1932B)


      1 """Check guest command-line serialization against the actual Windows MSVCRT parser."""
      2 import pathlib
      3 import subprocess
      4 
      5 
      6 root = pathlib.Path(__file__).resolve().parents[2]
      7 decompiled = root / "client"
      8 work = root / "local/client/portable-startup"
      9 work.mkdir(parents=True, exist_ok=True)
     10 
     11 # A space in the executable path also exercises CRT's special argv[0] parsing.
     12 reference = work / "startup reference.exe"
     13 subprocess.run([
     14     str(root / "toolchains/llvm-mingw-20261006-ucrt-x86_64/bin/i686-w64-mingw32-clang.exe"),
     15     "-O2", "tests/guest_startup.c", "-o", str(reference),
     16 ], cwd=decompiled, check=True)
     17 linux_path = "/mnt/" + decompiled.drive[0].lower() + decompiled.as_posix()[2:]
     18 linux_output = "/mnt/" + work.drive[0].lower() + work.as_posix()[2:] + "/translated"
     19 wsl = ["wsl", "-d", "Ubuntu-26.04", "--cd", linux_path, "--exec"]
     20 subprocess.run(wsl + [
     21     "gcc", "-O2", "-DRECOMP_PORTABLE", "-Iruntime", "-fno-strict-aliasing",
     22     "tests/guest_startup.c", "runtime/guest_crt.c", "runtime/guest_memory.c",
     23     "runtime/guest_heap.c", "runtime/recomp_state.c", "-lm", "-o", linux_output,
     24 ], check=True)
     25 
     26 # Feed the exact command line built by production Linux code to Windows.
     27 cases = [[], ["localtest", "localtest", "73", "2130706433", "7511", "0", "0"],
     28          ["", "with space", "with\ttab", 'say"hi', "a b\\", "c\\d"], ["*", "?"]]
     29 for slashes in range(9):
     30     cases.append(["\\" * slashes, "space " + "\\" * slashes,
     31                   "x" + "\\" * slashes + '"y', '"' + "\\" * slashes + '"'])
     32 for arguments in cases:
     33     actual = subprocess.check_output(wsl + [linux_output, str(reference), *arguments], text=True, timeout=30)
     34     command, actual = actual.split("\n", 1)
     35     expected = subprocess.check_output(command, text=True, timeout=30)
     36     assert actual == expected, (arguments, expected, actual)
     37 print(f"CRT startup: {len(cases)} command lines match Windows MSVCRT, including quotes/backslashes and FP mode")