KAZIK/tools/tests/check_underworld.py

29 lines
2.2 KiB
Python

"""Run real MASM underworld handlers and capture their production framebuffer."""
from pathlib import Path
import subprocess
import hashlib
from PIL import Image
from check_artifacts import toolchain
ROOT=Path(__file__).resolve().parents[2]
OUT=ROOT/'build/underworld'
def main():
OUT.mkdir(parents=True,exist_ok=True)
(OUT/'crash.bin').unlink(missing_ok=True)
before={p:hashlib.sha256(p.read_bytes()).digest() for p in (ROOT/'runtime').rglob('*') if p.is_file()}
source=(ROOT/'poker.asm').read_text(encoding='cp1251')
source=source.replace('main PROC','include tools\\tests\\underworld_probe.inc\ninclude tools\\tests\\heist_hq_probe.inc\nmain PROC\n call RunUnderworldProbe\n test eax,eax\n jnz uw_all_probe_done\n call RunHQProbe\nuw_all_probe_done:\n invoke ExitProcess,eax',1)
(OUT/'probe.asm').write_bytes(source.encode('cp1251'))
ml,link=toolchain()
sdk=Path('C:/Program Files (x86)/Windows Kits/10/Lib')
lib=next(p/'um/x86' for p in sorted(sdk.iterdir(),reverse=True) if (p/'um/x86/kernel32.lib').exists())
def run(args,timeout=120):return subprocess.run([str(x) for x in args],cwd=ROOT,check=True,timeout=timeout)
run([ml,'/c','/coff','/Cp','/nologo','/I.','/Fobuild/underworld/probe.obj','build/underworld/probe.asm'])
run([link,'/nologo','/SUBSYSTEM:CONSOLE','/MAP:build/underworld/probe.map','/LIBPATH:'+str(lib),'/OUT:build/underworld/probe.exe','build/underworld/probe.obj','kernel32.lib','user32.lib','gdi32.lib','winmm.lib','ws2_32.lib'])
run([OUT/'probe.exe'],180)
assert all(p.exists() and hashlib.sha256(p.read_bytes()).digest()==h for p,h in before.items()),'Profile mutation'
for p in OUT.glob('*.bmp'):Image.open(p).save(p.with_suffix('.png'))
print('PASS: loans/QTE, deferred debt/security, once-per-hand peek, public-card blackjack analysis; 100 paid races; profile reload; separate club interactions. HQ: van departure, stealth/assault, wall-blocked shots, silent/loud weapons, guard detection/damage, terminal/door, intel, safe without payout, extraction/return exactly once, abort/death preserve bank and restore map/position. 19 native framebuffer snapshots; real profiles unchanged.')
if __name__=='__main__':main()