xref: /petsc/config/report_tests.py (revision b41ce5d507ea9a58bfa83cf403107a702e77a67d)
1#!/usr/bin/env python
2import glob, os
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  print("\n# -------------")
24  print("#   Summary    ")
25  print("# -------------")
26  print("# FAILED " + ' '.join(summary['failures']))
27
28  for t in "success failed todo skip".split():
29    percent=summary[t]/float(summary['total'])*100
30    print("# %s %d/%d tests (%3.1f%%)" % (t, summary[t], summary['total'], percent))
31  return
32
33def main():
34    parser = optparse.OptionParser(usage="%prog [options]")
35    parser.add_option('-d', '--directory', dest='directory',
36                      help='Directory containing results of petsc test system',
37                      default='counts')
38    options, args = parser.parse_args()
39
40    # Process arguments
41    if len(args) > 0:
42      parser.print_usage()
43      return
44
45    summarize_results(options.directory)
46
47if __name__ == "__main__":
48        main()
49