summaryrefslogtreecommitdiff
path: root/diff-instrumental.py
blob: 0cac04269cdd4880ca942f54bbb1fcaa5ebcf114 (plain)
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
from __future__ import print_function
import sys
import getopt

fail_under = None
max_difference = 0
read_location = None
save_location = None
raw = False

argv = sys.argv[1:]

opts, args = getopt.getopt(
    argv, "s:r:", ["fail-under=", "max-difference=", "save=", "read=", "raw"]
)
if args:
    raise ValueError("Unexpected parameters: {0}".format(args))
for opt, arg in opts:
    if opt == "-s" or opt == "--save":
        save_location = arg
    elif opt == "-r" or opt == "--read":
        read_location = arg
    elif opt == "--fail-under":
        fail_under = float(arg) / 100.0
    elif opt == "--max-difference":
        max_difference = float(arg) / 100.0
    elif opt == "--raw":
        raw = True
    else:
        raise ValueError("Unknown option: {0}".format(opt))

total_hits = 0
total_count = 0

for line in sys.stdin.readlines():
    if not line.startswith("ecdsa"):
        continue

    fields = line.split()
    hit, count = fields[1].split("/")
    total_hits += int(hit)
    total_count += int(count)

coverage = total_hits * 1.0 / total_count

if read_location:
    with open(read_location, "r") as f:
        old_coverage = float(f.read())
    print("Old coverage: {0:6.2f}%".format(old_coverage * 100))

if save_location:
    with open(save_location, "w") as f:
        f.write("{0:1.40f}".format(coverage))

if raw:
    print("{0:6.2f}".format(coverage * 100))
else:
    print("Coverage: {0:6.2f}%".format(coverage * 100))

if read_location:
    print("Difference: {0:6.2f}%".format((old_coverage - coverage) * 100))

if fail_under and coverage < fail_under:
    print("ERROR: Insufficient coverage.", file=sys.stderr)
    sys.exit(1)

if read_location and coverage - old_coverage < max_difference:
    print("ERROR: Too big decrease in coverage", file=sys.stderr)
    sys.exit(1)