diff options
Diffstat (limited to 'gui/test')
| -rw-r--r-- | gui/test/basic.script | 103 | ||||
| -rw-r--r-- | gui/test/inspection.py | 92 |
2 files changed, 185 insertions, 10 deletions
diff --git a/gui/test/basic.script b/gui/test/basic.script index 220eb0b..cf23a47 100644 --- a/gui/test/basic.script +++ b/gui/test/basic.script @@ -1,33 +1,116 @@ console launch {TARGET} await stops 1 -console break work +type :break work +expect command_open true +key return +expect command_open false +type ? +expect help true +key escape +expect help false console continue await stops 2 expect status stopped -key f10 +key s await stops 3 frames 6 screenshot {STRIKE} frames 60 screenshot {SETTLED} -expect-different-screenshot {STRIKE} {SETTLED} 24 756 1280 280 -key left +expect-different-screenshot {STRIKE} {SETTLED} 24 844 1072 360 +key left_bracket expect following false expect moment 1 -key end +# Browsing and per-pane history do not execute the target. +console goto memory 0x1000 +wheel 1500 1000 -0.5 +expect nav[2].place.row 1.5 +console goto memory 0x2000 +console mouse-button 4 1500 1000 +expect nav[2].place.address 4096 +expect nav[2].place.row 1.5 +console mouse-button 5 1500 1000 +expect nav[2].place.address 8192 +hold left_ctrl +key o +release left_ctrl +expect nav[2].place.address 4096 +console goto memory 0x3000 +console mouse-button 5 1500 1000 +expect nav[2].place.address 12288 +key j +expect nav[2].place.row 1 +key g +key g +expect nav[2].place.row 0 +hold left_ctrl +key d +release left_ctrl +expect nav[2].place.row 7.5 +key f +expect nav[2].place.follow true +# Rendered code addresses route to disassembly, including source-aligned rows. +console mouse-button 3 650 122 +expect focus code +expect nav[0].place.follow false +console mouse-button 4 650 122 +expect nav[0].place.follow true +console mouse-button 5 650 122 +expect nav[0].place.follow false +key f +# Stack storage addresses route to telescope. +console mouse-button 3 250 855 +expect focus stack +expect nav[1].place.follow false +console mouse-button 4 250 855 +expect nav[1].place.follow true +console mouse-button 5 250 855 +expect nav[1].place.follow false +key f +expect status stopped +expect stops 3 +expect moment 1 +# A real address lens, with an animated rise and real recorded bytes. +click 250 855 +expect lens true +frames 6 +screenshot {LENS} +frames 30 +screenshot {LENS_SETTLED} +expect-different-screenshot {LENS} {LENS_SETTLED} 1090 580 1120 230 +key escape +expect lens false +# Opening from a call-frame address keeps its origin visible. +click 1700 726 +expect lens true +frames 30 +screenshot {FRAME_LENS} +key escape +expect lens false +# Minimap dragging moves the viewport without changing the target. +down 2175 950 +move 2175 1100 +up 2175 1100 +expect focus memory +key f +expect nav[2].place.follow true +expect stops 3 +hold left_shift +key f +release left_shift expect following true expect moment 2 console clear 1 -key f5 +key c await status running -key f5 +key escape await status stopped -click 260 50 +click 80 54 await stops 5 -key f11 +key n await stops 6 expect status stopped expect-no-log InterruptFailed expect-no-log CommandFailed -key f5 +key c await status running diff --git a/gui/test/inspection.py b/gui/test/inspection.py new file mode 100644 index 0000000..368b6aa --- /dev/null +++ b/gui/test/inspection.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +"""Real-target checks for read-only inspection and explicit GDB JIT ELF import.""" +import argparse +import json +import os +from pathlib import Path +import re +import select +import subprocess +import tempfile + +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 + 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 '')) + 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) |
