|
- #!/usr/bin/env python3
- """regress.py - build each test program with and without the optimizer, run both in VICE and
- compare the final screens (ignoring the blinking cursor cell). Needs PIL (pip install pillow).
-
- python tools/regress.py [tests/sem.c tests/uge.c ...]
- """
- import os, sys, subprocess
- from PIL import Image, ImageChops
- HERE = os.path.dirname(os.path.abspath(__file__))
- ROOT = os.path.normpath(os.path.join(HERE, '..'))
- tests = sys.argv[1:] or [os.path.join(ROOT, 'tests', t) for t in ('sem.c',)]
- ok = True
- for src in tests:
- name = os.path.splitext(os.path.basename(src))[0]
- shots = {}
- for mode in ('orig', 'opt'):
- d = os.path.join(ROOT, 'work', 'regress_%s_%s' % (name, mode))
- cmd = ['powershell', '-NoProfile', '-File', os.path.join(HERE, 'pcbuild.ps1'), '-Src', src, '-Name', name,
- '-Dir', d, '-Run', '\n', '-Settle', '60'] + (['-NoOpt'] if mode == 'orig' else [])
- r = subprocess.run(cmd, capture_output=True, text=True)
- size = [l for l in r.stdout.splitlines() if 'linked' in l]
- shots[mode] = (os.path.join(d, 'run.png'), size[-1] if size else 'LINK FAILED')
- a = Image.open(shots['orig'][0]).convert('RGB'); b = Image.open(shots['opt'][0]).convert('RGB')
- diff = ImageChops.difference(a, b).getbbox()
- # the blinking cursor is a single 8x8 cell
- same = diff is None or (diff[2] - diff[0] <= 8 and diff[3] - diff[1] <= 8)
- print('%-8s orig: %-24s opt: %-24s screens %s' % (name, shots['orig'][1], shots['opt'][1], 'IDENTICAL' if same else 'DIFFER %s' % (diff,)))
- ok &= same
- sys.exit(0 if ok else 1)
|