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 "\n# -------------" 33 print "# Summary " 34 print "# -------------" 35 print "# FAILED "+summary['failures'].rstrip(', ') 36 total=str(summary['total']) 37 38 for t in "success failed todo skip".split(): 39 percent=summary[t]/float(summary['total'])*100 40 prcnt="{:3.1f}".format(percent) 41 print "# "+t+" "+ str(summary[t])+"/"+total+" tests ("+prcnt+'%)' 42 return 43 44def main(): 45 parser = optparse.OptionParser(usage="%prog [options]") 46 parser.add_option('-d', '--directory', dest='directory', 47 help='Directory containing results of petsc test system', 48 default='counts') 49 options, args = parser.parse_args() 50 51 # Process arguments 52 if len(args) > 0: 53 parser.print_usage() 54 return 55 56 directory=options.directory 57 if not os.path.isdir(directory): 58 print directory+' is not a directory' 59 return 60 61 summarize_results(directory) 62 63if __name__ == "__main__": 64 main() 65