Skip to content

Commit 4a592c7

Browse files
froydnjkripken
authored andcommitted
adjust test scripts to cope with out-of-tree builds (#1420)
Many places assume that test/blah is valid, but that's only valid if you're executing scripts from the binaryen source directory. The binaryen_test option is more general, and enables out-of-tree testing, so that's what we should be using instead.
1 parent 5532413 commit 4a592c7

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

check.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def run_wasm_opt_tests():
108108
if 'BINARYEN_PASS_DEBUG' in os.environ:
109109
del os.environ['BINARYEN_PASS_DEBUG']
110110

111-
fail_if_not_identical(actual, open(os.path.join('test', 'passes', passname + ('.bin' if binary else '') + '.txt'), 'rb').read())
111+
fail_if_not_identical(actual, open(os.path.join(options.binaryen_test, 'passes', passname + ('.bin' if binary else '') + '.txt'), 'rb').read())
112112

113113
if 'emit-js-wrapper' in t:
114114
with open('a.js') as actual:
@@ -175,10 +175,11 @@ def run_wasm_dis_tests():
175175
def run_wasm_merge_tests():
176176
print '\n[ checking wasm-merge... ]\n'
177177

178-
for t in os.listdir(os.path.join('test', 'merge')):
178+
test_dir = os.path.join(options.binaryen_test, 'merge')
179+
for t in os.listdir(test_dir):
179180
if t.endswith(('.wast', '.wasm')):
180181
print '..', t
181-
t = os.path.join('test', 'merge', t)
182+
t = os.path.join(test_dir, t)
182183
u = t + '.toMerge'
183184
for finalize in [0, 1]:
184185
for opt in [0, 1]:
@@ -198,21 +199,23 @@ def run_wasm_merge_tests():
198199
def run_crash_tests():
199200
print "\n[ checking we don't crash on tricky inputs... ]\n"
200201

201-
for t in os.listdir(os.path.join('test', 'crash')):
202+
test_dir = os.path.join(options.binaryen_test, 'crash')
203+
for t in os.listdir(test_dir):
202204
if t.endswith(('.wast', '.wasm')):
203205
print '..', t
204-
t = os.path.join('test', 'crash', t)
206+
t = os.path.join(test_dir, t)
205207
cmd = WASM_OPT + [t]
206208
# expect a parse error to be reported
207209
run_command(cmd, expected_err='parse exception:', err_contains=True, expected_status=1)
208210

209211
def run_ctor_eval_tests():
210212
print '\n[ checking wasm-ctor-eval... ]\n'
211213

212-
for t in os.listdir(os.path.join('test', 'ctor-eval')):
214+
test_dir = os.path.join(options.binaryen_test, 'ctor-eval')
215+
for t in os.listdir(test_dir):
213216
if t.endswith(('.wast', '.wasm')):
214217
print '..', t
215-
t = os.path.join('test', 'ctor-eval', t)
218+
t = os.path.join(test_dir, t)
216219
ctors = open(t + '.ctors').read().strip()
217220
cmd = WASM_CTOR_EVAL + [t, '-o', 'a.wast', '-S', '--ctors', ctors]
218221
stdout = run_command(cmd)
@@ -224,10 +227,11 @@ def run_ctor_eval_tests():
224227
def run_wasm_metadce_tests():
225228
print '\n[ checking wasm-metadce ]\n'
226229

227-
for t in os.listdir(os.path.join('test', 'metadce')):
230+
test_dir = os.path.join(options.binaryen_test, 'metadce')
231+
for t in os.listdir(test_dir):
228232
if t.endswith(('.wast', '.wasm')):
229233
print '..', t
230-
t = os.path.join('test', 'metadce', t)
234+
t = os.path.join(test_dir, t)
231235
graph = t + '.graph.txt'
232236
cmd = WASM_METADCE + [t, '--graph-file=' + graph, '-o', 'a.wast', '-S']
233237
stdout = run_command(cmd)
@@ -241,10 +245,11 @@ def run_wasm_metadce_tests():
241245
def run_wasm_reduce_tests():
242246
print '\n[ checking wasm-reduce ]\n'
243247

244-
for t in os.listdir(os.path.join('test', 'reduce')):
248+
test_dir = os.path.join(options.binaryen_test, 'reduce')
249+
for t in os.listdir(test_dir):
245250
if t.endswith('.wast'):
246251
print '..', t
247-
t = os.path.join('test', 'reduce', t)
252+
t = os.path.join(test_dir, t)
248253
# convert to wasm
249254
run_command(WASM_AS + [t, '-o', 'a.wasm'])
250255
print run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])

scripts/test/wasm2asm.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
import os
44

55
from support import run_command
6-
from shared import (WASM2ASM, MOZJS, NODEJS, fail_if_not_identical, tests)
7-
6+
from shared import (
7+
WASM2ASM, MOZJS, NODEJS, fail_if_not_identical, options, tests
8+
)
89

910
# tests with i64s, invokes, etc.
10-
spec_tests = [os.path.join('spec', t)
11-
for t in sorted(os.listdir(os.path.join('test', 'spec')))
11+
spec_dir = os.path.join(options.binaryen_test, 'spec')
12+
spec_tests = [os.path.join(spec_dir, t)
13+
for t in sorted(os.listdir(spec_dir))
1214
if '.fail' not in t]
13-
extra_tests = [os.path.join('wasm2asm', t) for t in
14-
sorted(os.listdir(os.path.join('test', 'wasm2asm')))]
15+
wasm2asm_dir = os.path.join(options.binaryen_test, 'wasm2asm')
16+
extra_tests = [os.path.join(wasm2asm_dir, t) for t in
17+
sorted(os.listdir(wasm2asm_dir))]
1518
assert_tests = ['wasm2asm.wast.asserts']
1619

1720

@@ -21,14 +24,14 @@ def test_wasm2asm_output():
2124
continue
2225

2326
asm = os.path.basename(wasm).replace('.wast', '.2asm.js')
24-
expected_file = os.path.join('test', asm)
27+
expected_file = os.path.join(options.binaryen_test, asm)
2528

2629
if not os.path.exists(expected_file):
2730
continue
2831

2932
print '..', wasm
3033

31-
cmd = WASM2ASM + [os.path.join('test', wasm)]
34+
cmd = WASM2ASM + [os.path.join(options.binaryen_test, wasm)]
3235
out = run_command(cmd)
3336
expected = open(expected_file).read()
3437
fail_if_not_identical(out, expected)
@@ -68,10 +71,11 @@ def test_asserts_output():
6871

6972
asserts = os.path.basename(wasm).replace('.wast.asserts', '.asserts.js')
7073
traps = os.path.basename(wasm).replace('.wast.asserts', '.traps.js')
71-
asserts_expected_file = os.path.join('test', asserts)
72-
traps_expected_file = os.path.join('test', traps)
74+
asserts_expected_file = os.path.join(options.binaryen_test, asserts)
75+
traps_expected_file = os.path.join(options.binaryen_test, traps)
7376

74-
cmd = WASM2ASM + [os.path.join('test', wasm), '--allow-asserts']
77+
wasm = os.path.join(options.binaryen_test, wasm)
78+
cmd = WASM2ASM + [wasm, '--allow-asserts']
7579
out = run_command(cmd)
7680
expected = open(asserts_expected_file).read()
7781
fail_if_not_identical(out, expected)

0 commit comments

Comments
 (0)