1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#!/usr/bin/env python
from __future__ import print_function
import glob, os, re
import optparse
import inspect
"""
Quick script for parsing the output of the test system and summarizing the results.
"""
def inInstallDir():
"""
When slepc is installed then this file in installed in:
<PREFIX>/share/slepc/examples/config/report_tests.py
otherwise the path is:
<PETSC_DIR>/config/report_tests.py
We use this difference to determine if we are in installdir
"""
thisscriptdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
dirlist=thisscriptdir.split(os.path.sep)
if len(dirlist)>4:
lastfour=os.path.sep.join(dirlist[len(dirlist)-4:])
if lastfour==os.path.join('share','slepc','examples','config'):
return True
else:
return False
else:
return False
def summarize_results(directory,make,ntime,etime):
''' Loop over all of the results files and summarize the results'''
startdir=os.path.realpath(os.path.curdir)
try:
os.chdir(directory)
except OSError:
print('# No tests run')
return
summary={'total':0,'success':0,'failed':0,'failures':[],'todo':0,'skip':0,
'time':0}
timesummary={}
timelist=[]
for cfile in glob.glob('*.counts'):
with open(cfile, 'r') as f:
for line in f:
l = line.split()
if l[0] == 'failures':
if len(l)>1:
summary[l[0]] += l[1:]
elif l[0] == 'time':
if len(l)==1: continue
summary[l[0]] += float(l[1])
timesummary[cfile]=float(l[1])
timelist.append(float(l[1]))
elif l[0] not in summary:
continue
else:
summary[l[0]] += int(l[1])
failstr=' '.join(summary['failures'])
print("\n# -------------")
print("# Summary ")
print("# -------------")
if failstr.strip(): print("# FAILED " + failstr)
for t in "success failed todo skip".split():
percent=summary[t]/float(summary['total'])*100
print("# %s %d/%d tests (%3.1f%%)" % (t, summary[t], summary['total'], percent))
print("#")
if etime:
print("# Wall clock time for tests: %s sec"% etime)
print("# Approximate CPU time (not incl. build time): %s sec"% summary['time'])
if failstr.strip():
fail_targets=(
re.sub('(?<=[0-9]_\w)_.*','',
re.sub('cmd-','',
re.sub('diff-','',failstr+' ')))
)
# Strip off characters from subtests
fail_list=[]
for failure in fail_targets.split():
if failure.count('-')>1:
fail_list.append('-'.join(failure.split('-')[:-1]))
else:
fail_list.append(failure)
fail_list=list(set(fail_list))
fail_targets=' '.join(fail_list)
#Make the message nice
makefile="gmakefile.test" if inInstallDir() else "gmakefile"
print("#\n# To rerun failed tests: ")
print("# "+make+" -f "+makefile+" test search='" + fail_targets.strip()+"'")
if ntime>0:
print("#\n# Timing summary: ")
timelist=list(set(timelist))
timelist.sort(reverse=True)
nlim=(ntime if ntime<len(timelist) else len(timelist))
# Do a double loop to sort in order
for timelimit in timelist[0:nlim]:
for cf in timesummary:
if timesummary[cf] == timelimit:
print("# %s: %.2f sec" % (re.sub('.counts','',cf), timesummary[cf]))
return
def main():
parser = optparse.OptionParser(usage="%prog [options]")
parser.add_option('-d', '--directory', dest='directory',
help='Directory containing results of slepc test system',
default=os.path.join(os.environ.get('PETSC_ARCH',''),
'tests','counts'))
parser.add_option('-e', '--elapsed_time', dest='elapsed_time',
help='Report elapsed time in output',
default=None)
parser.add_option('-m', '--make', dest='make',
help='make executable to report in summary',
default='make')
parser.add_option('-t', '--time', dest='time',
help='-t n: Report on the n number expensive jobs',
default=0)
options, args = parser.parse_args()
# Process arguments
if len(args) > 0:
parser.print_usage()
return
summarize_results(options.directory,options.make,int(options.time),options.elapsed_time)
if __name__ == "__main__":
main()
|