omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / om / tls / test / x509 / limbo.py
| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | """Judge driver.om R results against x509-limbo expectations (test oracle, not shipped). |
| 3 | |
| 4 | usage: python3 limbo.py META_TSV RESULTS_TXT ALLOW_TXT |
| 5 | A case is |
| 6 | agree limbo SUCCESS and X509_OK, or limbo FAILURE and any reject code |
| 7 | ACCEPT limbo FAILURE but X509_OK: a chain limbo says must be refused was accepted |
| 8 | reject limbo SUCCESS but a reject code: stricter than limbo |
| 9 | ALLOW_TXT lists the explained differences, one per line: "accept|reject ID-GLOB CODE|* reason"; |
| 10 | the first matching line explains a case. Exit 1 on any unexplained ACCEPT or reject, on a case with |
| 11 | no result, on a trap or a STORE/LIST setup failure, and on an allow line that matches nothing. |
| 12 | Prints per-category counts and the final line |
| 13 | "LIMBO PASS|FAIL cases=N agree=A explained_accept=X explained_reject=R skipped=S unexplained=U". |
| 14 | """ |
| 15 | import collections |
| 16 | import fnmatch |
| 17 | import sys |
| 18 | |
| 19 | |
| 20 | def main(): |
| 21 | meta, res, allow = sys.argv[1:4] |
| 22 | rules = [] |
| 23 | for line in open(allow): |
| 24 | line = line.strip() |
| 25 | if not line or line.startswith("#"): |
| 26 | continue |
| 27 | kind, glob, code, why = line.split(None, 3) |
| 28 | rules.append([kind, glob, code, why, 0]) |
| 29 | got = {} |
| 30 | for line in open(res): |
| 31 | f = line.split() |
| 32 | if len(f) == 3 and f[0] == "RESULT": |
| 33 | got[f[1]] = f[2] |
| 34 | count = collections.Counter() |
| 35 | bad = [] |
| 36 | n = 0 |
| 37 | for line in open(meta): |
| 38 | name, cid, want, kind, flags = line.rstrip("\n").split("\t") |
| 39 | if flags.startswith("SKIP:"): |
| 40 | count["skipped " + flags[5:]] += 1 |
| 41 | continue |
| 42 | n += 1 |
| 43 | g = got.get(name) |
| 44 | if g is None or g in ("STORE", "LIST"): |
| 45 | bad.append("%s %s no result (%s)" % (name, cid, g)) |
| 46 | continue |
| 47 | ok = g == "X509_OK" |
| 48 | if (want == "SUCCESS") == ok: |
| 49 | count["agree"] += 1 |
| 50 | continue |
| 51 | k = "accept" if ok else "reject" |
| 52 | for r in rules: |
| 53 | if r[0] == k and fnmatch.fnmatchcase(cid, r[1]) and r[2] in ("*", g): |
| 54 | r[4] += 1 |
| 55 | count["explained %s: %s (%s)" % (k, r[3], g)] += 1 |
| 56 | break |
| 57 | else: |
| 58 | bad.append("UNEXPLAINED %s %s %s want %s got %s flags %s" % (k, name, cid, want, g, flags)) |
| 59 | for r in rules: |
| 60 | if r[4] == 0: |
| 61 | bad.append("allow line matches nothing: %s %s %s" % tuple(r[:3])) |
| 62 | for k in sorted(count): |
| 63 | print("%6d %s" % (count[k], k)) |
| 64 | for b in bad: |
| 65 | print(b) |
| 66 | acc = sum(v for k, v in count.items() if k.startswith("explained accept")) |
| 67 | rej = sum(v for k, v in count.items() if k.startswith("explained reject")) |
| 68 | sk = sum(v for k, v in count.items() if k.startswith("skipped")) |
| 69 | unexpl = sum(1 for b in bad if b.startswith("UNEXPLAINED")) |
| 70 | print("LIMBO %s cases=%d agree=%d explained_accept=%d explained_reject=%d skipped=%d unexplained=%d" |
| 71 | % ("FAIL" if bad else "PASS", n, count["agree"], acc, rej, sk, unexpl)) |
| 72 | sys.exit(1 if bad else 0) |
| 73 | |
| 74 | |
| 75 | if __name__ == "__main__": |
| 76 | main() |