forked from xyongcn/ucore_plus
-
Notifications
You must be signed in to change notification settings - Fork 10
/
formatter.py
executable file
·73 lines (65 loc) · 2.45 KB
/
formatter.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
#!/usr/bin/env python
import os, sys
import re
if len(sys.argv) < 5:
print 'Usage: formatter.py <section name> <result-dir> <repo> <tid>'
sys.exit()
tid_regex = re.compile('([a-z0-9]+)-.*')
arch_regex = re.compile('=+ ([\w]+) =+')
result_regex = re.compile('(<.*> )([\w]+)( *)(\[.*\])')
result_formats = {
'[ PASS ]':'line-ok',
'[! PASS !]':'line-warning',
'[ FAIL ]':'line-warning',
'[! FAIL !]':'line-error',
'[!BROKEN!]':'line-error'
}
section = sys.argv[1]
result_dir = sys.argv[2]
repo = sys.argv[3]
tid = sys.argv[4]
m = tid_regex.match(tid)
if not m:
print 'Invalid tid'
sys.exit()
commit = m.group(1)
if section == 'AutoTest':
sys.stdout.write('Legend:<br>')
sys.stdout.write('<span class="line-ok">[ PASS ]</span>:\tThe test terminates successfully with correct output<br>')
sys.stdout.write('<span class="line-warning">[! PASS !]</span>:\tThe test passes, but it is expected to fail in previous builds<br>')
sys.stdout.write('<span class="line-warning">[ FAIL ]</span>:\tSomething wrong happened in the test, but it is expected and has a corresponding issue on github<br>')
sys.stdout.write('<span class="line-error">[! FAIL !]</span>:\tThe test fails and it is not expected so<br>')
sys.stdout.write('<span class="line-error">[!BROKEN!]</span>:\tThe test is not executed normally, usually due to disk out of space or bugs in the test script<br><br>')
sys.stdout.write('<center>')
arch = ''
while True:
l = sys.stdin.readline()
if not l:
break
line = l.rstrip('\n')
m = result_regex.match(line)
if not m:
m = arch_regex.match(line)
if m:
arch = m.group(1)
sys.stdout.write(line + '<br>')
continue
testsuite = m.group(1)
testcase = m.group(2)
whitespaces = m.group(3)
result = m.group(4)
output = testsuite.replace('<', '<').replace('>', '>')
test_result = os.path.join(result_dir, repo, commit, arch, testcase + '.error')
if os.path.exists(test_result):
output += '<a href="/repo/' + repo + '/' + commit + '/' + arch + '/' + testcase + '">' + testcase + '</a>'
else:
output += testcase
output += whitespaces
if result_formats.has_key(result):
output += '<span class="' + result_formats[result] + '">' + result + '</span>'
else:
output += result
sys.stdout.write(output + '<br>')
if section == 'AutoTest':
sys.stdout.write('</center>')
sys.stdout.flush()