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