summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck.py58
1 files changed, 25 insertions, 33 deletions
diff --git a/check.py b/check.py
index f751f3e90..ae642c260 100755
--- a/check.py
+++ b/check.py
@@ -123,6 +123,13 @@ except:
# utilities
+def run_command(cmd, stderr=None):
+ print 'executing: ', ' '.join(cmd)
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr)
+ out, err = proc.communicate()
+ assert proc.returncode == 0, err
+ return out
+
def fail(actual, expected):
raise Exception("incorrect output, diff:\n\n%s" % (
''.join([a.rstrip()+'\n' for a in difflib.unified_diff(expected.split('\n'), actual.split('\n'), fromfile='expected', tofile='actual')])[-1000:]
@@ -270,9 +277,7 @@ for t in sorted(os.listdir(os.path.join('test', 'passes'))):
passname = os.path.basename(t).replace('.wast', '')
opt = '-O' if passname == 'O' else '--' + passname
cmd = [os.path.join('bin', 'binaryen-shell'), opt, os.path.join('test', 'passes', t), '--print']
- print ' ', ' '.join(cmd)
- actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
- assert not err, err
+ actual = run_command(cmd)
fail_if_not_identical(actual, open(os.path.join('test', 'passes', passname + '.txt')).read())
print '[ checking asm2wasm testcases... ]\n'
@@ -287,9 +292,7 @@ for asm in tests:
wasm += '.imprecise'
wasm = os.path.join('test', wasm)
print '..', asm, wasm
- print ' ', ' '.join(cmd)
- actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
- assert err == '', 'bad err:' + err
+ actual = run_command(cmd)
# verify output
if not os.path.exists(wasm):
@@ -345,9 +348,7 @@ for t in tests:
print '..', t
t = os.path.join('test', t)
cmd = [os.path.join('bin', 'binaryen-shell'), t, '--print']
- print ' ', ' '.join(cmd)
- actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
- assert err.replace('printing before:', '').strip() == '', 'bad err:' + err
+ actual = run_command(cmd)
actual = actual.replace('printing before:\n', '')
expected = open(t).read()
@@ -372,10 +373,8 @@ for t in spec_tests:
def run_spec_test(wast):
print ' run binaryen-shell on', wast
- proc = subprocess.Popen([os.path.join('bin', 'binaryen-shell'), wast], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- actual, err = proc.communicate()
- assert proc.returncode == 0, err
- return actual
+ cmd = [os.path.join('bin', 'binaryen-shell'), wast]
+ return run_command(cmd, stderr=subprocess.PIPE)
def check_expected(actual, expected):
if expected and os.path.exists(expected):
@@ -460,9 +459,8 @@ if has_node:
f.write(open(os.path.join('bin', 'binaryen.js')).read())
f.write(open(os.path.join('test', 'binaryen.js', s)).read())
f.close()
- proc = subprocess.Popen([has_node, 'a.js'], stdout=subprocess.PIPE)
- out, err = proc.communicate()
- assert proc.returncode == 0
+ cmd = [has_node, 'a.js']
+ out = run_command(cmd)
expected = open(os.path.join('test', 'binaryen.js', s + '.txt')).read()
if expected not in out:
fail(out, expected)
@@ -479,8 +477,7 @@ for dot_s_dir in ['dot_s', 'llvm_autogenerated']:
cmd = [os.path.join('bin', 's2wasm'), full, '--emscripten-glue'] + stack_alloc
if s.startswith('start_'):
cmd.append('--start')
- actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
- assert err == '', 'bad err:' + err
+ actual = run_command(cmd)
# verify output
expected_file = os.path.join('test', dot_s_dir, wasm)
@@ -492,14 +489,12 @@ for dot_s_dir in ['dot_s', 'llvm_autogenerated']:
fail(actual, expected)
# verify with options
- proc = subprocess.Popen([os.path.join('bin', 's2wasm'), full, '--global-base=1024'] + stack_alloc, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = proc.communicate()
- assert proc.returncode == 0, err
+ cmd = [os.path.join('bin', 's2wasm'), full, '--global-base=1024'] + stack_alloc
+ run_command(cmd)
# run binaryen-shell on the .wast to verify that it parses
- proc = subprocess.Popen([os.path.join('bin', 'binaryen-shell'), expected_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- actual, err = proc.communicate()
- assert proc.returncode == 0, err
+ cmd = [os.path.join('bin', 'binaryen-shell'), expected_file]
+ run_command(cmd)
if torture:
@@ -562,9 +557,8 @@ if has_vanilla_emcc and has_vanilla_llvm:
subprocess.check_call(command)
if has_node:
print ' (check in node)'
- proc = subprocess.Popen([has_node, 'a.wasm.js'], stdout=subprocess.PIPE)
- out, err = proc.communicate()
- assert proc.returncode == 0
+ cmd = [has_node, 'a.wasm.js']
+ out = run_command(cmd)
if out.strip() != expected.strip():
fail(out, expected)
finally:
@@ -600,9 +594,8 @@ if has_emcc:
print ' '.join(command)
subprocess.check_call(command)
- proc = subprocess.Popen(['mozjs', 'a.wasm.js'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = proc.communicate()
- assert proc.returncode == 0, err
+ cmd = ['mozjs', 'a.wasm.js']
+ out = run_command(cmd)
assert 'hello, world!' in out, out
proc = subprocess.Popen([has_node, 'a.wasm.js'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -702,9 +695,8 @@ if has_emcc:
def execute():
if has_node:
- proc = subprocess.Popen([has_node, 'a.' + which + '.js'] + args, stdout=subprocess.PIPE)
- out, err = proc.communicate()
- assert proc.returncode == 0
+ cmd = [has_node, 'a.' + which + '.js'] + args
+ out = run_command(cmd)
if out.strip() != expected.strip():
fail(out, expected)