forked from maleadt/gpuocelot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·306 lines (235 loc) · 8.93 KB
/
build.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
297
298
299
300
301
302
303
304
305
#!/usr/bin/env python
################################################################################
# \file build.py
# \author Gregory Diamos <[email protected]>
# \date Thursday March 29, 2012
# \brief The top level Ocelot build script to direct scons builds
# and run unit tests
################################################################################
import os
import re
import subprocess
import time
from optparse import OptionParser
import sys
sys.path.append(os.path.abspath('ocelot/scripts'))
from create_config import ConfigFile
################################################################################
## Build Ocelot
def build(options):
command = "scons -Q"
if options.clean:
command += " -c"
if options.debug:
command += " mode=debug"
if options.no_werr:
command += " Werror=false"
if options.no_llvm:
command += " enable_llvm=false"
if options.build_deb:
if not options.install:
print "Install must be set for a debian build, setting it"
options.install = True
# Should probably change this to not use a specific
# target but instead use defaults for the same reason
# as install described below.
command += " debian"
if options.install:
command += " install=true"
if options.install_prefix:
command += " install_path=" + options.install_prefix
command += " " + options.build_target
if options.test_level != "none":
if options.install:
command += " tests"
else:
if options.debug:
command += " .debug_build/tests"
else:
command += " .release_build/tests"
command += " test_level=" + options.test_level
command += " -j" + options.threads
# Run SCons
print command
scons = subprocess.Popen(command, shell=True)
return scons.wait() == 0
################################################################################
################################################################################
## Safe file remove
def safeRemove(path):
if os.path.isfile(path):
os.remove(path)
################################################################################
################################################################################
## Create a configure.ocelot file
def createConfig(directory, config):
filePath = os.path.join(directory, 'configure.ocelot')
safeRemove(filePath)
openFile = open(filePath, 'w')
config.write(openFile)
################################################################################
################################################################################
## Run Standard Tests
def runStandardTests(options, directory, name, config):
if not directory in options.test_lists.replace(' ', '').split(','):
return True
directory = os.path.join("tests", directory)
createConfig(directory, config)
# Run Cuda 2.2 tests
command = "cd " + directory + "; hydrazine/python/RunRegression.py -v"
if options.debug:
command += " -p ../../.debug_build/" + directory
else:
command += " -p ../../.release_build/" + directory
command += ' -t regression/tests.txt -l regression/tests.log; cd ../..'
print '\nRunning ' + name + ' Unit Tests...'
status = os.popen(command).read()
print status
# Check for any failing/missing tests
if re.search('Failing tests|Non-Existent tests', status):
return False
return True
################################################################################
################################################################################
## Get configurations
def getConfigs(options):
configs = []
stripped = options.devices.replace(' ', '')
stripped = stripped.replace('[', '')
stripped = stripped.replace(']', '')
for device in stripped.split(','):
config = ConfigFile()
config.executive.devices = "[\"" + device + "\"]"
configs.append(config)
return configs
################################################################################
################################################################################
## Run Unit Tests
def runUnitTests(options, buildSucceeded):
if options.clean:
return False
if options.test_level == 'none':
return False
if not buildSucceeded:
print "Build failed..."
return False
else:
print "Build succeeded..."
for config in getConfigs(options):
# run Ocelot tests
if 'unit' in options.test_lists.replace(' ', '').split(','):
createConfig('ocelot', config)
command = "cd ocelot; hydrazine/python/RunRegression.py -v"
if options.debug:
command += " -p ../.debug_build/ocelot"
prefix = "debug"
else:
command += " -p ../.release_build/ocelot"
prefix = "release"
if options.test_level == 'basic':
log = "regression/" + prefix + "-basic.log"
command += " -t regression/basic.level"
elif options.test_level == 'full':
log = "regression/" + prefix + "-full.log"
command += " -t regression/full.level"
command += " -l " + log + "; cd .."
print '\nRunning Ocelot Unit Tests...'
status = os.popen(command).read()
print status
# Check for any failing/missing tests
if re.search('Failing tests|Non-Existent tests', status):
return False
elif options.test_level == 'basic':
return True
# Run standard tests
if not runStandardTests(options, 'cuda2.2', 'CUDA SDK 2.2', config):
return False
if not runStandardTests(options, 'cuda2.3', 'CUDA SDK 2.3', config):
return False
if not runStandardTests(options, 'cuda3.2', 'CUDA SDK 3.2', config):
return False
if not runStandardTests(options, 'parboil', 'Parboil', config):
return False
if not runStandardTests(options, 'cuda4.1sdk', 'CUDA SDK 4.1', config):
return False
return True
################################################################################
################################################################################
## Submit to SVN
def submit(options, testPassed):
if not options.submit:
return
if len(options.message) == 0:
print "Log message not specified (use -m)"
return
if not testPassed:
# The tests may have failed or may have not been run
# because '-c' or '-t none' was specified.
print "Regression tests failed or not run, commit prohibited."
return
command = "svn commit -m \"" + options.message + "\""
os.system(command)
################################################################################
################################################################################
## Main
def main():
defaultInstallPath = '/usr/local'
if 'OCELOT_INSTALL_PATH' in os.environ:
defaultInstallPath = os.environ['OCELOT_INSTALL_PATH']
parser = OptionParser()
parser.add_option( "-c", "--clean", \
default = False, action = "store_true" )
parser.add_option( "-d", "--debug", \
default = False, action = "store_true", \
help = "build Ocelot in debug mode." )
parser.add_option( "-t", "--test_level", default = "none", \
help = "set the test level (none, basic, full)" )
parser.add_option( "-j", "--threads", default = "1" )
parser.add_option( "-s", "--submit", \
default = False, action = "store_true" )
parser.add_option( "-i", "--install", \
default = False, action = "store_true", help = "Install ocelot." )
parser.add_option( "-b", "--build_target", \
default = "ocelot", help = "build a specific target." )
parser.add_option( "-w", "--no_werr", \
default = False, action = "store_true",
help = "don't turn warnings into errors." )
parser.add_option( "-p", "--install_prefix", \
default = defaultInstallPath,
help = "The base path to install ocelot in." )
parser.add_option( "--build_deb", \
default = False, action = "store_true",
help = "Build a .deb package of Ocelot." )
parser.add_option( "--test_lists", \
default = "unit, cuda2.2, cuda2.3, parboil",
help = "Comma separated list of tests." )
parser.add_option( "--no_llvm", \
default = False, action = "store_true", help = "Disable llvm support." )
parser.add_option( "-m", "--message", default = "", \
help = "The message describing the changes being committed." )
parser.add_option( "-D", "--devices", default = "[emulated]", \
help = "A list of Ocelot devices to test [emulated, nvidia, llvm, amd]." )
( options, arguments ) = parser.parse_args()
if options.submit:
if options.test_level != 'full':
print "Full test level required for a submit."
options.test_level = 'full'
options.build_target = 'tests ocelot'
# Do the build
buildSucceeded = build(options)
# Run unit tests
testsPassed = runUnitTests(options, buildSucceeded)
# Submit if the tests pass
submit(options, testsPassed)
# No need to print suceeded as already done in runUnitTests. A
# sucessful clean is also success.
if buildSucceeded and (options.clean or (options.test_level == 'none') or testsPassed):
sys.exit(0)
else:
sys.exit(1)
################################################################################
################################################################################
## Guard Main
if __name__ == "__main__":
main()
################################################################################