forked from tarantool/tarantool-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-run.py
executable file
·122 lines (107 loc) · 4.41 KB
/
test-run.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
#!/usr/bin/env python
import os
import sys
import shlex
import shutil
import subprocess
import time
from lib.tarantool_server import TarantoolServer
from pprint import pprint
def read_popen(cmd):
path = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
path.wait()
return path.stdout.read()
def read_popen_config(cmd):
cmd = os.environ.get('PHP_CONFIG', 'php-config') + ' ' + cmd
return read_popen(cmd)
def find_php_bin():
path = read_popen('which php').strip()
if (path.find('phpenv') != -1):
version = read_popen('phpenv global')
if (version.find('system') != -1):
return '/usr/bin/php'
return '~/.phpenv/versions/{0}/bin/php'.format(version.strip())
return path
def prepare_env(php_ini):
if os.path.isdir('var'):
shutil.rmtree('var')
if not os.path.isdir('var') and not os.path.exists('var'):
os.mkdir('var')
shutil.copy('test/shared/phpunit.xml', 'var')
test_dir_path = os.path.abspath(os.path.join(os.getcwd(), 'test'))
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
# shutil.copy('test/shared/tarantool.ini', 'var')
shutil.copy(php_ini, 'var')
shutil.copy('modules/tarantool.so', 'var')
def main():
path = os.path.dirname(sys.argv[0])
if not path:
path = '.'
os.chdir(path)
if '--prepare' in sys.argv:
prepare_env('test/shared/tarantool.ini')
exit(0)
srv = None
srv = TarantoolServer()
srv.script = 'test/shared/box.lua'
srv.start()
test_dir_path = os.path.abspath(os.path.join(os.getcwd(), 'test'))
test_cwd = os.path.dirname(srv.vardir)
test_lib_path = ""
try:
shutil.copy('test/shared/phpunit.xml', os.path.join(test_cwd, 'phpunit.xml'))
shutil.copy('modules/tarantool.so', test_cwd)
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
version = read_popen_config('--version').strip(' \n\t') + '.'
version1 = read_popen_config('--extension-dir').strip(' \n\t')
version += '\n' + ('With' if version1.find('non-zts') == -1 else 'Without') + ' ZTS'
version += '\n' + ('With' if version1.find('no-debug') == -1 else 'Without') + ' Debug'
print('Running against ' + version)
for php_ini in [
'test/shared/tarantool-1.ini',
'test/shared/tarantool-2.ini',
'test/shared/tarantool-3.ini'
]:
cmd = ''
shutil.copy(php_ini, os.path.join(test_cwd, 'tarantool.ini'))
if '--flags' in sys.argv:
os.environ['ZEND_DONT_UNLOAD_MODULES'] = '1'
os.environ['USE_ZEND_ALLOC'] = '0'
os.environ['MALLOC_CHECK_'] = '1'
if '--valgrind' in sys.argv:
cmd = cmd + 'valgrind --leak-check=full --log-file='
cmd = cmd + os.path.basename(php_ini).split('.')[0] + '.out '
cmd = cmd + '--suppressions=test/shared/valgrind.sup '
cmd = cmd + '--keep-stacktraces=alloc-and-free'
cmd = cmd + ' --freelist-vol=2000000000 '
cmd = cmd + '--malloc-fill=0 --free-fill=0 '
cmd = cmd + '--num-callers=50 ' + find_php_bin()
cmd = cmd + ' -c tarantool.ini {0}'.format(test_lib_path)
elif '--gdb' in sys.argv:
cmd = cmd + 'gdb {0} --ex '.format(find_php_bin())
cmd = cmd + '"set args -c tarantool.ini {0}"'.format(test_lib_path)
elif '--lldb' in sys.argv:
cmd = cmd + 'lldb -- {0} -c tarantool.ini {1}'.format(find_php_bin(), test_lib_path)
elif '--strace' in sys.argv:
cmd = cmd + 'strace ' + find_php_bin()
cmd = cmd + ' -c tarantool.ini {0}'.format(test_lib_path)
else:
print find_php_bin()
cmd = '{0} -c tarantool.ini {1}'.format(find_php_bin(), test_lib_path)
print cmd
print('Running "%s" with "%s"' % (cmd, php_ini))
proc = subprocess.Popen(cmd, shell=True, cwd=test_cwd)
rv = proc.wait()
if rv != 0:
return -1
finally:
a = [
os.path.join(test_cwd, 'tarantool.ini'),
os.path.join(test_cwd, 'phpunit.xml'),
os.path.join(test_cwd, 'tarantool.so'),
]
for elem in a:
if os.path.exists(elem):
os.remove(elem)
return 0
exit(main())