File size: 2,604 Bytes
870b85a
 
3f15e9f
 
 
 
870b85a
3f15e9f
 
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Per seed: take the newest finished run (z_ > x_ > w_), re-run the current conventions audit on its saved manifest and report the
final status with the driver's rule: geometry+visibility passed AND audit passed => accepted."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
import rhg_paths
import json, subprocess, sys, glob, os
V = rhg_paths.resolve('${RHG_WORKSPACE_ROOT}/hayfung/validation/')
AUDIT = rhg_paths.resolve('${RHG_WORKSPACE_ROOT}/generic_20261101/src/layout_conventions_audit.py')
PREF = {'z': 3, 'x': 2, 'w': 1}
best = {}
for d in glob.glob(V + '[wxz]_*/'):
    p = d + 'results.json'
    if not os.path.exists(p):
        continue
    r = json.load(open(p))[0]
    k = PREF[os.path.basename(d.rstrip('/'))[0]]
    if r['seed'] not in best or k > best[r['seed']][0]:
        best[r['seed']] = (k, d, r)
rows = []
for seed, (k, d, r) in sorted(best.items(), key=lambda x: int(x[0])):
    status, fails, warns = r['status'], None, None
    manifest = None
    try:
        manifest = json.load(open(d + 'run_01/execute.receipt.json'))
    except Exception:
        pass
    res = None
    for cand in glob.glob(d + 'run_01/layout_conventions.json'):
        res = json.load(open(cand))
    if res is not None:
        m = res['manifest']; out = '/tmp/audit_%s.json' % seed
        shell = os.path.join(os.path.dirname(m), 'shell_geometry_input.json')
        cmd = ['/usr/bin/python3', '-B', AUDIT, '--manifest', m, '--out', out] + (['--shell', shell] if os.path.isfile(shell) else [])
        subprocess.run(cmd, stdout=subprocess.DEVNULL)
        a = json.load(open(out)); fails, warns = a['fail_count'], a['warn_count']
        if status in ('accepted_with_conventions', 'visibility_passed_conventions_failed'):
            status = 'accepted_with_conventions' if a['passed'] else 'visibility_passed_conventions_failed'
        rows.append(dict(seed=seed, run=os.path.basename(d.rstrip('/')), status=status, driver_status=r['status'], elapsed_s=r['elapsed_s'], fails=fails, warns=warns,
                         fail_rules=[f['rule'] for f in a['findings'] if f['severity'] == 'fail'], warn_rules=sorted({f['rule'] for f in a['findings'] if f['severity'] == 'warn'})))
    else:
        rows.append(dict(seed=seed, run=os.path.basename(d.rstrip('/')), status=status, driver_status=r['status'], elapsed_s=r['elapsed_s']))
json.dump(rows, open(V + 'final_table.json', 'w'), indent=1, ensure_ascii=False)
for x in rows:
    print(x['seed'], x['run'], x['status'], x['elapsed_s'], x.get('fails'), x.get('warns'), x.get('fail_rules', ''))