xref: /petsc/config/report_tests.py (revision 536a8a5b170ea90d331b2eaeca24068ed5349df1)
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  if failstr.strip(): 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  if failstr.strip():
34      fail_targets=(
35          re.sub('(?<=[0-9]_\w)_.*','',
36          re.sub('_1 ',' ',
37          re.sub('-','-run',
38          re.sub('cmd-','',
39          re.sub('diff-','',failstr+' ')))))
40          )
41      # Need to make sure we have a unique list
42      fail_targets=' '.join(list(set(fail_targets.split())))
43      print("#\n# To rerun failed tests: ")
44      print("#     make -f gmakefile.test test search='" + fail_targets.strip()+"'")
45  return
46
47def main():
48    parser = optparse.OptionParser(usage="%prog [options]")
49    parser.add_option('-d', '--directory', dest='directory',
50                      help='Directory containing results of petsc test system',
51                      default='counts')
52    options, args = parser.parse_args()
53
54    # Process arguments
55    if len(args) > 0:
56      parser.print_usage()
57      return
58
59    summarize_results(options.directory)
60
61if __name__ == "__main__":
62        main()
63