1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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')
|