summaryrefslogtreecommitdiff
path: root/gui/test/adaptive.py
diff options
context:
space:
mode:
Diffstat (limited to 'gui/test/adaptive.py')
-rw-r--r--gui/test/adaptive.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/gui/test/adaptive.py b/gui/test/adaptive.py
new file mode 100644
index 0000000..89ce49a
--- /dev/null
+++ b/gui/test/adaptive.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+"""Real GUI checks for geometry, large mappings, pointer hit targets and repeated live stops."""
+import argparse
+from pathlib import Path
+import re
+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')
+a = p.parse_args()
+a.gui = a.gui.resolve()
+with tempfile.TemporaryDirectory(prefix='ztrace-adaptive-') as directory:
+ out = Path(directory)
+ target = out / 'segments'
+ subprocess.run(['cc', '-g', '-O0', '-no-pie', str(ROOT / 'gui/targets/segments.c'), '-o', str(target)], check=True)
+ symbols = {name: int(address, 16) for address, name in re.findall(r'^([0-9a-f]+) \w (\w+)$', subprocess.check_output(['nm', '-n', str(target)], text=True), re.M)}
+ for size in ('2240x1260', '1440x900', '800x700'):
+ for zoom in (60, 100, 200):
+ script = out / 'check.script'
+ script.write_text(f'''console launch {target}
+await stops 1
+console break checkpoint
+console continue
+await execution 1
+console goto memory {hex(symbols['counter'])}
+frames 40
+key c
+await execution 2
+frames 40
+expect nav[2].place.follow false
+# An inspection reply doesn't resume execution or unpin a pane.
+expect execution 2
+# Font controls, actual key routing and bounds.
+console set zoom {zoom}
+hold left_ctrl
+key equals
+release left_ctrl
+expect zoom {min(200, zoom + 10)}
+hold left_ctrl
+key minus
+release left_ctrl
+expect zoom {max(60, min(200, zoom + 10) - 10)}
+console set zoom {zoom}
+frames 10
+# All four GiB are navigable. A single row still changes the address at the end.
+key p
+type ztrace-test-segment
+key return
+frames 20
+key g
+key g
+expect nav[2].place.row 0
+hold left_shift
+key g
+release left_shift
+print nav[2].place.row
+key k
+print nav[2].place.row
+# The same selector routes into code and preserves its jump history.
+console set focus code
+key p
+type ztrace-test-segment
+key return
+expect nav[0].place.follow false
+hold left_ctrl
+key o
+release left_ctrl
+expect nav[0].place.follow true
+key t
+expect graph true
+key l
+expect horizontal[0] 48
+key t
+key d
+expect dim 100
+# Historical inspection does not fetch memory or execute the target.
+key left_bracket
+expect following false
+console goto memory 0xffffffffffff0000
+frames 20
+expect execution 2
+key p
+type no-such-segment
+key escape
+expect segments false
+# Lens closure and a rendered header hit remain accurate at every zoom.
+console set pc {symbols['head']}
+key z
+expect lens_count 1
+frames 30
+screenshot {out / 'lens.png'}
+key escape
+expect lens_count 0
+hold left_ctrl
+key 0
+release left_ctrl
+expect zoom 100
+expect-no-log CommandFailed
+expect-no-log InvalidCount
+''')
+ run = subprocess.Popen([str(a.gui), '--headless', '--fresh', '--state', str(out / f'{size}-{zoom}.state'), '--size', size, '--script', str(script)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+ stdout, stderr = run.communicate(timeout=90)
+ assert run.returncode == 0, (size, zoom, stdout, stderr)
+ rows = [float(v) for v in re.findall(r'nav\[2\].place.row = ([\d.]+)', stderr)]
+ assert len(rows) == 2 and rows[0] > 268000000 and rows[0] - rows[1] == 1, rows
+ recordings = list(Path('/tmp').glob(f'ztrace-gui-{run.pid}-*.ztrace'))
+ assert len(recordings) == 1
+ dump = subprocess.check_output([str(a.gui.parent / 'ztrace'), 'dump', str(recordings[0])], text=True)
+ writes = [(int(addr, 16), int(length, 16)) for addr, length in re.findall(r'mem_write\s+.*?a=([0-9a-f]+) ([0-9a-f]+)', dump)]
+ assert sum(addr <= symbols['counter'] < addr + length for addr, length in writes) >= 2, 'same-PC live stop did not refresh pinned bytes'
+ recordings[0].unlink()
+ print(f'{size} at {zoom}%: live refresh, mapping ends, history, graph, lenses and zoom passed')