-
Notifications
You must be signed in to change notification settings - Fork 4
/
log_parser.py
297 lines (263 loc) · 11.3 KB
/
log_parser.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import urllib
import re
import datetime
import sys
import copy
import gzip
import tempfile
class LogParser():
# data format
# dataStructure = {
# "buildid": build,
# "product": product,
# "os": opsys,
# "testtype": testtype,
# "timestamp": str(date),
# "tests": [test1, test2, test3, ...]
# }
# testStructure = {
# testname: {
# "pass": passcount,
# "fail": failcount,
# "todo": todocount,
# "note": [note1, note2, note3, ...]
# }
#crashtest- line status: 'REFTEST TEST-*', parsing build step: 'parse crashtest log'
#reftest- line status: 'REFTEST TEST-*', parsing build step: 'parse reftest log'
#xpcshell- line status: 'TEST-*', parsing build step: 'parse xpcshell log'
reftestHarness = re.compile(r'REFTEST TEST-((FAIL)|(PASS)|(UNEXPECTED-FAIL)|(TIMEOUT)|(KNOWN-FAIL)|(UNEXPECTED-PASS))')
mochitestHarness = re.compile(r'INFO TEST-((FAIL)|(PASS)|(UNEXPECTED-FAIL)|(TIMEOUT)|(KNOWN-FAIL)|(UNEXPECTED-PASS))')
xpcshellHarness = re.compile(r'TEST-((FAIL)|(PASS)|(UNEXPECTED-FAIL)|(TIMEOUT)|(KNOWN-FAIL)|(UNEXPECTED-PASS))')
reReftest = ''
reJSReftest = ''
reCrashtest = ''
reXpcshell = ''
reChrome = ''
reBrowserChrome = ''
reMochitest = ''
reParsing = ''
logroot = ''
def __init__(self, product="mobile"):
if (product == "mobile"):
self.reReftest = "testtype=reftest"
self.reJSReftest = "testtype=jsreftest"
self.reCrashtest = "testtype=crashtest"
self.reXpcshell = "testtype=xpcshell"
self.reChrome = "testtype=chrome"
self.reBrowserChrome = "testtype=browserchrome"
self.reMochitest = "testtype=mochitest"
self.reParsing = re.compile(r'python maemkit-chunked.py')
self.logroot = "http://tinderbox.mozilla.org/Mobile/"
else:
self.reReftest = "=symbols reftest/tests/layout/reftests/reftest.list"
self.reJSReftest = "jsreftest/tests/jstests.list"
self.reCrashtest = "=symbols reftest/tests/testing/crashtest/crashtests.list"
self.reXpcshell = "manifest=xpcshell/tests/all-test-dirs.list"
self.reChrome = "--chrome"
self.reBrowserChrome = "--browser-chrome"
self.reMochitest = "--this-chunk="
self.reParsing = re.compile(r'python|bash')
self.logroot = "http://tinderbox.mozilla.org/Firefox-Unittest/"
def _getBuild(self, text):
#tinderbox: build: OS X 10.5.2 mozilla-central debug test everythingelse
#tinderbox: build: Linux mozilla-central opt test mochitests-4/5
#tinderbox: build: WINNT 5.2 mozilla-central debug test mochitests-1/5
label = r'tinderbox: build: '
regex = re.compile(label + r'.*')
result = regex.search(text)
if result != None:
return (result.group(0))[len(label):len(result.group(0))]
else:
return 'no-info'
# bug: BUILDID appears twice with different values in the log
def getBuildId(self, text):
label = r'BuildID='
regex = re.compile(label + r'.*')
result = regex.search(text)
if result != None:
return (result.group(0))[len(label):len(result.group(0))]
else:
return 'no-info'
def getProduct(self, text):
label = r'Name='
regex = re.compile(label + r'.*')
result = regex.search(text)
if result != None:
return (result.group(0))[len(label):len(result.group(0))]
else:
return 'no-info'
def getOs(self, text):
return (re.split(' +', self._getBuild(text)))[0]
def getTestType(self, text):
if (self.reReftest in text):
return "reftest"
elif (self.reJSReftest in text):
return "jsreftest"
elif (self.reCrashtest in text):
return "crashtest"
elif (self.reXpcshell in text):
return "xpcshell"
elif (self.reChrome in text):
return "chrome"
elif (self.reBrowserChrome in text):
return "browser-chrome"
elif (self.reMochitest in text):
return "mochitest"
return None
# cannot handle blank test file when exception occurred
# some notes appear on the line below:
# TEST-PASS | /media/mmc1/release/xpcshell/tests/test_uriloader_exthandler/unit/test_handlerService.js | [run_test : 147] true == true
# NEXT ERROR TEST-UNEXPECTED-FAIL | /media/mmc1/release/xpcshell/tests/test_uriloader_exthandler/unit/test_handlerService.js | 0 == 3 - See following stac$
# JS frame :: /media/mmc1/release/xpcshell/head.js :: do_throw :: line 181
# JS frame :: /media/mmc1/release/xpcshell/head.js :: do_check_eq :: line 211
# JS frame :: /media/mmc1/release/xpcshell/tests/test_uriloader_exthandler/unit/test_handlerService.js :: run_test :: line 154
# JS frame :: /media/mmc1/release/xpcshell/head.js :: _execute_test :: line 125
# JS frame :: -e :: <TOP_LEVEL> :: line 1
# TEST-INFO | (xpcshell/head.js) | exiting test
# <<<<<<<
# TEST-PASS | /media/mmc1/release/xpcshell/tests/test_uriloader_exthandler/unit/test_punycodeURIs.js | test passed
def getTestDetail(self, text):
line = text.split('|')
match = self.reStatus.search(line[0])
if (match):
outcome = match.group(0)
if (outcome.split(' ')[0] == "REFTEST"):
outcome = outcome.split(' ')[1]
if (outcome.split(' ')[0] == "INFO"):
outcome = outcome.split(' ')[1]
else:
return
pathname = line[1].strip()
pieces = pathname.replace('\\', '/').split('/')
if 'reftest' in pieces:
index = pieces.index('reftest') + 1
name = "/".join(pieces[index:])
elif 'jsreftest' in pieces:
index = pieces.index('jsreftest') + 1
name = "/".join(pieces[index:])
elif 'xpcshell' in pieces:
index = pieces.index('xpcshell') + 1
name = "/".join(pieces[index:])
elif 'chrome' in pieces:
index = pieces.index('content') + 2
name = "/".join(pieces[index:])
elif 'browser' in pieces:
index = pieces.index('browser') + 1
name = "/".join(pieces[index:])
else:
name = pathname
if len(self.tests) is 0 or ((name.strip() != "") and (self.tests[-1]['name'] != name)):
self.tests.append({'pass': 0, 'fail': 0, 'todo': 0, 'note': [], 'name':name})
t = self.tests[-1]
if outcome == 'TEST-PASS':
t['pass'] += 1
elif outcome == 'TEST-KNOWN-FAIL':
t['todo'] += 1
else:
t['fail'] += 1
def parseLog(self, tbox_id, callback=None):
retVal = []
doc = {}
contentAll = ''
url = self.logroot + tbox_id
try:
print 'GET '+url
filename = tempfile.mktemp()
# request = urllib2.Request(url)
# request.add_header('Accept-encoding', 'gzip')
# opener = urllib2.build_opener()
# opener.retreive(request, filename)
filename, headers = urllib.urlretrieve(url, filename)
f = gzip.GzipFile(fileobj=open(filename, 'r'))
contentAll = f.read()
f.close()
except IOError:
print "File not ready " + url
return []
doc = {
"build": self.getBuildId(contentAll),
"product": self.getProduct(contentAll),
"os": self.getOs(contentAll),
"testtype": self.getTestType(contentAll),
"tinderboxID": tbox_id}
self.reStatus = ''
buildSteps = contentAll.split("BuildStep ended")
current_step = ''
for current_step in buildSteps:
# if 'BuildStep ended' in line:
if self.reParsing.search(current_step):
doc["testtype"] = self.getTestType(current_step)
if (doc["testtype"] <> None):
if (doc["testtype"] == "reftest" or
doc["testtype"] == "jsreftest" or
doc["testtype"] == "crashtest"):
self.reStatus = self.reftestHarness
elif (doc["testtype"] == "xpcshell"):
self.reStatus = self.xpcshellHarness
elif (doc["testtype"] == "chrome" or
doc['testtype'] == "mochitest" or
doc['testtype'] == "browser-chrome"):
self.reStatus = self.mochitestHarness
if (self.reStatus <> ''):
if callback:
callback(self.parseBuildStep(doc, current_step))
else:
retVal.append(self.parseBuildStep(doc, current_step))
current_step = ''
# else:
# current_step += line
# line = f.readline()
if callback is None:
return retVal
def parseBuildStep(self, doc, step):
mydoc = {}
mydoc["build"] = doc["build"]
mydoc["product"] = doc["product"]
mydoc["os"] = doc["os"]
mydoc["tinderboxID"] = doc["tinderboxID"]
mydoc["testtype"] = doc["testtype"]
self.tests = []
contentByLine = step.split("\n")
for line in contentByLine:
if self.reStatus.search(line) != None:
self.getTestDetail(line)
mydoc["tests"] = self.tests
mydoc["timestamp"] = str(datetime.datetime.now())
for test in mydoc['tests']:
if test['fail'] is 0:
test['result'] = True
else:
test['result'] = False
mydoc['pass_count'] = sum([t.get('pass', 0) for t in mydoc['tests']], 0)
mydoc['fail_count'] = sum([t.get('fail', 0) for t in mydoc['tests']], 0)
#HACK: to only count 1 test/check for each test file
# mikeal: I don't know why we would want to do this
# if (mydoc["testtype"] == "xpcshell"):
# for test in mydoc['tests']:
# if (mydoc['tests'][test]['fail'] >= 1):
# mydoc['tests'][test] = dict({'pass': 0, 'fail': 1, 'todo': 0, 'note': []})
# else:
# mydoc['tests'][test] = dict({'pass': 1, 'fail': 0, 'todo': 0, 'note': []})
return mydoc
def main():
if (len(sys.argv) <= 1):
print "usage: " + sys.argv[0] + " [<product>] <tinderbox_id>"
print " <product> = mobile|firefox- mobile is default"
print "\nexample: " + sys.argv[0] + " mobile 1258685405.1258695209.5922.gz"
print "\nexample: " + sys.argv[0] + " firefox 1258743503.1258747166.27999.gz"
return
product = ''
tboxid = ''
if (len(sys.argv) == 2):
product = "mobile"
tboxid = sys.argv[1]
elif(len(sys.argv) == 3):
product = sys.argv[1]
tboxid = sys.argv[2]
else:
print "invalid # of args"
return
result = LogParser(product).parseLog(tboxid)
print result
if __name__ == "__main__":
result = main()