mirror of
https://git.triforceproject.com/triforce/source
synced 2026-12-02 05:48:50 -04:00
Triforce v0.9.1
The 16 GB update: idle memory unlocked and handed back to Windows while playing, empty pages under freed locks returned, and a page-file check at launch that warns before a too-small page file can crash the game.
This commit is contained in:
97
tests/test_pagefile_rule.py
Normal file
97
tests/test_pagefile_rule.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""The page-file check at the start (host/pagefile_rule.h, mkw_glue.c hos_pagefile_check; no game).
|
||||
|
||||
(Triforce, 12-01.) 16 GB players crash when RAM + page file run out; the game takes ~24 GB of commit at its peak. This compiles
|
||||
pagefile_rule.h alone and runs its parse of the registry's PagingFiles value and its verdict on made-up PCs: no page file,
|
||||
fixed ones small and large, a managed one with a full or a roomy drive; and reads mkw_glue.c for the check's call, its
|
||||
once-per-settings note and its switch.
|
||||
|
||||
python -I -B tests/test_pagefile_rule.py [--cc clang]
|
||||
"""
|
||||
import argparse
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
HOST = ROOT / "host"
|
||||
RUN_ALL_ARGS = ["--cc", "clang"]
|
||||
|
||||
PROG = r'''
|
||||
#include <stdio.h>
|
||||
#include "pagefile_rule.h"
|
||||
static void parse(const char *name, const char *m, size_t n) {
|
||||
PfSettings s = pf_parse(m, n);
|
||||
printf("parse %s %d %c %.2f\n", name, s.kind, s.drive ? s.drive : '-', s.fixed_max_gb);
|
||||
}
|
||||
static void decide(const char *name, int kind, double fixed, double ram, double limit, double in_use, double disk) {
|
||||
PfSettings s = {kind, 'C', fixed};
|
||||
PfVerdict v = pf_decide(&s, ram, limit, in_use, disk);
|
||||
printf("decide %s %d %.1f %.1f\n", name, v.verdict, v.reach_gb, v.need_gb);
|
||||
}
|
||||
int main(void) {
|
||||
parse("auto", "?:\\pagefile.sys\0\0", 17);
|
||||
parse("managed_d", "D:\\pagefile.sys 0 0\0\0", 21);
|
||||
parse("fixed", "C:\\pagefile.sys 4096 8192\0\0", 27);
|
||||
parse("fixed2", "C:\\pagefile.sys 2048 2048\0E:\\pagefile.sys 1024 4096\0\0", 54);
|
||||
parse("none", "\0\0", 2);
|
||||
parse("empty", "", 0);
|
||||
parse("mixed", "C:\\pagefile.sys 1024 2048\0D:\\pagefile.sys 0 0\0\0", 47);
|
||||
decide("16_none", 0, 0, 16, 16, 6, 100);
|
||||
decide("16_fixed8", 2, 8, 16, 24, 6, 100);
|
||||
decide("16_fixed24", 2, 24, 16, 20, 6, 100);
|
||||
decide("16_managed_roomy", 1, 0, 16, 19, 6, 200);
|
||||
decide("16_managed_full", 1, 0, 16, 19, 6, 3);
|
||||
decide("32_none", 0, 0, 32, 32, 8, 100);
|
||||
decide("32_managed", 1, 0, 32, 57, 28, 300);
|
||||
decide("16_busy_managed", 1, 0, 16, 30, 14, 10);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def check(ok, why):
|
||||
if not ok:
|
||||
raise SystemExit("FAIL: " + why)
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--cc", default="clang")
|
||||
a = ap.parse_args()
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
src = Path(d) / "t.c"
|
||||
exe = Path(d) / "t.exe"
|
||||
src.write_text(PROG)
|
||||
subprocess.run([a.cc, "-std=c11", "-Wall", "-Werror", "-I", str(HOST), str(src), "-o", str(exe)], check=True)
|
||||
out = subprocess.run([str(exe)], capture_output=True, text=True, check=True).stdout.split("\n")
|
||||
r = {}
|
||||
for line in out:
|
||||
f = line.split()
|
||||
if f:
|
||||
r[(f[0], f[1])] = f[2:]
|
||||
check(r[("parse", "auto")][:2] == ["1", "C"], "?:\\pagefile.sys is managed, on C: %s" % r[("parse", "auto")])
|
||||
check(r[("parse", "managed_d")][:2] == ["1", "D"], "a drive with 0 0 is managed there")
|
||||
check(r[("parse", "fixed")] == ["2", "C", "8.00"], "fixed 4096..8192 MB: 8 GB at most %s" % r[("parse", "fixed")])
|
||||
check(r[("parse", "fixed2")] == ["2", "C", "6.00"], "two fixed files: their maximums summed %s" % r[("parse", "fixed2")])
|
||||
check(r[("parse", "none")][0] == "0" and r[("parse", "empty")][0] == "0", "no strings: no page file")
|
||||
check(r[("parse", "mixed")][:2] == ["1", "D"], "one managed file of several: managed")
|
||||
v = {k[1]: (int(x[0]), float(x[1]), float(x[2])) for k, x in r.items() if k[0] == "decide"}
|
||||
check(v["16_none"][0] == 1, "16 GB with no page file: short (none)")
|
||||
check(v["16_fixed8"][0] == 2 and v["16_fixed8"][1] == 24.0, "16 GB + 8 GB fixed: reach 24, short (fixed)")
|
||||
check(v["16_fixed24"][0] == 0 and v["16_fixed24"][1] == 40.0, "16 GB + 24 GB fixed: reach 40, enough")
|
||||
check(v["16_managed_roomy"][0] == 0 and v["16_managed_roomy"][1] == 64.0, "managed, roomy drive: up to 3x RAM")
|
||||
check(v["16_managed_full"][0] == 3, "managed on a full drive: short (disk)")
|
||||
check(v["32_none"][0] == 1, "32 GB with no page file: short (needs 36)")
|
||||
check(v["32_managed"][0] == 0 and v["32_managed"][2] == 54.0, "this PC: enough; need = in use 28 + 26")
|
||||
check(v["16_busy_managed"][0] == 3 and v["16_busy_managed"][2] == 40.0, "busy 16 GB PC, 10 GB free disk: short (disk)")
|
||||
glue = (HOST / "mkw_glue.c").read_text(encoding="utf-8")
|
||||
check("pf_decide(" in glue and "pf_parse(" in glue, "mkw_glue.c runs the rule")
|
||||
check("triforce_pagefile_warned.txt" in glue, "the warning once per page-file settings")
|
||||
check("HOS_PAGEFILE_CHECK" in glue, "the switch")
|
||||
mem = (HOST / "hos_mem.c").read_text(encoding="utf-8")
|
||||
check("hos_pagefile_check()" in mem, "called at the start (hos_mem_init)")
|
||||
print("ok: page-file rule")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user