xref: /petsc/config/report_tests.py (revision 8ccd5183338cbf93f0b46c61e37b2657320e4638)
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  os.chdir(directory)
12  summary={'total':0,'success':0,'failed':0,'failures':'','todo':0,'skip':0}
13  for cfile in glob.glob('*.counts'):
14    sh=open(cfile,"r"); fileStr=sh.read(); sh.close()
15    for line in fileStr.split('\n'):
16      if not line: break
17      try:
18        var,val=line.split()
19        if not val.strip(): continue
20        val=int(val)
21      except:
22        var=line.split()[0]
23        val=" ".join(line.split()[1:])+" "
24      summary[var]=summary[var]+val
25
26  print "# FAILED "+summary['failures']
27  total=str(summary['total'])
28
29  for t in "success failed todo skip".split():
30    percent=summary[t]/float(summary['total'])*100
31    prcnt="{:3.1f}".format(percent)
32    print "# "+t+" "+ str(summary[t])+"/"+total+" tests ("+prcnt+'%)'
33  return
34
35def main():
36    parser = optparse.OptionParser(usage="%prog [options]")
37    parser.add_option('-d', '--directory', dest='directory',
38                      help='Directory containing results of petsc test system',
39                      default='counts')
40    options, args = parser.parse_args()
41
42    # Process arguments
43    if len(args) > 0:
44      parser.print_usage()
45      return
46
47    directory=options.directory
48    if not os.path.isdir(directory):
49      print directory+' is not a directory'
50      return
51
52    summarize_results(directory)
53
54if __name__ == "__main__":
55        main()
56