tools/client/test_portable_rand.py (1498B)
1 """Compare actual Windows MSVCRT rand/srand with the portable guest CRT.""" 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-rand" 9 work.mkdir(parents=True, exist_ok=True) 10 11 # The reference resolves msvcrt.dll exports explicitly, never UCRT rand/srand. 12 reference = work / "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_rand.c", "-o", str(reference), 16 ], cwd=decompiled, check=True) 17 expected = subprocess.check_output([str(reference)], text=True, timeout=30) 18 print("Windows reference: " + expected.strip(), flush=True) 19 20 # Link only production guest CRT/memory/heap/state into the isolated Linux test. 21 linux_path = "/mnt/" + decompiled.drive[0].lower() + decompiled.as_posix()[2:] 22 linux_output = "/mnt/" + work.drive[0].lower() + work.as_posix()[2:] + "/translated" 23 wsl = ["wsl", "-d", "Ubuntu-26.04", "--cd", linux_path, "--exec"] 24 subprocess.run(wsl + [ 25 "gcc", "-O2", "-DRECOMP_PORTABLE", "-Iruntime", "-fno-strict-aliasing", 26 "tests/guest_rand.c", "runtime/guest_crt.c", "runtime/guest_memory.c", 27 "runtime/guest_heap.c", "runtime/recomp_state.c", "-pthread", "-lm", "-o", linux_output, 28 ], check=True) 29 actual = subprocess.check_output(wsl + [linux_output], text=True, timeout=30) 30 assert actual == expected, (expected, actual) 31 print("Windows MSVCRT == Linux x86-64: " + actual.strip())