import json, re, sys, collections
r = json.load(open(sys.argv[1]))
top = int(sys.argv[2]) if len(sys.argv) > 2 else 12
fs = r["functions"]
by = collections.Counter(f["status"] for f in fs)
size = collections.Counter()
for f in fs: size[f["status"]] += f["size"]
print("functions: %d " % len(fs) + " ".join("%s=%d (%dB)" % (k, v, size[k]) for k, v in by.most_common()))
s, b = r["source"], r.get("binary_coverage", {})
print("source coverage: %d/%d = %.1f%%" % (s["proved"], s["total"], 100.0 * s["proved"] / max(1, s["total"])))
if b: print("binary coverage: %d/%d = %.1f%%" % (b.get("proved", 0), b.get("total", 0), 100.0 * b.get("proved", 0) / max(1, b.get("total", 1))))
print("skipped sources: %d" % len(r.get("skipped_sources", [])))
print("not counted: %d source functions without code (%d points), %d statements under a constant-false condition; %d proved bytes are constants among the code"
% (len(r.get("source_functions_not_in_binary", [])), r.get("source_points_not_in_binary", 0),
len(r.get("source_no_code", [])), b.get("constants", 0)))
byname = {f["name"]: f for f in fs}
led = collections.Counter(); worst = collections.Counter()
for g in b.get("ranges", []):
if g["state"] != "unproved": continue
f = byname.get(g.get("symbol"))
if g.get("symbol") is None: k = "no function symbol (data not located, vector table)"
elif f is None: k = "function without source (not verified)"
elif f["status"] == "proved": k = "inside a proved function (no path of the source reaches it)"
else: k = f["status"] + ": " + re.sub(r"[;(:].*", "", f["detail"]).strip()[:60]
led[k] += g["size"]
if f is not None and f["status"] != "proved": worst[f["name"]] += g["size"]
print("\n== unproved bytes by cause ==")
for k, v in led.most_common(): print("%7d %s" % (v, k))
print("largest: " + ", ".join("%s %d" % kv for kv in worst.most_common(10)))
def norm(d):
d = re.sub(r" \([^()]*:\d+\)$", "", d)
d = re.sub(r"^calls [A-Za-z0-9_.]+: ", "calls X: ", d)
d = re.sub(r"\b\d+ paths? proved", "N paths proved", d)
d = re.sub(r"0x[0-9a-f]+", "0xN", d)
d = re.sub(r"\b\d+\b", "N", d)
return d[:150]
for st in ("unsupported", "inconclusive", "bounded"):
c = collections.Counter(); sz = collections.Counter(); ex = {}
for f in fs:
if f["status"] == st:
k = norm(f["detail"]); c[k] += 1; sz[k] += f["size"]; ex.setdefault(k, f["name"])
print("\n== %s: top reasons (count, bytes, example) ==" % st)
for k, v in sorted(c.items(), key=lambda kv: -sz[kv[0]])[:top]:
print("%4d %6dB %-28s %s" % (v, sz[k], ex[k], k))
print("\n== mismatches ==")
for f in fs:
if f["status"] == "mismatch": print(" %-36s %5dB %s" % (f["name"], f["size"], f["detail"][:200]))
slow = sorted(fs, key=lambda f: -f["ms"])[:5]
print("\nslowest: " + ", ".join("%s %dms" % (f["name"], f["ms"]) for f in slow))