forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkTestLog.py
executable file
·269 lines (215 loc) · 9.27 KB
/
checkTestLog.py
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/env python
import os, sys, re, time
class TestLogChecker(object):
def __init__(self, outFileIn=None, verbIn=False):
self.outFile=sys.stdout
if outFileIn:
print "Summary file:", outFileIn
self.outFile=open(outFileIn, 'w')
self.verbose = verbIn
return
def __del__(self):
self.outFile.close()
return
def setVerbose(self, verbIn=False):
self.verbose = verbIn
return
def checkScramWarnings(self, logFile, verbose=False):
self.outFile.write("going to check "+ logFile+ ' for scram warnings\n')
#"""
#WARNING: Unable to find package/tool called Geometry/CommonDetAlgo
# in current project area (declared at src/RecoPixelVZero/PixelVZeroFinding/data)
#
#""""
exprNoPkg = '^WARNING: Unable to find package/tool called ([A-Za-z].*/[A-Za-z].*)'
exprNoPkg += '\s*in current project area \(declared at src/([A-Za-z].*)\)'
noPkgRe = re.compile(exprNoPkg)
#WARNING: PhysicsTools/RecoAlgos/BuildFile does not export anything:
noExportRe = re.compile('^WARNING: ([A-Za-a].*)/BuildFile does not export anything:')
lf = open(logFile,'r')
lines = lf.xreadlines()
startTime = time.time()
nLines = 0
nNoPkg = 0
noToolPkgs = []
noExport = []
testLines = {}
pkgLines = {}
prevLine = ""
for line in lines:
nLines += 1
# merge with the previous line (w/o the <endline> to get the two-line warnings from scram
both = prevLine[:-1] + line
prevLine = line
if both.find("WARNING:") == -1: continue
# analyze what we got
noPkgMatch = noPkgRe.match(both)
if noPkgMatch:
nNoPkg += 1
pkg = noPkgMatch.group(2).strip()
tool = noPkgMatch.group(1).strip()
tp = pkg+'--'+tool
if tp not in noToolPkgs: noToolPkgs.append(tp)
noExportMatch = noExportRe.match(both)
if noExportMatch:
buildFile = noExportMatch.group(1).strip()
if buildFile not in noExport:
noExport.append(buildFile)
lf.close()
self.outFile.write( 'found '+ str(nNoPkg)+ ' scram-warnings in ' +str( nLines)+ ' lines of log file.\n')
self.outFile.write( 'found ' + str(len(noToolPkgs))+ ' BuildFiles with tool problems\n')
if verbose:
for p in noToolPkgs: self.outFile.write( " "+p+'\n')
self.outFile.write('\n')
self.outFile.write( 'found ' +str(len(noExport))+ ' BuildFiles without exporting anything:\n')
if verbose:
for p in noExport: self.outFile.write( " "+ p+'\n')
self.outFile.write('\n')
self.outFile.write('\n')
return
# --------------------------------------------------------------------------------
def check(self, logFile):
self.outFile.write( "going to check "+ logFile+'\n')
subsysRe = re.compile('^>> Tests for package ([A-Za-z].*/[A-Za-z].*) ran.')
pkgTestStartRe = re.compile('^===== Test \"(.*)\" ====')
pkgTestEndRe = re.compile('^\^\^\^\^ End Test (.*) \^\^\^\^')
pkgTestResultRe = re.compile('.*---> test ([^ ]+) (had ERRORS|succeeded)')
pkgStartRe = re.compile("^>> Entering Package (.*)")
pkgEndRe = re.compile("^>> Leaving Package (.*)")
infoPkg = {}
pkgSubsysMap = {}
subsysPkgMap = {}
lf = open(logFile,'r')
lines = lf.xreadlines()
startTime = time.time()
nLines = 0
testNames = {}
testLines = {}
pkgLines = {}
results = {}
pkgTests = {}
actPkg = "None"
actTest = "None"
actTstLines = 0
actPkgLines = 0
for line in lines:
nLines += 1
actTstLines += 1
actPkgLines += 1
subsysMatch = subsysRe.match(line)
if subsysMatch:
subsys, pkg = subsysMatch.group(1).split('/')
if not pkgSubsysMap.has_key(pkg) :
pkgSubsysMap[pkg] = subsys
if subsysPkgMap.has_key(subsys) :
subsysPkgMap[subsys].append(pkg)
else:
subsysPkgMap[subsys] = [pkg]
pkgStartMatch = pkgStartRe.match(line)
if pkgStartMatch:
pkg = pkgStartMatch.group(1)
actPkg = pkg
pkgTests[pkg] = 0
actPkgLines = 0
pkgEndMatch = pkgEndRe.match(line)
if pkgEndMatch:
pkg = pkgEndMatch.group(1)
if actPkg != pkg :
self.outFile.write( "pkgEndMatch> package mismatch: pkg found "+pkg+' actPkg='+actPkg+'\n')
pkgLines[pkg] = actPkgLines
pkgTestResultMatch= pkgTestResultRe.match(line)
if pkgTestResultMatch : # this seems to only appear if there is an ERROR
tstName = pkgTestResultMatch.group(1)
results[tstName] = pkgTestResultMatch.group(2)
pkgTestStartMatch = pkgTestStartRe.match(line)
if pkgTestStartMatch:
tst = pkgTestStartMatch.group(1)
actTest = tst
actTstLines = 0
pkgTests[actPkg] += 1
if testNames.has_key(actPkg):
testNames[actPkg].append(actTest)
else:
testNames[actPkg] = [actTest]
if actTest not in results:
results[actTest] = "succeeded" # set the default, no error seen yet
pkgTestEndMatch = pkgTestEndRe.match(line)
if pkgTestEndMatch:
tst = pkgTestEndMatch.group(1)
if actTest != tst :
self.outFile.write( "pkgTestEndMatch> package mismatch: pkg found "+pkg+' actPkg='+actPkg+'\n')
testLines[tst] = actTstLines
stopTime = time.time()
lf.close()
self.outFile.write( "found a total of "+ str(nLines)+ ' lines in logfile.\n')
self.outFile.write( "analysis took "+str(stopTime-startTime)+ ' sec.\n')
self.outFile.write( "total number of tests: " +str( len(results.keys()) ) + '\n')
nMax = 1000
self.outFile.write( "tests with more than " +str(nMax) + " lines of logs:\n")
for pkg, lines in testLines.items():
if lines > nMax : self.outFile.write( " "+ pkg+ ' : ' + str(lines) +'\n')
self.outFile.write( "Number of tests for packages: \n" )
noTests = 0
nrTests = 0
indent = ' '
totalOK = 0
totalFail = 0
for pkg, nTst in pkgTests.items():
if nTst == 0:
noTests += 1
else:
nrTests += 1
if self.verbose: self.outFile.write( '-'*80 +'\n' )
self.outFile.write( indent+pkg+' : ' )
nOK = 0
if self.verbose: self.outFile.write( "\n" )
for tNam in testNames[pkg]:
if results[tNam] == "succeeded":
nOK += 1
totalOK += 1
else:
totalFail += 1
if self.verbose :
self.outFile.write( indent*2 + tNam +' '+ results[tNam] + '\n')
if self.verbose: self.outFile.write( indent+ pkg+" : ")
self.outFile.write( indent + str(len(testNames[pkg]) ) + ' tests in total, OK:'+str(nOK)+ ' fail:'+str(len(testNames[pkg])-nOK) +'\n')
self.outFile.write( indent+str(nrTests)+" packages with tests ("+str(float(nrTests)/float(len(pkgTests.keys())) )+")\n")
self.outFile.write( indent+str(noTests)+" packages without tests ("+str(float(noTests)/float(len(pkgTests.keys())) )+")\n")
self.outFile.write( indent+"in total: tests OK : "+str(totalOK)+' tests FAIL : '+str(totalFail)+'\n')
return
# ================================================================================
def usage():
print "usage: "+ os.path.basename(sys.argv[0])+" --logFile <logFileName> [--verbose]\n"
return
if __name__ == "__main__" :
import getopt
options = sys.argv[1:]
try:
opts, args = getopt.getopt(options, 'hl:sv',
['help','logFile=','scram','verbose', 'outFile='])
except getopt.GetoptError:
usage()
sys.exit(-2)
logFile = None
chkScram = False
verb = False
outFile = None
for o, a in opts:
if o in ('-h', '--help'):
usage()
sys.exit()
if o in ('-l','--logFile',):
logFile = a
if o in ('-s','--scram',):
chkScram = True
if o in ('-v','--verbose',):
verb = True
if o in ('-l','--outFile',):
outFile = a
if not logFile:
usage()
sys.exit(-1)
tlc = TestLogChecker(outFileIn=outFile, verbIn=verb)
if chkScram:
tlc.checkScramWarnings(logFile, verb)
tlc.check(logFile)