-
Notifications
You must be signed in to change notification settings - Fork 3
/
statusReport.py
executable file
·229 lines (205 loc) · 9.41 KB
/
statusReport.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
#!/usr/bin/env python
import sys
import os
import time
import glob
import smtplib
import curses
from config import moduleNames, goodModuleNames#, shifter, shifterEmail
from datetime import datetime
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
tbLine = ["TB:"]
idLine = ["module ID:"]
inputDir = os.path.expanduser('~') + "/allTestResults/"
tbs = []
inputFiles = []
cellLength = 18
for index, module in enumerate(moduleNames):
if module == "0":
continue
tbs.append(index)
testDirs = glob.glob(inputDir + "/" + module + "_*")
testDirs.sort(key=lambda x: os.path.getmtime(x))
testDir = testDirs[-1]
inputFiles.append(testDir)
for index, module in enumerate(goodModuleNames):
tbLine.append(str(tbs[index]))
idLine.append(module)
def moduleCrash(line):
# following keywords suggest test failure
isCrashed = False
if "not programmable; stop" in line or\
"empty results" in line or\
"Abort data processing" in line:
#"Event ID mismatch" in line:
isCrashed = True
return isCrashed
def checkEqual(list, str):
# check if all elements in `list` equal to `str`,
# blank elements are excluded.
allEqual = True
nEmpty = 0
for element in list:
if element == "" or element == " "*cellLength:
nEmpty += 1
continue
if element != str:
allEqual = False
if nEmpty != 4:
return allEqual
else:
return False
def str2time(str):
return datetime.strptime(str,'%H:%M:%S')
def endPrint():
screen.addstr(9,0,'#'*cellLength*(len(goodModuleNames)+1))
screen.addstr(11,0, "FULL TEST DONE!")
#screen.addstr(12,0, "An email of summary has been sent to shifter with address provided.")
screen.addstr(13,0, "Please wait for a few minutes while results are processing and saving,")
screen.addstr(14,0, "until you are prompt to hit `ENTER` on console.")
screen.addstr(16,0, "[statusReport] This is the end, my friEND.")
screen.addstr(17,0, "---------Hit any button to exit---------")
def sendEmail(receiver, body):
# Using mail.com because of easy registration; somehow unstable
fadd = "[email protected]"
tadd = receiver
msg = MIMEMultipart()
msg['From'] = fadd
msg['To'] = tadd
msg['Subject'] = "Module Tests Summary"
msg.attach(MIMEText(body, 'plain'))
s = smtplib.SMTP('smtp.mail.com', 587)
s.starttls()
s.login(fadd, "PixelUpgrade")
s.sendmail(fadd, [tadd], msg.as_string())
s.quit()
def summaryFormat(list, length):
line = ""
for entry in list:
line += str(entry) + ' '*(length-len(str(entry)))
return line
screen = curses.initscr()
curses.start_color()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) #DEFAULT
curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) #WARNING
curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK) #ERROR
curses.init_pair(4, curses.COLOR_MAGENTA, curses.COLOR_BLACK) #CRITICAL
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_RED) #CRASH
for index, x in enumerate(range(0,cellLength*len(goodModuleNames)+1,cellLength)):
screen.addstr(0, x, tbLine[index])
testStartTime = ['']*4
ivEndTime = ['']*4
ivDoneFlag = [0]*4
colorFlag = [[1 for x in range(len(goodModuleNames)+1)] for y in range(8)] #DEFAULT COLOR
try:
while 1:
testOutput = ["current test:"]
subtestOutput = ["current subtest:"]
timeOutput = ["time duration:"]
criticalOutput = ["# Criticals:"]
errorOutput = ["# pXar errors:"]
warningOutput = ["# Warnings:"]
for index, moduleDir in enumerate(inputFiles):
test = ""
subtest = ""
timePassed = ""
nErrors = 0
nCriticals = 0
nWarnings = 0
fpixTestLog = glob.glob(moduleDir + '/' + "000*/commander_*.log")
if fpixTestLog:
with open(fpixTestLog[0]) as data_file:
for line in data_file:
if line[0] != '[':
continue
## status counting
if "WARNING:" in line:
nWarnings += 1
colorFlag[7][index+1] = 2
if colorFlag[1][index+1] < 2:
colorFlag[1][index+1] = 2
if "ERROR:" in line:
nErrors += 1
colorFlag[6][index+1] = 3
if colorFlag[1][index+1] < 3:
colorFlag[1][index+1] = 3
if "CRITICAL:" in line:
nCriticals += 1
colorFlag[5][index+1] = 4
if colorFlag[1][index+1] < 4:
colorFlag[1][index+1] = 4
## Get current time & test duration
nowTime = datetime.now().time().strftime('%H:%M:%S')
if testStartTime[index]:
timePassed = str2time(nowTime) - str2time(testStartTime[index])
## Get test names & test start time
if not any(s in line for s in ('done','took','end','Factory','init','setParameter')):
if "doTest()" in line:
test = line.split(" ")[7].split('::')[0].replace("PixTest","")
testStartTime[index] = line.split(" ")[0].strip('[]')[:-4]
subtest = ''
if "PixTest" in line and "::" in line and "doTest()" not in line:
for entry in line.split(' '):
if '::' in entry:
subtest = entry.split('::')[1].replace("()","")
if ',' in subtest:
subtest = subtest[:-1]
testStartTime[index] = line.split(" ")[0].strip('[]')[:-4]
## crash counting
if moduleCrash(line):
if colorFlag[1][index+1] < 5:
colorFlag[1][index+1] = 5
msg = "Module "+idLine[index+1]+" failed test["\
+ test + "] subtest["+subtest+"]."
#sendEmail(shifterEmail, msg)
## Go to IV test
if "this is the end" in line:
ivTestLog = glob.glob(moduleDir + '/' + "001*/IV.log")
if ivTestLog:
test = "IVtest"
with open(ivTestLog[0]) as data_file1:
for line in data_file1:
if "Welcome" in line:
testStartTime[index] = line.split(" ")[0].strip('[]')[:-4]
nowTime = datetime.now().time().strftime('%H:%M:%S')
if not ivDoneFlag[index]:
ivEndTime[index] = nowTime
timePassed = str2time(nowTime)\
- str2time(testStartTime[index])
if "this is the end" in line:
test = "ALL done"
ivDoneFlag[index] = 1
if ivDoneFlag[index]:
timePassed = str2time(ivEndTime[index])\
- str2time(testStartTime[index])
testOutput.append(test+' '*(cellLength-len(test)))
subtestOutput.append(subtest+' '*(cellLength-len(subtest)))
timeOutput.append(str(timePassed))
criticalOutput.append(str(nCriticals))
errorOutput.append(str(nErrors))
warningOutput.append(str(nWarnings))
snapshot = [idLine, testOutput, subtestOutput, timeOutput, criticalOutput,\
errorOutput, warningOutput]
for y in range(1,8):
for index, x in enumerate(range(0,cellLength*len(goodModuleNames)+1,cellLength)):
screen.addstr(y, x, snapshot[y-1][index],\
curses.color_pair(colorFlag[y][index]))
screen.refresh()
time.sleep(3)
if checkEqual(testOutput[1:], "ALL done"+' '*(cellLength-len("ALL done"))):
content = "Hello " + "shifter"\
+ ",\n\nYour module tests are finished, summarized as bellow:\n\n"\
+ '\t' + summaryFormat(snapshot[0], cellLength) + '\n'\
+ '\t' + summaryFormat(snapshot[4], cellLength) + '\n'\
+ '\t' + summaryFormat(snapshot[5], cellLength) + '\n'\
+ '\t' + summaryFormat(snapshot[6], cellLength) + '\n'\
+ "\n\nThank you!"
#sendEmail(shifterEmail, content) #shifterEmail imported from config
endPrint()
break
screen.getch()
curses.endwin()
os.system("stty sane")
except KeyboardInterrupt:
os.system("stty sane")