xref: /petsc/config/report_tests.py (revision 9f4d3c52fa2fe0bb72fec4f4e85d8e495867af35)
1#!/usr/bin/env python
2import glob, os, re
3import optparse
4import inspect
5
6"""
7Quick script for parsing the output of the test system and summarizing the results.
8"""
9
10def inInstallDir():
11  """
12  When petsc is installed then this file in installed in:
13       <PREFIX>/share/petsc/examples/config/gmakegentest.py
14  otherwise the path is:
15       <PETSC_DIR>/config/gmakegentest.py
16  We use this difference to determine if we are in installdir
17  """
18  thisscriptdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
19  dirlist=thisscriptdir.split(os.path.sep)
20  if len(dirlist)>4:
21    lastfour=os.path.sep.join(dirlist[len(dirlist)-4:])
22    if lastfour==os.path.join('share','petsc','examples','config'):
23      return True
24    else:
25      return False
26  else:
27    return False
28
29def summarize_results(directory,make):
30  ''' Loop over all of the results files and summarize the results'''
31  startdir=os.path.realpath(os.path.curdir)
32  try:
33    os.chdir(directory)
34  except OSError:
35    print('# No tests run')
36    return
37  summary={'total':0,'success':0,'failed':0,'failures':[],'todo':0,'skip':0}
38  for cfile in glob.glob('*.counts'):
39    with open(cfile, 'r') as f:
40      for line in f:
41        l = line.split()
42        summary[l[0]] += l[1:] if l[0] == 'failures' else int(l[1])
43
44  failstr=' '.join(summary['failures'])
45  print("\n# -------------")
46  print("#   Summary    ")
47  print("# -------------")
48  if failstr.strip(): print("# FAILED " + failstr)
49
50  for t in "success failed todo skip".split():
51    percent=summary[t]/float(summary['total'])*100
52    print("# %s %d/%d tests (%3.1f%%)" % (t, summary[t], summary['total'], percent))
53
54  if failstr.strip():
55      fail_targets=(
56          re.sub('(?<=[0-9]_\w)_.*','',
57          re.sub('_1 ',' ',
58          re.sub('-','-run',
59          re.sub('cmd-','',
60          re.sub('diff-','',failstr+' ')))))
61          )
62      # Need to make sure we have a unique list
63      fail_targets=' '.join(list(set(fail_targets.split())))
64
65      #Make the message nice
66      makefile="gmakefile.test" if inInstallDir() else "gmakefile"
67
68      print("#\n# To rerun failed tests: ")
69      print("#     "+make+" -f "+makefile+" test search='" + fail_targets.strip()+"'")
70  return
71
72def main():
73    parser = optparse.OptionParser(usage="%prog [options]")
74    parser.add_option('-d', '--directory', dest='directory',
75                      help='Directory containing results of petsc test system',
76                      default='counts')
77    parser.add_option('-m', '--make', dest='make',
78                      help='make executable to report in summary',
79                      default='make')
80    options, args = parser.parse_args()
81
82    # Process arguments
83    if len(args) > 0:
84      parser.print_usage()
85      return
86
87    summarize_results(options.directory,options.make)
88
89if __name__ == "__main__":
90        main()
91