jit-coverage-report.py 2.0 KB

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