diff options
Diffstat (limited to 'check.py')
-rwxr-xr-x | check.py | 108 |
1 files changed, 31 insertions, 77 deletions
@@ -17,7 +17,7 @@ import os, shutil, sys, subprocess, difflib, json, time, urllib2 import scripts.storage -import scripts.support +from scripts.support import run_command, split_wast interpreter = None requested = [] @@ -73,7 +73,7 @@ def fetch_waterfall(): os.mkdir(WATERFALL_BUILD_DIR) subprocess.check_call(['tar', '-xf', os.path.abspath(fullname)], cwd=WATERFALL_BUILD_DIR) print '(noting local revision)' - open(os.path.join('test', 'local-revision'), 'w').write(rev) + with open(os.path.join('test', 'local-revision'), 'w') as o: o.write(rev) has_vanilla_llvm = False @@ -155,13 +155,6 @@ def delete_from_orbit(filename): # removes a file if it exists, using any and al except: pass -def run_command(cmd, expected_status=0, stderr=None): - print 'executing: ', ' '.join(cmd) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr) - out, err = proc.communicate() - if proc.returncode != expected_status: raise Exception(('run_command failed', 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')])[:] @@ -193,50 +186,6 @@ if not has_vanilla_emcc: # check utilities -def split_wast(wast): - # .wast files can contain multiple modules, and assertions for each one. - # this splits out a wast into [(module, assertions), ..] - # we ignore module invalidity tests here. - wast = open(wast).read() - ret = [] - def to_end(j): - depth = 1 - while depth > 0 and j < len(wast): - if wast[j] == '"': - j = wast.find('"', j + 1) - elif wast[j] == '(': - depth += 1 - elif wast[j] == ')': - depth -= 1 - elif wast[j] == ';' and wast[j+1] == ';': - j = wast.find('\n', j) - j += 1 - return j - i = 0 - while i >= 0: - start = wast.find('(', i) - if start >= 0 and wast[start+1] == ';': - # block comment - i = wast.find(';)', start+2) - assert i > 0, wast[start:] - i += 2 - continue - skip = wast.find(';', i) - if skip >= 0 and skip < start and skip + 1 < len(wast): - if wast[skip+1] == ';': - i = wast.find('\n', i) + 1 - continue - if start < 0: break - i = to_end(start + 1) - chunk = wast[start:i] - if chunk.startswith('(module'): - ret += [(chunk, [])] - elif chunk.startswith('(assert_invalid'): - continue - elif chunk.startswith(('(assert', '(invoke')): - ret[-1][1].append(chunk) - return ret - def binary_format_check(wast, verify_final_result=True): # checks we can convert the wast to binary and back @@ -254,7 +203,7 @@ def binary_format_check(wast, verify_final_result=True): assert os.path.exists('ab.wast') # make sure it is a valid wast - cmd = [os.path.join('bin', 'binaryen-shell'), 'ab.wast'] + cmd = [os.path.join('bin', 'wasm-shell'), 'ab.wast'] print ' ', ' '.join(cmd) subprocess.check_call(cmd, stdout=subprocess.PIPE) @@ -270,11 +219,11 @@ def minify_check(wast, verify_final_result=True): # checks we can parse minified output print ' (minify check)' - cmd = [os.path.join('bin', 'binaryen-shell'), wast, '--print-minified'] + cmd = [os.path.join('bin', 'wasm-opt'), wast, '--print-minified'] print ' ', ' '.join(cmd) - subprocess.check_call([os.path.join('bin', 'binaryen-shell'), wast, '--print-minified'], stdout=open('a.wasm', 'w'), stderr=subprocess.PIPE) + subprocess.check_call([os.path.join('bin', 'wasm-opt'), wast, '--print-minified'], stdout=open('a.wasm', 'w'), stderr=subprocess.PIPE) assert os.path.exists('a.wasm') - subprocess.check_call([os.path.join('bin', 'binaryen-shell'), 'a.wasm', '--print-minified'], stdout=open('b.wasm', 'w'), stderr=subprocess.PIPE) + subprocess.check_call([os.path.join('bin', 'wasm-opt'), 'a.wasm', '--print-minified'], stdout=open('b.wasm', 'w'), stderr=subprocess.PIPE) assert os.path.exists('b.wasm') if verify_final_result: expected = open('a.wasm').read() @@ -301,23 +250,28 @@ for e in executables: assert e in err, 'Expected help to contain program name, got:\n%s' % err assert len(err.split('\n')) > 8, 'Expected some help, got:\n%s' % err -print '\n[ checking binaryen-shell -o notation... ]\n' +print '\n[ checking wasm-opt -o notation... ]\n' wast = os.path.join('test', 'hello_world.wast') delete_from_orbit('a.wast') -cmd = [os.path.join('bin', 'binaryen-shell'), wast, '-o', 'a.wast'] +cmd = [os.path.join('bin', 'wasm-opt'), wast, '-o', 'a.wast'] run_command(cmd) fail_if_not_identical(open('a.wast').read(), open(wast).read()) -print '\n[ checking binaryen-shell passes... ]\n' +print '\n[ checking wasm-opt passes... ]\n' for t in sorted(os.listdir(os.path.join('test', 'passes'))): if t.endswith('.wast'): print '..', t passname = os.path.basename(t).replace('.wast', '') opts = ['-O'] if passname == 'O' else ['--' + p for p in passname.split('_')] - cmd = [os.path.join('bin', 'binaryen-shell')] + opts + [os.path.join('test', 'passes', t), '--print'] - actual = run_command(cmd) + t = os.path.join('test', 'passes', t) + actual = '' + for module, asserts in split_wast(t): + assert len(asserts) == 0 + with open('split.wast', 'w') as o: o.write(module) + cmd = [os.path.join('bin', 'wasm-opt')] + opts + ['split.wast', '--print'] + actual += run_command(cmd) fail_if_not_identical(actual, open(os.path.join('test', 'passes', passname + '.txt')).read()) print '[ checking asm2wasm testcases... ]\n' @@ -350,7 +304,7 @@ for asm in tests: # verify in wasm if interpreter: # remove imports, spec interpreter doesn't know what to do with them - subprocess.check_call([os.path.join('bin', 'binaryen-shell'), '--remove-imports', '--print', wasm], stdout=open('ztemp.wast', 'w'), stderr=subprocess.PIPE) + subprocess.check_call([os.path.join('bin', 'wasm-opt'), '--remove-imports', wasm], stdout=open('ztemp.wast', 'w'), stderr=subprocess.PIPE) proc = subprocess.Popen([interpreter, 'ztemp.wast'], stderr=subprocess.PIPE) out, err = proc.communicate() if proc.returncode != 0: @@ -370,28 +324,28 @@ for asm in tests: raise Exception('wasm interpreter error: ' + err) # failed to pretty-print raise Exception('wasm interpreter error') -print '\n[ checking binaryen-shell parsing & printing... ]\n' +print '\n[ checking wasm-opt parsing & printing... ]\n' for t in sorted(os.listdir(os.path.join('test', 'print'))): if t.endswith('.wast'): print '..', t wasm = os.path.basename(t).replace('.wast', '') - cmd = [os.path.join('bin', 'binaryen-shell'), os.path.join('test', 'print', t), '--print'] + cmd = [os.path.join('bin', 'wasm-opt'), os.path.join('test', 'print', t), '--print'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() fail_if_not_identical(actual, open(os.path.join('test', 'print', wasm + '.txt')).read()) - cmd = [os.path.join('bin', 'binaryen-shell'), os.path.join('test', 'print', t), '--print-minified'] + cmd = [os.path.join('bin', 'wasm-opt'), os.path.join('test', 'print', t), '--print-minified'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() fail_if_not_identical(actual.strip(), open(os.path.join('test', 'print', wasm + '.minified.txt')).read().strip()) -print '\n[ checking binaryen-shell testcases... ]\n' +print '\n[ checking wasm-opt testcases... ]\n' for t in tests: if t.endswith('.wast') and not t.startswith('spec'): print '..', t t = os.path.join('test', t) - cmd = [os.path.join('bin', 'binaryen-shell'), t, '--print'] + cmd = [os.path.join('bin', 'wasm-opt'), t, '--print'] actual = run_command(cmd) actual = actual.replace('printing before:\n', '') @@ -402,7 +356,7 @@ for t in tests: binary_format_check(t) minify_check(t) -print '\n[ checking binaryen-shell spec testcases... ]\n' +print '\n[ checking wasm-shell spec testcases... ]\n' if len(requested) == 0: BLACKLIST = [] @@ -416,8 +370,8 @@ for t in spec_tests: wast = os.path.join('test', t) def run_spec_test(wast): - print ' run binaryen-shell on', wast - cmd = [os.path.join('bin', 'binaryen-shell'), wast] + print ' run wasm-shell on', wast + cmd = [os.path.join('bin', 'wasm-shell'), wast] return run_command(cmd, stderr=subprocess.PIPE) def check_expected(actual, expected): @@ -458,7 +412,7 @@ for t in spec_tests: for module, asserts in split_wast(wast): print ' testing split module', split_num split_num += 1 - open('split.wast', 'w').write(module + '\n' + '\n'.join(asserts)) + with open('split.wast', 'w') as o: o.write(module + '\n' + '\n'.join(asserts)) run_spec_test('split.wast') # before binary stuff - just check it's still ok split out result_wast = binary_format_check('split.wast', verify_final_result=False) # add the asserts, and verify that the test still passes @@ -547,8 +501,8 @@ for dot_s_dir in ['dot_s', 'llvm_autogenerated']: 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 - cmd = [os.path.join('bin', 'binaryen-shell'), expected_file] + # run wasm-shell on the .wast to verify that it parses + cmd = [os.path.join('bin', 'wasm-shell'), expected_file] run_command(cmd) print '\n[ running linker tests... ]\n' @@ -609,7 +563,7 @@ if torture: import test.waterfall.src.execute_files as execute_files unexpected_result_count += execute_files.run( - runner=os.path.abspath(os.path.join('bin', 'binaryen-shell')), + runner=os.path.abspath(os.path.join('bin', 'wasm-shell')), files=os.path.abspath(os.path.join(s2wasm_torture_out, '*.wast')), fails=os.path.abspath(os.path.join('test', 's2wasm_known_binaryen_shell_test_failures.txt')), out='', @@ -673,7 +627,7 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): continue print ' (will check trace in ', t, ')' src = 'trace.cpp' - open(src, 'w').write(out) + with open(src, 'w') as o: o.write(out) expected = os.path.join('test', 'example', t + '.txt') else: src = os.path.join('test', 'example', t) @@ -751,7 +705,7 @@ if has_emcc: asm = open('a.wasm.asm.js').read() asm = asm.replace('"almost asm"', '"use asm"; var not_in_asm = [].length + (true || { x: 5 }.x);') asm = asm.replace("'almost asm'", '"use asm"; var not_in_asm = [].length + (true || { x: 5 }.x);') - open('a.wasm.asm.js', 'w').write(asm) + with open('a.wasm.asm.js', 'w') as o: o.write(asm) if method == 'interpret-asm2wasm': os.unlink('a.wasm.wast') # we should not need the .wast if not success: |