summaryrefslogtreecommitdiff
path: root/gui/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-13 09:28:38 -0300
committerGabriel Schneider <[email protected]>2026-11-13 09:28:38 -0300
commit5c0230ea5a77f85de77ad4354788cd6c27aa1ef6 (patch)
treee01a903bdee092965b86e118dfaab85c3bd60004 /gui/test
parent5a40dca5adb6e9e650f55f3ec6f254a13bf50493 (diff)
downloadcomputeranim-5c0230ea5a77f85de77ad4354788cd6c27aa1ef6.tar.gz
computeranim-5c0230ea5a77f85de77ad4354788cd6c27aa1ef6.zip
debugger: follow natural V8 deoptimization with adaptive live views
Diffstat (limited to 'gui/test')
-rw-r--r--gui/test/adaptive.py114
-rw-r--r--gui/test/basic.script28
-rw-r--r--gui/test/inspection.py132
3 files changed, 185 insertions, 89 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')
diff --git a/gui/test/basic.script b/gui/test/basic.script
index cf23a47..be2034f 100644
--- a/gui/test/basic.script
+++ b/gui/test/basic.script
@@ -46,16 +46,16 @@ expect nav[2].place.row 0
hold left_ctrl
key d
release left_ctrl
-expect nav[2].place.row 7.5
+expect nav[2].place.row 7
key f
expect nav[2].place.follow true
# Rendered code addresses route to disassembly, including source-aligned rows.
-console mouse-button 3 650 122
+console mouse-button 3 650 204
expect focus code
expect nav[0].place.follow false
-console mouse-button 4 650 122
+console mouse-button 4 650 204
expect nav[0].place.follow true
-console mouse-button 5 650 122
+console mouse-button 5 650 204
expect nav[0].place.follow false
key f
# Stack storage addresses route to telescope.
@@ -77,11 +77,27 @@ frames 6
screenshot {LENS}
frames 30
screenshot {LENS_SETTLED}
-expect-different-screenshot {LENS} {LENS_SETTLED} 1090 580 1120 230
+expect-different-screenshot {LENS} {LENS_SETTLED} 1090 130 1120 230
+# Header addresses use the same pointer hits as rows. Keep ancestors, mark cycles,
+# replace descendants from a parent, and close one branch at a time.
+click 1230 161
+expect lens_count 2
+expect lenses[1].cycle true
+frames 30
+click 1230 365
+expect lens_count 3
+frames 30
+click 1230 161
+expect lens_count 2
+frames 30
+click 2180 350
+expect lens_count 1
+click 2180 146
+expect lens_count 0
key escape
expect lens false
# Opening from a call-frame address keeps its origin visible.
-click 1700 726
+click 1700 750
expect lens true
frames 30
screenshot {FRAME_LENS}
diff --git a/gui/test/inspection.py b/gui/test/inspection.py
index 368b6aa..bdb90da 100644
--- a/gui/test/inspection.py
+++ b/gui/test/inspection.py
@@ -1,92 +1,58 @@
#!/usr/bin/env python3
-"""Real-target checks for read-only inspection and explicit GDB JIT ELF import."""
+"""Real-target checks for bounded read-only inspection, source maps, and natural deoptimization."""
import argparse
-import json
-import os
from pathlib import Path
-import re
-import select
import subprocess
+import sys
import tempfile
+sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'bench'))
+from control import ROOT, Controller, natural, deoptimization
-ROOT = Path(__file__).resolve().parents[2]
-p = argparse.ArgumentParser(description=__doc__)
-p.add_argument('--ztrace', type=Path, default=ROOT / 'gui/zig-out/bin/ztrace')
-p.add_argument('--d8', type=Path)
-a = p.parse_args()
-a.ztrace = a.ztrace.resolve()
-with tempfile.TemporaryDirectory(prefix='ztrace-inspect-') as directory:
- work = Path(directory)
- small = work / 'loop'
- subprocess.run(['cc', '-g', '-O0', str(ROOT / 'gui/targets/loop.c'), '-o', str(small)], check=True)
- programs = [('c', [str(small)])]
- js = work / f'gui-inspect-{os.getpid()}.js'
- if a.d8:
- js.write_bytes((ROOT / 'gui/targets/jit.js').read_bytes())
- programs.append(('v8', [str(a.d8.resolve()), '--allow-natives-syntax', '--no-concurrent-recompilation',
- '--no-maglev', '--gdbjit', '--gdbjit-dump', '--gdbjit-dump-filter=jitWork',
- '--print-opt-code', '--print-opt-code-filter=jitWork', js.name]))
- for name, argv in programs:
- recording = work / (name + '.ztrace')
- with (work / (name + '.log')).open('w+') as log:
- target = subprocess.Popen([str(a.ztrace), 'serve', str(recording), '--', *argv],
- cwd=work, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=log, bufsize=0)
- pending = b''
- def read():
- global pending
- while b'\n' not in pending:
- assert select.select([target.stdout], [], [], 30)[0], 'controller timeout'
- data = os.read(target.stdout.fileno(), 4096)
- assert data, 'controller exited'
- pending += data
- line, pending = pending.split(b'\n', 1)
- return json.loads(line)
- def command(text, status='stopped'):
- target.stdin.write((text + '\n').encode())
- while True:
- answer = read()
- if answer['status'] != 'running':
- assert answer['status'] == status, answer
- return answer
- elf = None
+def inspect(c, stopped):
+ for kind, count in [('code', 128), ('memory', 256)]:
+ assert c.command(f'inspect {kind} {stopped["pc"]} {count}')['pc'] == stopped['pc']
+ for request in ['inspect code 0 0', 'inspect code 0 257', 'inspect memory 0 4097', 'inspect cheese 0 8', 'source-map /tmp']:
+ assert c.command(request, 'failed')['pc'] == stopped['pc']
+ assert c.command('inspect memory 0 16')['pc'] == stopped['pc']
+ assert 'State:\tt' in Path(f'/proc/{stopped["pid"]}/status').read_text()
+ assert c.command('stepi')['pc'] != stopped['pc']
+
+
+def main():
+ p = argparse.ArgumentParser(description=__doc__)
+ p.add_argument('--ztrace', type=Path, default=ROOT / 'gui/zig-out/bin/ztrace')
+ p.add_argument('--d8', type=Path)
+ p.add_argument('--source', type=Path, default=Path('/tmp/computeranim-v8-source'))
+ a = p.parse_args()
+ with tempfile.TemporaryDirectory(prefix='ztrace-inspect-') as directory:
+ out = Path(directory)
+ small = out / 'loop'
+ subprocess.run(['cc', '-g', '-O0', str(ROOT / 'gui/targets/loop.c'), '-o', str(small)], check=True)
+ c = Controller(a.ztrace, out, 'c', [str(small)])
+ try:
+ c.read()
+ c.command('break work')
+ stopped = c.command('continue')
+ inspect(c, stopped)
+ c.command('source-map ' + str(ROOT / 'gui/targets') + ' /mapped-source')
+ assert '/mapped-source/loop.c:' in c.show()
+ c.command('source-map ' + str(ROOT / 'gui/targets') + ' ' + str(ROOT / 'gui/targets'))
+ assert str(ROOT / 'gui/targets/loop.c') in c.show()
+ print('C: bounded inspection preserved PC; source prefix replacement and stepping passed')
+ finally:
+ c.close()
+ if a.d8:
+ c, js, elf, bounds, instructions, stopped = natural(a.ztrace, a.d8, out, a.source)
try:
- assert read()['status'] == 'stopped'
- if name == 'c':
- command('break work')
- stopped = command('continue')
- else:
- command('continue')
- log.seek(0)
- assembly = log.read()
- address = int(re.search(r'^(0x[0-9a-f]+)\s+[0-9a-f]+\s+[0-9a-f]+\s+addl r8,r11', assembly, re.M)[1], 16)
- command('signal 0')
- command('break *' + hex(address))
- stopped = command('continue')
- assert stopped['pc'] == address
- elf, = Path('/tmp').glob('elfdumpjitWork ' + js.name + ':*.o')
- loaded = command('symbols ' + str(elf))
- assert loaded['pc'] == stopped['pc'], loaded
- show = subprocess.check_output([str(a.ztrace), 'show', str(recording), '-1'], text=True)
- assert str(js) + ':6:' in show, show[:2000]
- assert '(gui-inspect-' in show, 'instruction source metadata missing'
- for kind, count in [('code', 128), ('memory', 256)]:
- seen = command(f'inspect {kind} {stopped["pc"]} {count}')
- assert seen['pc'] == stopped['pc'], seen
- for request in ['inspect code 0 0', 'inspect code 0 257', 'inspect memory 0 4097', 'inspect cheese 0 8']:
- failed = command(request, 'failed')
- assert failed['pc'] == stopped['pc']
- seen = command('inspect memory 0 16')
- assert seen['pc'] == stopped['pc']
- assert 'State:\tt' in Path(f'/proc/{stopped["pid"]}/status').read_text()
- moved = command('stepi')
- assert moved['pc'] != stopped['pc']
- print(name + ': inspection preserved PC; bounds rejected; stepping still works' + ('; real JIT source line recorded' if name == 'v8' else ''))
+ inspect(c, stopped)
+ result = deoptimization(c, bounds, instructions, a.source)
+ assert result['reason'] == 'wrong map'
+ print('V8: natural optimization, generated exit, native source, wrong map and ' + result['fallback_tier'] + ' dispatch verified')
finally:
- if target.poll() is None:
- target.stdin.write(b'quit\n')
- target.wait(timeout=30)
- target.stdin.close()
- target.stdout.close()
- if elf is not None:
- elf.unlink(missing_ok=True)
+ c.close()
+ elf.unlink(missing_ok=True)
+
+
+if __name__ == '__main__':
+ main()