xref: /petsc/config/report_tests.py (revision 93bdfce9bbcf736985cf7315d2c4474a1922c2df)
1#!/usr/bin/env python
2import glob, os, re
3import optparse
4"""
5Quick script for parsing the output of the test system and summarizing the results.
6"""
7
8def summarize_results(directory):
9  ''' Loop over all of the results files and summarize the results'''
10  startdir=os.path.realpath(os.path.curdir)
11  try:
12    os.chdir(directory)
13  except OSError:
14    print('# No tests run')
15    return
16  summary={'total':0,'success':0,'failed':0,'failures':[],'todo':0,'skip':0}
17  for cfile in glob.glob('*.counts'):
18    with open(cfile, 'r') as f:
19      for line in f:
20        l = line.split()
21        summary[l[0]] += l[1:] if l[0] == 'failures' else int(l[1])
22
23  failstr=' '.join(summary['failures'])
24  print("\n# -------------")
25  print("#   Summary    ")
26  print("# -------------")
27  print("# FAILED " + failstr)
28
29  for t in "success failed todo skip".split():
30    percent=summary[t]/float(summary['total'])*100
31    print("# %s %d/%d tests (%3.1f%%)" % (t, summary[t], summary['total'], percent))
32
33  fail_targets=(
34          re.sub('(?<=[0-9]_\w)_.*','',
35          re.sub('_1 ',' ',
36          re.sub('-','-run',
37          re.sub('cmd-','',
38          re.sub('diff-','',failstr+' ')))))
39          )
40  # Need to make sure we have a unique list
41  fail_targets=' '.join(list(set(fail_targets.split())))
42  print("#\n# To rerun failed tests: ")
43  print("#     make -f gmakefile.test test search='" + fail_targets.strip()+"'")
44  return
45
46def main():
47    parser = optparse.OptionParser(usage="%prog [options]")
48    parser.add_option('-d', '--directory', dest='directory',
49                      help='Directory containing results of petsc test system',
50                      default='counts')
51    options, args = parser.parse_args()
52
53    # Process arguments
54    if len(args) > 0:
55      parser.print_usage()
56      return
57
58    summarize_results(options.directory)
59
60if __name__ == "__main__":
61        main()
62