forked from emscripten-core/emsdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·204 lines (152 loc) · 6.57 KB
/
test.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
#!/usr/bin/env python
import json
import os
import shutil
import subprocess
import sys
import tempfile
# Utilities
def listify(x):
if type(x) == list or type(x) == tuple:
return x
return [x]
def check_call(cmd, **args):
if type(cmd) != list:
cmd = cmd.split()
print('running: %s' % cmd)
subprocess.check_call(cmd, **args)
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None):
cmd = cmd.split(' ')
print('running: %s' % cmd)
stdout = subprocess.check_output(cmd, stderr=stderr)
if expected:
for x in listify(expected):
assert x in stdout, 'call had the right output: ' + stdout + '\n[[[' + x + ']]]'
if unexpected:
for x in listify(unexpected):
assert x not in stdout, 'call had the wrong output: ' + stdout + '\n[[[' + x + ']]]'
def failing_call_with_output(cmd, expected):
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode, 'call must have failed'
assert expected in stdout, 'call did not have the right output'
def hack_emsdk(marker, replacement):
src = open('emsdk.py').read()
assert marker in src
src = src.replace(marker, replacement)
name = '__test_emsdk'
open(name, 'w').write(src)
return name
# Set up
open('hello_world.cpp', 'w').write('int main() {}')
TAGS = json.loads(open('emscripten-releases-tags.txt').read())
LIBC = os.path.expanduser('~/.emscripten_cache/wasm-obj/libc.a')
# Tests
print('test .emscripten contents (latest was installed/activated in test.sh)')
assert 'fastcomp' in open(os.path.expanduser('~/.emscripten')).read()
assert 'upstream' not in open(os.path.expanduser('~/.emscripten')).read()
print('building proper system libraries')
def test_lib_building(emcc, use_asmjs_optimizer):
def test_build(args, expected=None, unexpected=None):
checked_call_with_output(emcc + ' hello_world.cpp' + args,
expected=expected,
unexpected=unexpected,
stderr=subprocess.STDOUT)
# by default we ship libc, struct_info, and the asm.js optimizer, as they
# are important for various reasons (libc takes a long time to build;
# struct_info is a bootstrap product so if the user's setup is broken it's
# confusing; the asm.js optimizer is a native application so it needs a
# working native local build environment). otherwise we don't ship every
# single lib, so some building is expected on first run.
unexpected_system_libs = ['generating system library: libc.',
'generating system asset: optimizer']
if use_asmjs_optimizer:
unexpected_system_libs += ['generating system asset: generated_struct_info.json']
first_time_system_libs = ['generating system library: libdlmalloc.']
test_build('', expected=first_time_system_libs,
unexpected=unexpected_system_libs)
test_build(' -O2', unexpected=unexpected_system_libs + first_time_system_libs)
test_build(' -s WASM=0', unexpected=unexpected_system_libs + first_time_system_libs)
test_build(' -O2 -s WASM=0', unexpected=unexpected_system_libs + first_time_system_libs)
def run_emsdk(cmd):
if type(cmd) != list:
cmd = cmd.split()
check_call([emsdk] + cmd)
WINDOWS = sys.platform.startswith('win')
MACOS = sys.platform == 'darwin'
upstream_emcc = os.path.join('upstream', 'emscripten', 'emcc')
fastcomp_emcc = os.path.join('fastcomp', 'emscripten', 'emcc')
emsdk = './emsdk'
if WINDOWS:
upstream_emcc += '.bat'
fastcomp_emcc += '.bat'
emsdk = 'emsdk.bat'
else:
emsdk = './emsdk'
test_lib_building(fastcomp_emcc, use_asmjs_optimizer=True)
print('update')
run_emsdk('update-tags')
print('test latest-releases-upstream')
run_emsdk('install latest-upstream')
run_emsdk('activate latest-upstream')
test_lib_building(upstream_emcc, use_asmjs_optimizer=False)
assert open(os.path.expanduser('~/.emscripten')).read().count('LLVM_ROOT') == 1
assert 'upstream' in open(os.path.expanduser('~/.emscripten')).read()
assert 'fastcomp' not in open(os.path.expanduser('~/.emscripten')).read()
print('verify version')
checked_call_with_output(upstream_emcc + ' -v', TAGS['latest'], stderr=subprocess.STDOUT)
print('clear cache')
check_call(upstream_emcc + ' --clear-cache')
assert not os.path.exists(LIBC)
print('test tot-upstream')
run_emsdk('install tot-upstream')
assert not os.path.exists(LIBC)
old_config = open(os.path.expanduser('~/.emscripten')).read()
run_emsdk('activate tot-upstream')
assert old_config == open(os.path.expanduser('~/.emscripten.old')).read()
# TODO; test on latest as well
assert os.path.exists(LIBC), 'activation supplies prebuilt libc'
check_call(upstream_emcc + ' hello_world.cpp')
print('test tot-fastcomp')
run_emsdk('install tot-fastcomp')
run_emsdk('activate tot-fastcomp')
check_call(fastcomp_emcc + ' hello_world.cpp')
print('test specific release (old)')
run_emsdk('install sdk-1.38.31-64bit')
run_emsdk('activate sdk-1.38.31-64bit')
print('test specific release (new, short name)')
run_emsdk('install 1.38.33')
print('another install must re-download')
checked_call_with_output(emsdk + ' install 1.38.33', expected='Downloading:', unexpected='already exist in destination')
run_emsdk('activate 1.38.33')
assert 'fastcomp' in open(os.path.expanduser('~/.emscripten')).read()
assert 'upstream' not in open(os.path.expanduser('~/.emscripten')).read()
print('test specific release (new, full name)')
run_emsdk('install sdk-1.38.33-upstream-64bit')
run_emsdk('activate sdk-1.38.33-upstream-64bit')
print('test specific release (new, full name)')
run_emsdk('install sdk-tag-1.38.33-64bit')
run_emsdk('activate sdk-tag-1.38.33-64bit')
print('test binaryen source build')
run_emsdk(['install', '--build=Release', '--generator=Unix Makefiles', 'binaryen-master-64bit'])
print('test 32-bit error')
failing_call_with_output('python %s install latest' % hack_emsdk('not is_os_64bit()', 'True'), 'this tool is only provided for 64-bit OSes')
print('test non-git update')
temp_dir = tempfile.mkdtemp()
for filename in os.listdir('.'):
if not filename.startswith('.') and not os.path.isdir(filename):
shutil.copy2(filename, os.path.join(temp_dir, filename))
os.chdir(temp_dir)
run_emsdk('update')
print('second time')
run_emsdk('update')
print('verify downloads exist for all OSes')
latest_hash = TAGS['releases'][TAGS['latest']]
for osname, suffix in [
('linux', 'tbz2'),
('mac', 'tbz2'),
('win', 'zip')
]:
url = 'https://storage.googleapis.com/webassembly/emscripten-releases-builds/%s/%s/wasm-binaries.%s' % (osname, latest_hash, suffix)
print(' checking url: ' + url),
check_call('curl --fail --head --silent ' + url, stdout=subprocess.PIPE)