File size: 1,479 Bytes
8d4e520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Convert and validate every raw window; a process indir selects only window 0."""
import json
from pathlib import Path
import re
import subprocess
import sys

root = Path(sys.argv[1])
dr = '/data/cpu-tracing/tools/DynamoRIO-Linux-11.91.20708/bin64/drrun'
records = []
for window in sorted((root / 'native').glob('*/raw/window.*')):
    label = window.parent.parent.name + '-' + window.name
    log = root / 'validation' / (label + '.log')
    log.parent.mkdir(exist_ok=True)
    # Converter needs the parent trace directory to exist for the first window.
    (window.parent.parent / 'trace').mkdir(exist_ok=True)
    cmd = [dr, '-t', 'drmemtrace', '-indir', str(window),
           '-tool', 'basic_counts:invariant_checker', '-jobs', '1']
    with log.open('w') as stream:
        rc = subprocess.run(cmd, stdout=stream, stderr=subprocess.STDOUT,
                            timeout=600).returncode
    text = log.read_text()
    count = re.search(r'(\d+) total \(fetched\) instructions', text)
    record = {'window': str(window.relative_to(root)), 'command': cmd,
              'returncode': rc, 'invariants_passed': 'Trace invariant checks passed' in text,
              'fetched_instructions': int(count[1]) if count else None}
    records.append(record)
    print(json.dumps(record), flush=True)
    (root / 'validation.json').write_text(json.dumps(records, indent=2))
if not records or any(r['returncode'] or not r['invariants_passed'] for r in records):
    sys.exit(1)