xref: /petsc/config/report_tests.py (revision 609bdbee21ea3be08735c64dbe00a9ab27759925)
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    sh=open(cfile,"r"); fileStr=sh.read(); sh.close()
19    for line in fileStr.split('\n'):
20      if not line: break
21      try:
22        var,val=line.split()
23        if not val.strip(): continue
24        val=int(val)
25      except:
26        var=line.split()[0]
27        lval=len(line.split())-1
28        if lval==0: continue
29        val=line.split()[1]
30        if not val.strip(): continue
31        append=" ("+str(lval)+"), " if lval>1 else ", "
32        val=val+append
33
34      summary[var]=summary[var]+val
35
36  print "\n# -------------"
37  print "#   Summary    "
38  print "# -------------"
39  print "# FAILED "+summary['failures'].rstrip(', ')
40  total=str(summary['total'])
41
42  for t in "success failed todo skip".split():
43    percent=summary[t]/float(summary['total'])*100
44    print ("# "+t+" "+ str(summary[t])+"/"+total+" tests (%3.1f%%)") % (percent)
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