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
13 class FileFormatError(Exception):
16 def backend_int_pair(s
):
17 backend
, sep
, value
= s
.partition('=')
19 raise argparse
.ArgumentTypeError("'=' missing, expected name=value")
21 raise argparse
.ArgumentTypeError("Expected name=value")
23 raise argparse
.ArgumentTypeError("Expected name=value")
24 return backend
, int(value
)
27 parser
= argparse
.ArgumentParser(description
=__doc__
)
28 parser
.add_argument('input', nargs
='+')
29 parser
.add_argument('--num-rules', type=backend_int_pair
, action
='append',
30 metavar
='BACKEND=NUM',
31 help='Specify the number of rules for a backend')
32 args
= parser
.parse_args()
36 for input_filename
in args
.input:
37 with
open(input_filename
, 'rb') as input_fh
:
38 data
= input_fh
.read()
41 backend
, _
, data
= data
.partition('\0')
46 raise FileFormatError()
47 backend
, = struct
.unpack("%ds" % len(backend
), backend
)
51 raise FileFormatError()
52 rule_id
, = struct
.unpack("Q", data
[:8])
55 if rule_id
== (2 ** 64) - 1:
57 covered_rules
[backend
] = covered_rules
.get(backend
, {})
58 covered_rules
[backend
][rule_id
] = covered_rules
[backend
].get(rule_id
, 0) + 1
60 num_rules
= dict(args
.num_rules
)
61 for backend
, rules_for_backend
in covered_rules
.items():
62 if backend
in num_rules
:
63 print("%s: %3.2f%% of rules covered" % (backend
, float(len(rules_for_backend
)) / num_rules
[backend
]) * 100)
65 print("%s: %d rules covered" % (backend
, len(rules_for_backend
)))
67 if __name__
== '__main__':