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
|
#!/usr/bin/env python3
"""Real-target checks for bounded read-only inspection, source maps, and natural deoptimization."""
import argparse
from pathlib import Path
import subprocess
import sys
import tempfile
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'bench'))
from control import ROOT, Controller, natural, deoptimization
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:
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:
c.close()
elf.unlink(missing_ok=True)
if __name__ == '__main__':
main()
|