forked from VLSIDA/OpenRAM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregress_daemon.py
More file actions
executable file
·248 lines (196 loc) · 6.35 KB
/
regress_daemon.py
File metadata and controls
executable file
·248 lines (196 loc) · 6.35 KB
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
#!/usr/bin/env python2.7
import sys
import os
import re
import smtplib
import sys
import os
import re
import unittest
import getpass
import datetime
USER = getpass.getuser()
TO_FIELD = "openram@soe.ucsc.edu"
#TO_FIELD = "mrg@ucsc.edu"
#TO_FIELD = "bchen12@ucsc.edu"
FROM_FIELD = USER+"@ucsc.edu"
LOCAL = "/soe/"+USER+"/unit_test"
sys.path.append(LOCAL+"/setup_scripts")
sys.path.append(LOCAL+"/compiler")
sys.path.append(LOCAL+"/compiler/tests")
TECH_NAME = "NONE"
#REPOS = "http://gforge.soe.ucsc.edu/svn/openram/trunk"
#REPOS = "http://svn.soe.ucsc.edu/svn/openram/trunk"
#REPOS = "gitosis@mada0.soe.ucsc.edu:openram.git"
REPOS = "git@github.com:mguthaus/OpenRAM.git"
MAIL = "/usr/sbin/sendmail"
# Add warnings/errors to email message.
# Abort if warnings or errors.
def checkout(rev):
"""
FOR SVN
"""
print "Checking out revision " + rev
# if it doesnt exist check it out
if not os.path.isdir(LOCAL):
cmd = "svn co -r" + rev + " " + REPOS + " " + LOCAL
if os.system(cmd):
print "Cannot check out repository: " + REPOS
sys.exit(-1)
# if it does exist just update to current revision
else:
try:
os.chdir(LOCAL)
except OSError:
print "Cannot find repository at " + LOCAL
sys.exit(-2)
cmd = "svn update -r" + rev
if os.system(cmd):
print "Cannot update repository: " + REPOS
sys.exit(-1)
print "Done."
def git_clone():
"""
FOR GIT
"""
if not os.path.isdir(LOCAL):
print "Cloning git repository at " + LOCAL
cmd = "git clone " + REPOS + " " + LOCAL
if os.system(cmd):
email_error("Cannot clone out repository at " + LOCAL)
else:
print "Pulling git repository at " + LOCAL
try:
os.chdir(LOCAL)
except OSError:
email_error("Cannot find repository at " + LOCAL)
cmd = "git pull"
if os.system(cmd):
email_error("Cannot update repository at " + LOCAL)
print "Done."
def remove_cached_files():
"""
removes cached .pyc files
"""
if os.path.isdir(LOCAL):
print "Removing Cached Files"
cmd = "find {0} -type f -iname \*.pyc -delete".format(LOCAL)
os.system(cmd)
print "Done."
def regress():
print "Running Regressions"
try:
os.chdir(LOCAL+"/compiler")
except OSError:
print "Cannot find repository at " + LOCAL
sys.exit(-2)
# get a list of all files in the python directory
files = os.listdir("tests")
# assume any file that ends in "test.py" in it is a regression test
nametest = re.compile("test\.py$", re.IGNORECASE)
tests = filter(nametest.search, files)
tests.sort()
# import all of the modules
filenameToModuleName = lambda f: os.path.splitext(f)[0]
moduleNames = map(filenameToModuleName, tests)
modules = map(__import__, moduleNames)
suite = unittest.TestSuite()
load = unittest.defaultTestLoader.loadTestsFromModule
import traceback
for m in modules:
try:
t=load(m)
suite.addTests(t)
except ImportError:
print traceback.format_exc()
#email_error(traceback.format_exc())
result=unittest.TextTestRunner(verbosity=2).run(suite)
print "Done."
return (tests,result)
def email_start(toField,subj):
p = os.popen("%s -t" % MAIL, 'w')
p.write("From: <"+FROM_FIELD+">\n")
p.write("Subject: {0} {1} ({2})\n".format(subj,datetime.datetime.now().replace(second=0,microsecond=0),TECH_NAME))
p.write("To: <"+toField+">\n") # replace with openram
p.write("\n\n")
p.write("{0} Pacific Time\n".format(datetime.datetime.now().replace(second=0,microsecond=0)))
p.write("\nTECHNOLOGY: {0}\n\n".format(TECH_NAME))
return p;
def email_failure(sysinfo):
type, value, tb = sysinfo
import traceback
p = email_start(TO_FIELD,"ERROR running regression")
p.write(str(value)+"\n")
traceback.print_tb(tb,None,p)
p.write("\nLAST 5 CHECK-INS:\n\n")
try:
os.chdir(LOCAL)
except OSError:
print "Cannot find repository at " + LOCAL
sys.exit(-2)
log=os.popen("git log -5").read()
p.write(log)
p.close()
def email_results(tests,results):
if results.wasSuccessful():
p = email_start(TO_FIELD,"PASSED regression result")
p.write("TESTS:\n")
for t in tests:
p.write(t + "\n")
p.write("\nREGRESSION TEST RESULTS:\n\n")
else:
p = email_start(TO_FIELD,"FAILED regression result")
p.write("TESTS:\n")
for t in tests:
p.write(t + "\n")
p.write("\nREGRESSION TEST RESULTS:\n\n")
for failure in results.failures:
p.write("FAIL: "+str(failure[0])+"\n")
p.write(" "+str(failure[1])+"\n")
p.write("----------------------------\n")
for error in results.errors:
p.write("ERROR: "+str(error[0])+"\n")
p.write(" "+str(error[1])+"\n")
p.write("----------------------------\n")
for skip in results.skipped:
p.write("SKIP:"+str(skip[0])+"\n")
p.write("----------------------------\n")
p.write("\nLAST 5 CHECK-INS:\n\n")
try:
os.chdir(LOCAL)
except OSError:
print "Cannot find repository at " + LOCAL
sys.exit(-2)
log=os.popen("git log -5").read()
p.write(log)
p.close()
def email_error(error_msg):
p = email_start(TO_FIELD,"FAILED to run regression")
p.write("UNABLE TO RUN REGRESSION TESTS\n")
p.write(error_msg)
p.write("\nLAST 5 CHECK-INS:\n")
try:
os.chdir(LOCAL)
except OSError:
print "Cannot find repository at " + LOCAL
sys.exit(-2)
log=os.popen("git log -5").read()
p.write(log)
p.close()
sys.exit(-3)
if __name__ == "__main__":
# We must clone the repository before parsing any arguments
remove_cached_files()
git_clone()
# now we can import the globals which sets up everything
import globals
globals.parse_args()
# Update our local copy to the correct tech name for the email
#globals TECH_NAME
TECH_NAME = globals.OPTS.tech_name
try:
(tests,results) = regress()
email_results(tests,results)
except:
email_failure(sys.exc_info())
sys.exit(0)