3 Summarize the information in the given coverage files.
5 Emits the number of rules covered or the percentage of rules covered depending
6 on whether --num-rules has been used to specify the total number of rules.
8 from __future__
import print_function
14 class FileFormatError(Exception):
18 def backend_int_pair(s
):
19 backend
, sep
, value
= s
.partition("=")
21 raise argparse
.ArgumentTypeError("'=' missing, expected name=value")
23 raise argparse
.ArgumentTypeError("Expected name=value")
25 raise argparse
.ArgumentTypeError("Expected name=value")
26 return backend
, int(value
)
30 parser
= argparse
.ArgumentParser(description
=__doc__
)
31 parser
.add_argument("input", nargs
="+")
34 type=backend_int_pair
,
36 metavar
="BACKEND=NUM",
37 help="Specify the number of rules for a backend",
39 args
= parser
.parse_args()
43 for input_filename
in args
.input:
44 with
open(input_filename
, "rb") as input_fh
:
45 data
= input_fh
.read()
48 backend
, _
, data
= data
.partition("\0")
53 raise FileFormatError()
54 (backend
,) = struct
.unpack("%ds" % len(backend
), backend
)
58 raise FileFormatError()
59 (rule_id
,) = struct
.unpack("Q", data
[:8])
62 if rule_id
== (2**64) - 1:
64 covered_rules
[backend
] = covered_rules
.get(backend
, {})
65 covered_rules
[backend
][rule_id
] = (
66 covered_rules
[backend
].get(rule_id
, 0) + 1
69 num_rules
= dict(args
.num_rules
)
70 for backend
, rules_for_backend
in covered_rules
.items():
71 if backend
in num_rules
:
73 "%s: %3.2f%% of rules covered"
74 % (backend
, float(len(rules_for_backend
)) / num_rules
[backend
])
78 print("%s: %d rules covered" % (backend
, len(rules_for_backend
)))
81 if __name__
== "__main__":