-
Notifications
You must be signed in to change notification settings - Fork 40
/
AllTests.py
389 lines (369 loc) · 13.4 KB
/
AllTests.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import os
import sys
import subprocess
import time
import shutil
import signal
import platform
def objPath():
plat = 'Posix'
if os.name == 'nt':
plat = 'Windows'
elif platform.system() == 'Darwin':
if gMac64 == 1:
plat = 'Mac-x64'
elif giOsArm64 == 1:
plat = 'iOs-arm64'
elif giOsx64 == 1:
plat = 'iOs-x64'
variant = 'Release'
if gDebugBuild == 1:
variant = 'Debug'
path = os.path.join('Build', 'Obj', plat, variant)
return path
def buildArgs():
buildArgs = ''
if gDebugBuild == 1:
buildArgs += ' debug=1'
if gMac64 == 1:
buildArgs += ' mac-64=1'
if giOsArm64 == 1:
buildArgs += ' iOs-arm64=1'
if giOsx64 == 1:
buildArgs += ' iOs-x64=1'
if gAndroid == 1:
buildArgs += ' Android-anycpu=1'
if gCore == 1 or gQnap == 1:
buildArgs += ' platform=' + gPlatform
if gNativeBuildsOnly == 1:
buildArgs += ' native_only=yes'
return buildArgs
def build(aTarget, aParallel=False):
buildCmd = 'make '
if aParallel:
buildCmd += '-j4 '
if os.name == 'nt':
buildCmd = 'nmake -s -f OhNet.mak '
buildCmd += aTarget
if platform.system() == 'Darwin':
# No C++11 support on standard Mac build slaves
buildCmd += ' nocpp11=yes'
if 'CS_PLATFORM' in os.environ:
buildCmd += ' csplatform=' + os.environ['CS_PLATFORM']
buildCmd += buildArgs()
ret = os.system(buildCmd)
if (0 != ret):
print('\nBuild for ' + aTarget + ' failed, aborting')
sys.exit(1)
def runBuilds():
if gIncremental == 0:
cleanCmd = ''
if os.name == 'nt':
cleanCmd = 'nmake /s /f OhNet.mak clean'
else:
cleanCmd = 'make clean'
cleanCmd += buildArgs()
os.system(cleanCmd)
if gParallel:
build('copy_build_includes')
if gCore == 1:
build('ohNet TestFramework', gParallel)
else:
build('all', gParallel)
if (gRunJavaTests == 1):
build('ohNetJavaAll', False)
print('\nBuilds complete')
def runTests():
testsToRun = list(gAllTests)
if gFullTests != 1:
# Suppress non-quick tests
testsToRun = [test for test in testsToRun if test.quick]
if gNativeTestsOnly == 1:
# Suppress non-native tests
testsToRun = [test for test in testsToRun if test.native]
for test in testsToRun:
print('\nTest: ' + test.name)
cmdLine = test.args
cmdLine.insert(0, test.Path())
print("Running: %s" % cmdLine)
ret = subprocess.call(cmdLine)
if ret != 0:
print('\nTest ' + test.name + ' failed, aborting')
sys.exit(1)
if (gRunJavaTests == 1):
testsToRun = list(gJavaTests)
if gFullTests != 1:
# Suppress non-quick tests
testsToRun = [test for test in testsToRun if test.quick]
for test in testsToRun:
print ('\nTest: ' + test.name)
cmdLine = []
print("AllTests.py JAVA_HOME: ", os.environ['JAVA_HOME'])
cmdLine.append(os.path.join(os.environ['JAVA_HOME'], 'bin', 'java'))
cmdLine.append('-Djava.library.path=' + objPath())
cmdLine.append('-classpath')
cmdLine.append(objPath())
cmdLine.append('-enableassertions')
cmdLine.append(test.name)
ret = subprocess.call(cmdLine)
if ret != 0:
print('\nTest ' + test.name + ' failed, aborting')
sys.exit(1)
def runTestsValgrind():
# clear any old output files
outputDir = 'vgout'
if os.path.exists(outputDir):
shutil.rmtree(outputDir)
os.mkdir(outputDir)
failed = []
testsToRun = [test for test in gAllTests if test.quick and test.native]
if gFullTests == 1:
testsToRun = [test for test in gAllTests if test.native]
os.system('export GLIBCXX_FORCE_NEW')
for test in testsToRun:
print('\nTest: ' + test.name)
cmdLine = []
cmdLine.append('valgrind')
cmdLine.append('--leak-check=yes')
cmdLine.append('--suppressions=ValgrindSuppressions.txt')
cmdLine.append('--xml=yes')
cmdLine.append('--xml-file=' + os.path.join(outputDir, test.name) + '.xml')
cmdLine.append(test.Path())
for arg in test.args:
cmdLine.append(arg)
ret = subprocess.call(cmdLine)
if ret != 0:
failed.append(test.name)
if len(failed) > 0:
print('\nERROR, the following tests failed:')
for fail in failed:
print('\t' + fail)
sys.exit(-1)
def runTestsHelgrind():
# clear any old output files
outputDir = 'hgout'
if os.path.exists(outputDir):
shutil.rmtree(outputDir)
os.mkdir(outputDir)
failed = []
testsToRun = [test for test in gAllTests if test.quick and test.native]
if gFullTests == 1:
testsToRun = [test for test in gAllTests if test.native]
os.system('export GLIBCXX_FORCE_NEW')
for test in testsToRun:
print('\nTest: ' + test.name)
cmdLine = []
cmdLine.append('valgrind')
cmdLine.append('--tool=helgrind')
cmdLine.append('--suppressions=HelgrindSuppressions.txt')
cmdLine.append('--xml=yes')
cmdLine.append('--xml-file=' + os.path.join(outputDir, test.name) + '.xml')
cmdLine.append(test.Path())
for arg in test.args:
cmdLine.append(arg)
ret = subprocess.call(cmdLine)
if ret != 0:
failed.append(test.name)
if len(failed) > 0:
print('\nERROR, the following tests failed:')
for fail in failed:
print('\t', fail)
sys.exit(-1)
gStartTime = time.strftime('%H:%M:%S')
gBuildsCompleteTime = ''
gBuildOnly = 0
gFullTests = 0
gIncremental = 0
gNativeTestsOnly = 0
gNativeBuildsOnly = 0
gSilent = 0
gTestsOnly = 0
gValgrind = 0
gHelgrind = 0
gRunJavaTests = 0
gJsTests = 0
gDebugBuild = 0
gMac64 = 0
giOsArm64 = 0
giOsx64 = 0
gAndroid = 0
gQnap = 0
try:
gPlatform = os.environ['PLATFORM']
except KeyError:
gPlatform = None
gCore = 0
gParallel = False
for arg in sys.argv[1:]:
if arg == '-b' or arg == '--buildonly':
gBuildOnly = 1
elif arg == '--debug':
gDebugBuild = 1
elif arg == '-f' or arg == '--full':
gFullTests = 1
elif arg == '-i' or arg == '--incremental':
gIncremental = 1
elif arg == '--java':
gRunJavaTests = 1
elif arg == '--js':
gJsTests = 1
elif arg == '-n' or arg == '--native-tests':
gNativeTestsOnly = 1
elif arg == '--native-builds':
gNativeBuildsOnly = 1
elif arg == '-s' or arg == '--silent':
gSilent = 1
elif arg == '-t' or arg == '--testsonly':
gTestsOnly = 1
elif arg == '-vg' or arg == '--valgrind':
gValgrind = 1
if os.name == 'nt':
print('ERROR - valgrind is only supported on linux')
sys.exit(1)
elif arg == '-hg' or arg == '--helgrind':
gHelgrind = 1
if os.name == 'nt':
print('ERROR - helgrind is only supported on linux')
sys.exit(1)
elif arg == '--mac-64':
gMac64 = 1
if platform.system() != 'Darwin':
print('ERROR - --mac-64 only applicable on Darwin')
sys.exit(1)
elif arg == '--iOs-arm64':
giOsArm64 = 1
if platform.system() != 'Darwin':
print('ERROR - --iOs-arm64 only applicable on Darwin')
sys.exit(1)
elif arg == '--iOs-x64':
giOsx64 = 1
if platform.system() != 'Darwin':
print('ERROR - --iOs-x64 only applicable on Darwin')
sys.exit(1)
elif arg == '--parallel':
gParallel = True
elif arg == '--core':
gCore = 1
elif arg == '--Android-anycpu':
gAndroid = 1
elif arg == '--qnap':
gQnap = 1;
else:
print('Unrecognised argument - ', arg)
sys.exit(1)
os.environ["ABORT_ON_FAILURE"] = "1"
if gSilent != 0:
os.environ["NO_ERROR_DIALOGS"] = "1"
class TestCase(object):
def __init__(self, name, args, quick=False, native=True):
self.name = name
self.args = args
self.quick = quick
self.native = native
def Path(self):
path = objPath() + '/' + self.name
if os.name == 'nt':
path += '.exe'
elif not self.native:
os.environ['LD_LIBRARY_PATH'] = objPath()
#NOTE: newer dotnet SDKs create self-contained executables without a prefix
else:
path += '.elf'
return path
gAllTests = [ TestCase('TestBuffer', [], True)
,TestCase('TestStream', [], True)
,TestCase('TestThread', ['--full'], False)
,TestCase('TestFunctorGeneric', [], True)
,TestCase('TestFifo', [], True)
,TestCase('TestFile', [], True)
,TestCase('TestQueue', [], True)
,TestCase('TestTextUtils', [], True)
,TestCase('TestNetwork', [], True)
,TestCase('TestTime', [], True)
#,TestCase('TestTimer', [])
,TestCase('TestTimerMock', [], True)
#,TestCase('TestHttpReader', [], True)
,TestCase('TestSsdpMListen', ['-d', '10'], True)
,TestCase('TestXmlParser', [], True)
,TestCase('TestSsdpUListen', ['-t', 'av.openhome.org:service:Radio:1'], True)
,TestCase('TestDeviceList', ['-t', 'av.openhome.org:service:Radio:1', '-f'], True)
,TestCase('TestDeviceListStd', ['-t', 'av.openhome.org:service:Radio:1', '-f'], True)
,TestCase('TestDeviceListC', ['-t', 'av.openhome.org:service:Radio:1', '-f'], True)
,TestCase('TestInvocation', [])
,TestCase('TestInvocationStd', [])
,TestCase('TestSubscription', [])
,TestCase('TestProxyC', [])
,TestCase('TestDviDiscovery', ['-l'], True)
,TestCase('TestDviDeviceList', ['-l'], True)
,TestCase('TestDvInvocation', ['-l'], True)
,TestCase('TestDvSubscription', ['-l'], True)
,TestCase('TestDvDeviceStd', ['-l'], True)
,TestCase('TestDvDeviceC', [], True)
#,TestCase('TestCpDeviceDv', [], True)
#,TestCase('TestCpDeviceDvStd', [], True)
#,TestCase('TestCpDeviceDvC', [], True)
,TestCase('TestDvLpec', [], True)
,TestCase('TestProxyCs', [], False, False)
,TestCase('TestDvDeviceCs', [], True, False)
,TestCase('TestCpDeviceDvCs', [], True, False)
]
gJavaTests = [ TestCase('org.openhome.net.controlpoint.tests.TestProxy', [], False, False)
,TestCase('org.openhome.net.controlpoint.tests.TestCpDeviceDv', [], True, False)
,TestCase('org.openhome.net.device.tests.TestDvDevice', [], True, False)
]
class js_test:
def write_dummy_results(self):
if not os.path.exists("xout"):
os.mkdir("xout")
# write dummy XML that gets re-written by real XML if browser connects to node properly
dummy_xml_read = open("OpenHome/Net/Bindings/Js/ControlPoint/Tests/dummyxml.xml", 'r')
dummy_xml_write = open("xout/ProxyJsTest.xml", 'w')
dummy_xml_write.writelines(dummy_xml_read)
dummy_xml_write.close()
def get_env(self,objpath):
self.objpath = objpath
program_files = os.environ.get('ProgramFiles')
self.browser_location = os.path.join(program_files, 'Safari\\Safari.exe')
self.test_dir = os.path.join(os.getcwd(), 'Build\\Include\\OpenHome\\Net\\Private\\Js\\Tests')
def find_device(self):
self.test_testbasic = subprocess.Popen([os.path.join(self.objpath, 'TestDvTestBasic.exe'), '-l', '-c', self.test_dir])
time.sleep(5)
test_devfinder = subprocess.Popen([os.path.join(self.objpath, 'TestDeviceFinder.exe'), '-l', '-s', 'openhome.org:service:TestBasic:1'],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.launch_url = test_devfinder.communicate()[1].rstrip()
print('found device at ', self.launch_url)
def run_browser(self):
subprocess.call(["%s" %(self.browser_location), "%s" %(self.launch_url)])
self.test_testbasic.terminate()
def run_browser_jenkins(self):
subprocess.call(["psexec", "-i", "2", "-u", "hudson-zapp", "-p", "temp123", "%s" %(self.browser_location), "%s" %(self.launch_url)])
self.test_testbasic.terminate()
def JsTests():
objpath = objPath()
do_jstest = js_test()
do_jstest.write_dummy_results()
do_jstest.get_env(objpath)
do_jstest.find_device()
# PsExec allows us to view JS tests under Jenkins
# ...it also seems to cause most of the problems around JS tests so try ignoring it for now
do_jstest.run_browser()
#if os.getenv('JENKINS_COOKIE') is None:
# do_jstest.run_browser()
#else:
# do_jstest.run_browser_jenkins()
if gTestsOnly == 0:
runBuilds()
gBuildsCompleteTime = time.strftime('%H:%M:%S')
if gBuildOnly == 0:
if gValgrind == 1:
runTestsValgrind()
if gHelgrind == 1:
runTestsHelgrind()
if gValgrind == 0 and gHelgrind == 0:
runTests()
# JS tests currently disabled as they are not Python3 compatible
#if gJsTests == 1:
# JsTests()
print('\nFinished. All tests passed')
print('Start time: ', gStartTime)
print('Builds complete: ', gBuildsCompleteTime)
print('End time: ', time.strftime('%H:%M:%S'))