openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / bin / oal-gate
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # oal-gate [--min-backends N] RESULTS.jsonl... |
| 4 | # Judge oal-matrix output. Prints one line per finding, then a summary line. Exit 0 when: |
| 5 | # every control fails (FAIL or RUNTIME_FAIL) wherever it ran, and never passes; |
| 6 | # every workload has at least N backends whose every record PASSed; |
| 7 | # no workload record ends FAIL, RUNTIME_FAIL, COMPILE_FAIL or TIMEOUT; |
| 8 | # the same (workload, params, seed) produced the same case_sha256 on every runner. |
| 9 | # Exit 1 otherwise, 2 on a usage error. |
| 10 | # INTERIM host glue (Python). Successor: oal-gate in seeded Omega. |
| 11 | import os |
| 12 | import sys |
| 13 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) |
| 14 | import argparse |
| 15 | import collections |
| 16 | import json |
| 17 | |
| 18 | ap = argparse.ArgumentParser(prog="oal-gate") |
| 19 | ap.add_argument("--min-backends", type=int, default=3) |
| 20 | ap.add_argument("files", nargs="+") |
| 21 | a = ap.parse_args() |
| 22 | recs = [] |
| 23 | for path in a.files: |
| 24 | with open(path) as f: |
| 25 | recs += [json.loads(l) for l in f if l.strip()] |
| 26 | bad = 0 |
| 27 | cases = {} |
| 28 | passing = collections.defaultdict(lambda: collections.defaultdict(list)) |
| 29 | names = set() |
| 30 | for r in recs: |
| 31 | key = (r["workload"], json.dumps(r["params"], sort_keys=True), r["seed"]) |
| 32 | prev = cases.setdefault(key, (r["case_sha256"], r["machine"]["arch"])) |
| 33 | if prev[0] != r["case_sha256"]: |
| 34 | print("CASE-MISMATCH %s %s seed %d: %s on %s, %s on %s" % (key[0], key[1], key[2], prev[0][:12], prev[1], |
| 35 | r["case_sha256"][:12], r["machine"]["arch"])) |
| 36 | bad += 1 |
| 37 | if r["control"]: |
| 38 | if r["status"] == "PASS": |
| 39 | print("CONTROL-PASSED %s on %s (%s) seed %d: the wrong kernel was not flagged" % ( |
| 40 | r["workload"], r["backend"], r["machine"]["arch"], r["seed"])) |
| 41 | bad += 1 |
| 42 | continue |
| 43 | names.add(r["workload"]) |
| 44 | if r["status"] in ("FAIL", "RUNTIME_FAIL", "COMPILE_FAIL", "TIMEOUT"): |
| 45 | print("ENTRANT-%s %s on %s (%s) params %s seed %d" % (r["status"], r["workload"], r["backend"], |
| 46 | r["machine"]["arch"], key[1], r["seed"])) |
| 47 | bad += 1 |
| 48 | if r["status"] in ("PASS", "FAIL", "RUNTIME_FAIL", "COMPILE_FAIL", "TIMEOUT"): |
| 49 | passing[r["workload"]][r["backend"]].append(r["status"] == "PASS") |
| 50 | for w in sorted(names): |
| 51 | ok = sorted(b for b, v in passing[w].items() if v and all(v)) |
| 52 | if len(ok) < a.min_backends: |
| 53 | print("TOO-FEW-BACKENDS %s: %d passing (%s), need %d" % (w, len(ok), ",".join(ok) or "none", a.min_backends)) |
| 54 | bad += 1 |
| 55 | nctl = len({r["workload"] for r in recs if r["control"]}) |
| 56 | print("oal-gate: %d records, %d workloads, %d controls, %d findings" % (len(recs), len(names), nctl, bad)) |
| 57 | sys.exit(1 if bad else 0) |