IXWebSocket/test/run.py

120 lines
2.8 KiB
Python
Raw Normal View History

2019-01-05 02:28:13 +01:00
import os
import platform
import shutil
import subprocess
import threading
class Command(object):
"""Run system commands with timeout
From http://www.bo-yang.net/2016/12/01/python-run-command-with-timeout
Python3 might have a builtin way to do that.
"""
def __init__(self, cmd):
self.cmd = cmd
self.process = None
def run_command(self, capture = False):
self.process = subprocess.Popen(self.cmd, shell=True)
self.process.communicate()
def run(self, timeout = 5 * 60):
'''5 minutes default timeout'''
thread = threading.Thread(target=self.run_command, args=())
thread.start()
thread.join(timeout)
if thread.is_alive():
2019-03-21 21:50:59 +01:00
print('Command timeout, kill it: ' + self.cmd)
self.process.terminate()
thread.join()
return False, 255
else:
return True, self.process.returncode
2019-01-05 02:28:13 +01:00
osName = platform.system()
print('os name = {}'.format(osName))
root = os.path.dirname(os.path.realpath(__file__))
2019-03-14 22:37:43 +01:00
buildDir = os.path.join(root, 'build', osName)
2019-01-05 02:28:13 +01:00
if not os.path.exists(buildDir):
2019-03-14 22:37:43 +01:00
os.makedirs(buildDir)
2019-01-05 02:28:13 +01:00
os.chdir(buildDir)
if osName == 'Windows':
generator = '-G"NMake Makefiles"'
make = 'nmake'
testBinary ='ixwebsocket_unittest.exe'
else:
generator = ''
2019-01-24 21:42:49 +01:00
make = 'make -j6'
testBinary ='./ixwebsocket_unittest'
2019-01-05 02:28:13 +01:00
2019-01-07 03:54:16 +01:00
sanitizersFlags = {
'asan': '-DSANITIZE_ADDRESS=On',
'ubsan': '-DSANITIZE_UNDEFINED=On',
'tsan': '-DSANITIZE_THREAD=On',
'none': ''
}
sanitizer = 'tsan'
if osName == 'Linux':
2019-01-27 05:57:48 +01:00
sanitizer = 'none'
2019-01-07 03:54:16 +01:00
sanitizerFlags = sanitizersFlags[sanitizer]
# if osName == 'Windows':
# os.environ['CC'] = 'clang-cl'
# os.environ['CXX'] = 'clang-cl'
2019-03-14 22:37:43 +01:00
cmakeCmd = 'cmake -DCMAKE_BUILD_TYPE=Debug {} {} ../..'.format(generator, sanitizerFlags)
2019-01-07 03:54:16 +01:00
print(cmakeCmd)
ret = os.system(cmakeCmd)
assert ret == 0, 'CMake failed, exiting'
2019-01-05 02:28:13 +01:00
ret = os.system(make)
assert ret == 0, 'Make failed, exiting'
def findFiles(prefix):
'''Find all files under a given directory'''
paths = []
for root, _, files in os.walk(prefix):
for path in files:
fullPath = os.path.join(root, path)
if os.path.islink(fullPath):
continue
paths.append(fullPath)
return paths
2019-01-05 20:42:25 +01:00
#for path in findFiles('.'):
# print(path)
2019-01-05 02:28:13 +01:00
2019-01-05 20:42:25 +01:00
# We need to copy the zlib DLL in the current work directory
2019-01-05 02:28:13 +01:00
shutil.copy(os.path.join(
2019-03-14 22:37:43 +01:00
'..',
2019-01-05 02:28:13 +01:00
'..',
'..',
'third_party',
'ZLIB-Windows',
'zlib-1.2.11_deploy_v140',
'release_dynamic',
'x64',
'bin',
'zlib.dll'), '.')
2019-03-15 02:37:38 +01:00
# lldb = "lldb --batch -o 'run' -k 'thread backtrace all' -k 'quit 1'"
lldb = "" # Disabled for now
testCommand = '{} {} {}'.format(lldb, testBinary, os.getenv('TEST', ''))
command = Command(testCommand)
timedout, ret = command.run()
2019-01-06 01:30:22 +01:00
assert ret == 0, 'Test command failed'