|
| 1 | +#!/usr/bin/env python2 |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +from support import run_command |
| 6 | +from shared import (WASM2ASM, MOZJS, NODEJS, fail_if_not_identical, tests) |
| 7 | + |
| 8 | + |
| 9 | +def test_wasm2asm(): |
| 10 | + print '\n[ checking wasm2asm testcases... ]\n' |
| 11 | + |
| 12 | + # tests with i64s, invokes, etc. |
| 13 | + blacklist = ['atomics.wast', 'address.wast'] |
| 14 | + spec_tests = [os.path.join('spec', t) for t in |
| 15 | + sorted(os.listdir(os.path.join('test', 'spec')))] |
| 16 | + for wasm in tests + spec_tests: |
| 17 | + if not wasm.endswith('.wast') or os.path.basename(wasm) in blacklist: |
| 18 | + continue |
| 19 | + |
| 20 | + asm = os.path.basename(wasm).replace('.wast', '.2asm.js') |
| 21 | + expected_file = os.path.join('test', asm) |
| 22 | + if not os.path.exists(expected_file): |
| 23 | + continue |
| 24 | + |
| 25 | + print '..', wasm |
| 26 | + |
| 27 | + cmd = WASM2ASM + [os.path.join('test', wasm)] |
| 28 | + out = run_command(cmd) |
| 29 | + |
| 30 | + # verify output |
| 31 | + expected = open(expected_file).read() |
| 32 | + fail_if_not_identical(out, expected) |
| 33 | + |
| 34 | + open('a.2asm.js', 'w').write(out) |
| 35 | + |
| 36 | + if NODEJS: |
| 37 | + # verify asm.js is valid js |
| 38 | + out = run_command([NODEJS, 'a.2asm.js']) |
| 39 | + fail_if_not_identical(out, '') |
| 40 | + |
| 41 | + if MOZJS: |
| 42 | + # verify asm.js validates |
| 43 | + # check only subset of err because mozjs emits timing info |
| 44 | + out = run_command([MOZJS, '-w', 'a.2asm.js'], |
| 45 | + expected_err='Successfully compiled asm.js code', |
| 46 | + err_contains=True) |
| 47 | + fail_if_not_identical(out, '') |
| 48 | + |
| 49 | + |
| 50 | +if __name__ == "__main__": |
| 51 | + test_wasm2asm() |
0 commit comments