diff options
Diffstat (limited to 'gui/test/restart.py')
| -rw-r--r-- | gui/test/restart.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/gui/test/restart.py b/gui/test/restart.py new file mode 100644 index 0000000..166d8e3 --- /dev/null +++ b/gui/test/restart.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +"""Restart live targets and keep native window/backing sizes independent of font zoom.""" +import argparse +from pathlib import Path +import re +import struct +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[2] +p = argparse.ArgumentParser(description=__doc__) +p.add_argument('--gui', type=Path, default=ROOT / 'gui/zig-out/bin/ztrace-gui') +p.add_argument('--native', action='store_true', help='Exercise an actual SDL window and its resize feedback') +a = p.parse_args() +a.gui = a.gui.resolve() +with tempfile.TemporaryDirectory(prefix='ztrace-restart-') as directory: + out = Path(directory) + script = out / 'check.script' + commands = '''type :launch /bin/sleep 1 +key return +await stops 1 +console goto memory 0x1234 +console set origin 1234 +key z +console continue +await status exited +# Restart after exit through the toolbar, then while running through the shortcut. +click 710 54 +await launches 2 +await status stopped +expect stops 1 +expect moment 0 +expect nav[2].place.follow true +expect lens_count 0 +expect origin 0 +key c +await status running +hold left_shift +key r +release left_shift +await launches 3 +await status stopped +expect stops 1 +# A stopped target can restart too; the command and button share this path. +type :restart +key return +await launches 4 +await status stopped +expect stops 1 +''' + images = [] + for zoom in (100, 90, 60, 200, 100): + shot = out / f'zoom-{len(images)}.png' + images.append(shot) + commands += f'console set zoom {zoom}\nframes 3\nscreenshot {shot}\n' + if zoom == 60: + # Button coordinates are physical pixels even after font scaling. + commands += 'click 425 35\nawait launches 5\nawait status stopped\nexpect zoom 60\n' + if zoom == 200: + # Tiny overlays reveal the new lens's header and keep its close control reachable. + commands += 'key z\nexpect lens_count 1\nframes 30\nclick 250 406\nexpect lens_count 2\nexpect lenses[1].cycle true\nframes 30\nclick 700 406\nexpect lens_count 1\nkey escape\n' + commands += '''hold left_ctrl +key minus +release left_ctrl +expect zoom 90 +frames 60 +hold left_ctrl +key equals +release left_ctrl +expect zoom 100 +hold left_ctrl +key 0 +release left_ctrl +expect zoom 100 +expect-no-log CommandFailed +expect-no-log NoLaunchCommand +''' + script.write_text(commands) + args = [str(a.gui), '--fresh', '--size', '800x700', '--state', str(out / 'session.state'), '--script', str(script)] + if not a.native: + args.append('--headless') + run = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + stdout, stderr = run.communicate(timeout=90) + assert run.returncode == 0, (stdout, stderr) + dimensions = [struct.unpack('>II', shot.read_bytes()[16:24]) for shot in images] + assert all(size == dimensions[0] for size in dimensions), ('zoom resized the window/backing', dimensions) + assert dimensions[0] == (800, 700), dimensions + recordings = list(Path('/tmp').glob(f'ztrace-gui-{run.pid}-*.ztrace')) + assert len(recordings) == 5, recordings + pids = [] + for recording in recordings: + dump = subprocess.check_output([str(a.gui.parent / 'ztrace'), 'dump', str(recording)], text=True) + pid = int(re.search(r'tid=(\d+)', dump)[1]) + pids.append(pid) + assert not Path(f'/proc/{pid}').exists(), ('old target survived restart/close', pid) + recording.unlink() + assert len(set(pids)) == 5, pids + print(('Native' if a.native else 'Headless') + ': restart after exit/running/stopped, fresh recordings, scaled button hits, stable 800x700 backing at 60–200% passed') |
