annotate contrib/jit-coverage-report.py @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 #! /usr/bin/python
kono
parents:
diff changeset
2 #
kono
parents:
diff changeset
3 # Print a report on which libgccjit.so symbols are used in which test
kono
parents:
diff changeset
4 # cases, and which lack test coverage. Tested with Python 2.7 and 3.2
kono
parents:
diff changeset
5 # To be run from the root directory of the source tree.
kono
parents:
diff changeset
6 #
kono
parents:
diff changeset
7 # Copyright (C) 2014 Free Software Foundation, Inc.
kono
parents:
diff changeset
8 # Written by David Malcolm <dmalcolm@redhat.com>.
kono
parents:
diff changeset
9 #
kono
parents:
diff changeset
10 # This script is Free Software, and it can be copied, distributed and
kono
parents:
diff changeset
11 # modified as defined in the GNU General Public License. A copy of
kono
parents:
diff changeset
12 # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 from collections import Counter
kono
parents:
diff changeset
15 import glob
kono
parents:
diff changeset
16 import re
kono
parents:
diff changeset
17 import sys
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 def parse_map_file(path):
kono
parents:
diff changeset
20 """
kono
parents:
diff changeset
21 Parse libgccjit.map, returning the symbols in the API as a list of str.
kono
parents:
diff changeset
22 """
kono
parents:
diff changeset
23 syms = []
kono
parents:
diff changeset
24 with open(path) as f:
kono
parents:
diff changeset
25 for line in f:
kono
parents:
diff changeset
26 m = re.match('^\s+([a-z_]+);$', line)
kono
parents:
diff changeset
27 if m:
kono
parents:
diff changeset
28 syms.append(m.group(1))
kono
parents:
diff changeset
29 return syms
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 def parse_test_case(path):
kono
parents:
diff changeset
32 """
kono
parents:
diff changeset
33 Locate all symbol-like things in a C test case, yielding
kono
parents:
diff changeset
34 them as a sequence of str.
kono
parents:
diff changeset
35 """
kono
parents:
diff changeset
36 with open(path) as f:
kono
parents:
diff changeset
37 for line in f:
kono
parents:
diff changeset
38 for m in re.finditer('([_A-Za-z][_A-Za-z0-9]*)', line):
kono
parents:
diff changeset
39 yield m.group(1)
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 def find_test_cases():
kono
parents:
diff changeset
42 for path in glob.glob('gcc/testsuite/jit.dg/*.[ch]'):
kono
parents:
diff changeset
43 yield path
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 api_syms = parse_map_file('gcc/jit/libgccjit.map')
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 syms_in_test_cases = {}
kono
parents:
diff changeset
48 for path in find_test_cases():
kono
parents:
diff changeset
49 syms_in_test_cases[path] = list(parse_test_case(path))
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 uses = Counter()
kono
parents:
diff changeset
52 for sym in sorted(api_syms):
kono
parents:
diff changeset
53 print('symbol: %s' % sym)
kono
parents:
diff changeset
54 uses[sym] = 0
kono
parents:
diff changeset
55 for path in syms_in_test_cases:
kono
parents:
diff changeset
56 count = syms_in_test_cases[path].count(sym)
kono
parents:
diff changeset
57 uses[sym] += count
kono
parents:
diff changeset
58 if count:
kono
parents:
diff changeset
59 print(' uses in %s: %i' % (path, count))
kono
parents:
diff changeset
60 if uses[sym] == 0:
kono
parents:
diff changeset
61 print(' NEVER USED')
kono
parents:
diff changeset
62 sys.stdout.write('\n')
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 layout = '%40s %5s %s'
kono
parents:
diff changeset
65 print(layout % ('SYMBOL', 'USES', 'HISTOGRAM'))
kono
parents:
diff changeset
66 for sym, count in uses.most_common():
kono
parents:
diff changeset
67 print(layout % (sym, count, '*' * count if count else 'UNUSED'))