-
Notifications
You must be signed in to change notification settings - Fork 6
/
summarize_gcov.py
executable file
·59 lines (54 loc) · 2.11 KB
/
summarize_gcov.py
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
#!/usr/bin/env python3
import os
import sys
def summarize_gcov(path: str):
summary = {}
overall_sum = 0
overall_missed = 0
overall_noop = 0
overall_covered = 0
overall_max = 0
for root, _, files in os.walk(path):
for gcov_file in files:
if not gcov_file.endswith(".gcov"):
continue
file_path = os.path.join(root, gcov_file)
file_max = 0
file_sum = 0
file_covered = 0
file_missed = 0
file_noop = 0
with open(file_path) as content:
for line in content:
value = line.split(":")[0]
if value == "#####":
file_missed += 1
continue
if value == "-":
file_noop += 1
continue
value = int(value)
file_covered += 1
file_sum += value
if value > file_max:
file_max = value
file_all = max(file_covered + file_missed, 1)
summary[file_path] = {"max": file_max, "coverage": file_covered / file_all,
"sum": file_sum, "missed": file_missed, "covered": file_covered,
"average": file_sum / file_all, "noop": file_noop}
if file_max > overall_max:
overall_max = file_max
overall_covered += file_covered
overall_missed += file_missed
overall_noop += file_noop
overall_sum += file_sum
overall_all = max(overall_covered + overall_missed, 1)
summary["overall"] = {"max": overall_max, "coverage": overall_covered / overall_all,
"sum": overall_sum, "missed": overall_missed, "covered": overall_covered,
"average": overall_sum / overall_all, "noop": overall_noop}
return summary
if __name__ == "__main__":
import json
res = summarize_gcov(sys.argv[1])
with open(sys.argv[2], "w") as f:
json.dump(res, f, indent=2)