Files
Triforce-Source/tests/test_mesh_args_cleanup.py
ruckus7382sfgsgdf 4fa4f9188b Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
2026-11-25 10:21:32 -06:00

67 lines
2.9 KiB
Python

"""Defensive failure injection against actual mesh argument initialization; no Vulkan/game required."""
import argparse
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
ROOT = Path(__file__).resolve().parents[1]
CASES = ("allocation_failure", "allocation_failure_outputs", "null_mapping",
"zero_address", "success_reuse", "take_ranges")
def actual_initializer(source):
start = source.index("constexpr uint32_t kMeshArgs =")
first = source.index("{", source.index("uint32_t mesh_args_take(uint32_t n)", start))
depth, at = 1, first + 1
while depth:
if source[at] == "{":
depth += 1
elif source[at] == "}":
depth -= 1
at += 1
return source[start:at]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--cxx", default=os.environ.get("CXX", "clang++"), help="GCC/Clang C++ compiler")
parser.add_argument("--source", type=Path, default=ROOT / "gpu/vk/vk_draw.cpp",
help="Public vk_draw.cpp override for an original-source negative control")
parser.add_argument("--case", action="append", choices=CASES)
args = parser.parse_args()
cxx = shutil.which(args.cxx)
if not cxx:
raise SystemExit("C++ compiler not found: " + args.cxx)
actual = actual_initializer(args.source.read_text(encoding="utf-8"))
flags = subprocess.CREATE_NO_WINDOW | subprocess.BELOW_NORMAL_PRIORITY_CLASS if os.name == "nt" else 0
env = dict(os.environ)
env["PATH"] = str(Path(cxx).parent) + os.pathsep + env.get("PATH", "")
with tempfile.TemporaryDirectory(prefix="hookshot-mesh-args-") as folder:
tmp = Path(folder)
(tmp / "mesh_args_actual.inc").write_text(actual + "\n", encoding="utf-8")
exe = tmp / ("mesh_args.exe" if os.name == "nt" else "mesh_args")
command = [cxx, "-std=c++20", "-O0", "-Wall", "-Wextra", "-Werror", "-I" + str(tmp),
str(ROOT / "tests/mesh_args_cleanup_test.cpp"), "-o", str(exe)]
result = subprocess.run(command, cwd=tmp, env=env, capture_output=True, text=True, timeout=60,
creationflags=flags)
if result.returncode:
print(result.stdout + result.stderr)
return result.returncode
failed = 0
for case in args.case or CASES:
# The production function caches its result forever: each case gets a fresh process.
result = subprocess.run([str(exe), case], cwd=tmp, env=env, capture_output=True, text=True,
timeout=10, creationflags=flags)
print((result.stdout + result.stderr).strip())
failed += result.returncode != 0
print("mesh argument initialization: %d cases, %d failed" % (len(args.case or CASES), failed))
return int(failed != 0)
if __name__ == "__main__":
raise SystemExit(main())