-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage_diff.py
More file actions
76 lines (62 loc) · 2.21 KB
/
Copy pathcoverage_diff.py
File metadata and controls
76 lines (62 loc) · 2.21 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
import os
import sys
def load(path):
if not os.path.exists(path):
raise RuntimeError(f"Missing coverage export: {path}")
if os.path.getsize(path) == 0:
raise RuntimeError(f"Coverage export is empty: {path}")
try:
with open(path, "r", encoding="utf-8") as handle:
data = json.load(handle)
except json.JSONDecodeError as err:
raise RuntimeError(f"Invalid JSON in {path}: {err}") from err
try:
files = data["data"][0]["files"]
except (KeyError, IndexError, TypeError) as err:
raise RuntimeError(f"Unexpected llvm-cov export shape in {path}") from err
result = {}
for f in files:
summary = f["summary"]["lines"]
percent = summary["percent"]
covered = summary["covered"]
total = summary["count"]
result[f["filename"]] = {
"percent": percent,
"covered": covered,
"total": total,
"missing": total - covered
}
return result
try:
macros = load("data/macros.json")
borrow = load("data/borrow.json")
except RuntimeError as err:
print(f"Error: {err}")
print("Hint: run ./run_coverage.sh, ./merge_profiles.sh, and ./export_coverage.sh first")
sys.exit(1)
print("\n=== Coverage Differences ===\n")
# Files only in macros
only_macros = set(macros.keys()) - set(borrow.keys())
if only_macros:
print("Files only covered by macro tests:")
for f in only_macros:
print(f" {f}")
# Files only in borrow
only_borrow = set(borrow.keys()) - set(macros.keys())
if only_borrow:
print("Files only covered by borrow tests:")
for f in only_borrow:
print(f" {f}")
# Common files with big differences
common = set(macros.keys()) & set(borrow.keys())
big_diffs = []
for f in common:
diff = abs(macros[f]["percent"] - borrow[f]["percent"])
if diff > 10: # arbitrary threshold
big_diffs.append((f, diff, macros[f]["percent"], borrow[f]["percent"]))
big_diffs.sort(key=lambda x: x[1], reverse=True)
if big_diffs:
print("Files with significant coverage differences (>10%):")
for f, diff, m_pct, b_pct in big_diffs[:10]:
print(f" {f}: macro {m_pct:.2f}%, borrow {b_pct:.2f}% (diff {diff:.2f}%)")