xref: /petsc/config/report_tests.py (revision 01bcacee857cf80104286b57a1db04e7a3b08b61)
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        lval=len(line.split())-1
24        if lval==0: continue
25        val=line.split()[1]
26        if not val.strip(): continue
27        append=" ("+str(lval)+"), " if lval>1 else ", "
28        val=val+append
29
30      summary[var]=summary[var]+val
31
32  print "# FAILED "+summary['failures'].rstrip(', ')
33  total=str(summary['total'])
34
35  for t in "success failed todo skip".split():
36    percent=summary[t]/float(summary['total'])*100
37    prcnt="{:3.1f}".format(percent)
38    print "# "+t+" "+ str(summary[t])+"/"+total+" tests ("+prcnt+'%)'
39  return
40
41def main():
42    parser = optparse.OptionParser(usage="%prog [options]")
43    parser.add_option('-d', '--directory', dest='directory',
44                      help='Directory containing results of petsc test system',
45                      default='counts')
46    options, args = parser.parse_args()
47
48    # Process arguments
49    if len(args) > 0:
50      parser.print_usage()
51      return
52
53    directory=options.directory
54    if not os.path.isdir(directory):
55      print directory+' is not a directory'
56      return
57
58    summarize_results(directory)
59
60if __name__ == "__main__":
61        main()
62