|
36 | 36 |
|
37 | 37 |
|
38 | 38 | def test_wasm2js_output(): |
39 | | - for wasm in tests + spec_tests + extra_wasm2js_tests: |
40 | | - if not wasm.endswith('.wast'): |
41 | | - continue |
42 | | - basename = os.path.basename(wasm) |
43 | | - if basename in wasm2js_blacklist: |
44 | | - continue |
| 39 | + for opt in (0, 1): |
| 40 | + for wasm in tests + spec_tests + extra_wasm2js_tests: |
| 41 | + if not wasm.endswith('.wast'): |
| 42 | + continue |
| 43 | + basename = os.path.basename(wasm) |
| 44 | + if basename in wasm2js_blacklist: |
| 45 | + continue |
45 | 46 |
|
46 | | - asm = basename.replace('.wast', '.2asm.js') |
47 | | - expected_file = os.path.join(wasm2js_dir, asm) |
| 47 | + asm = basename.replace('.wast', '.2asm.js') |
| 48 | + expected_file = os.path.join(wasm2js_dir, asm) |
| 49 | + if opt: |
| 50 | + expected_file += '.opt' |
48 | 51 |
|
49 | | - if not os.path.exists(expected_file): |
50 | | - continue |
| 52 | + if not os.path.exists(expected_file): |
| 53 | + continue |
51 | 54 |
|
52 | | - print '..', wasm |
| 55 | + print '..', wasm |
53 | 56 |
|
54 | | - t = os.path.join(options.binaryen_test, wasm) |
| 57 | + t = os.path.join(options.binaryen_test, wasm) |
55 | 58 |
|
56 | | - all_out = [] |
| 59 | + all_out = [] |
57 | 60 |
|
58 | | - for module, asserts in split_wast(t): |
59 | | - with open('split.wast', 'w') as o: |
60 | | - o.write(module + '\n'.join(asserts)) |
| 61 | + for module, asserts in split_wast(t): |
| 62 | + with open('split.wast', 'w') as o: |
| 63 | + o.write(module + '\n'.join(asserts)) |
61 | 64 |
|
62 | | - cmd = WASM2JS + ['split.wast', '-O'] |
63 | | - if 'emscripten' in wasm: |
64 | | - cmd += ['--emscripten'] |
65 | | - out = run_command(cmd) |
66 | | - all_out.append(out) |
| 65 | + cmd = WASM2JS + ['split.wast'] |
| 66 | + if opt: |
| 67 | + cmd += ['-O'] |
| 68 | + if 'emscripten' in wasm: |
| 69 | + cmd += ['--emscripten'] |
| 70 | + out = run_command(cmd) |
| 71 | + all_out.append(out) |
67 | 72 |
|
68 | | - if not NODEJS and not MOZJS: |
69 | | - print 'No JS interpreters. Skipping spec tests.' |
70 | | - continue |
| 73 | + if not NODEJS and not MOZJS: |
| 74 | + print 'No JS interpreters. Skipping spec tests.' |
| 75 | + continue |
71 | 76 |
|
72 | | - open('a.2asm.mjs', 'w').write(out) |
| 77 | + open('a.2asm.mjs', 'w').write(out) |
73 | 78 |
|
74 | | - cmd += ['--allow-asserts'] |
75 | | - out = run_command(cmd) |
76 | | - # also verify it passes pass-debug verifications |
77 | | - with_pass_debug(lambda: run_command(cmd)) |
| 79 | + cmd += ['--allow-asserts'] |
| 80 | + out = run_command(cmd) |
| 81 | + # also verify it passes pass-debug verifications |
| 82 | + with_pass_debug(lambda: run_command(cmd)) |
78 | 83 |
|
79 | | - open('a.2asm.asserts.mjs', 'w').write(out) |
| 84 | + open('a.2asm.asserts.mjs', 'w').write(out) |
80 | 85 |
|
81 | | - # verify asm.js is valid js, note that we're using --experimental-modules |
82 | | - # to enable ESM syntax and we're also passing a custom loader to handle the |
83 | | - # `spectest` and `env` modules in our tests. |
84 | | - if NODEJS: |
85 | | - node = [NODEJS, '--experimental-modules', '--loader', './scripts/test/node-esm-loader.mjs'] |
86 | | - cmd = node[:] |
87 | | - cmd.append('a.2asm.mjs') |
88 | | - out = run_command(cmd) |
89 | | - fail_if_not_identical(out, '') |
90 | | - cmd = node[:] |
91 | | - cmd.append('a.2asm.asserts.mjs') |
92 | | - out = run_command(cmd, expected_err='', err_ignore='The ESM module loader is experimental') |
93 | | - fail_if_not_identical(out, '') |
| 86 | + # verify asm.js is valid js, note that we're using --experimental-modules |
| 87 | + # to enable ESM syntax and we're also passing a custom loader to handle the |
| 88 | + # `spectest` and `env` modules in our tests. |
| 89 | + if NODEJS: |
| 90 | + node = [NODEJS, '--experimental-modules', '--loader', './scripts/test/node-esm-loader.mjs'] |
| 91 | + cmd = node[:] |
| 92 | + cmd.append('a.2asm.mjs') |
| 93 | + out = run_command(cmd) |
| 94 | + fail_if_not_identical(out, '') |
| 95 | + cmd = node[:] |
| 96 | + cmd.append('a.2asm.asserts.mjs') |
| 97 | + out = run_command(cmd, expected_err='', err_ignore='The ESM module loader is experimental') |
| 98 | + fail_if_not_identical(out, '') |
94 | 99 |
|
95 | | - fail_if_not_identical_to_file(''.join(all_out), expected_file) |
| 100 | + fail_if_not_identical_to_file(''.join(all_out), expected_file) |
96 | 101 |
|
97 | 102 |
|
98 | 103 | def test_asserts_output(): |
@@ -123,41 +128,46 @@ def test_wasm2js(): |
123 | 128 | def update_wasm2js_tests(): |
124 | 129 | print '\n[ checking wasm2js ]\n' |
125 | 130 |
|
126 | | - for wasm in tests + spec_tests + extra_wasm2js_tests: |
127 | | - if not wasm.endswith('.wast'): |
128 | | - continue |
| 131 | + for opt in (0, 1): |
| 132 | + for wasm in tests + spec_tests + extra_wasm2js_tests: |
| 133 | + if not wasm.endswith('.wast'): |
| 134 | + continue |
129 | 135 |
|
130 | | - if os.path.basename(wasm) in wasm2js_blacklist: |
131 | | - continue |
| 136 | + if os.path.basename(wasm) in wasm2js_blacklist: |
| 137 | + continue |
132 | 138 |
|
133 | | - asm = os.path.basename(wasm).replace('.wast', '.2asm.js') |
134 | | - expected_file = os.path.join(wasm2js_dir, asm) |
| 139 | + asm = os.path.basename(wasm).replace('.wast', '.2asm.js') |
| 140 | + expected_file = os.path.join(wasm2js_dir, asm) |
| 141 | + if opt: |
| 142 | + expected_file += '.opt' |
135 | 143 |
|
136 | | - # we run wasm2js on tests and spec tests only if the output |
137 | | - # exists - only some work so far. the tests in extra are in |
138 | | - # the test/wasm2js dir and so are specific to wasm2js, and |
139 | | - # we run all of those. |
140 | | - if wasm not in extra_wasm2js_tests and not os.path.exists(expected_file): |
141 | | - continue |
| 144 | + # we run wasm2js on tests and spec tests only if the output |
| 145 | + # exists - only some work so far. the tests in extra are in |
| 146 | + # the test/wasm2js dir and so are specific to wasm2js, and |
| 147 | + # we run all of those. |
| 148 | + if wasm not in extra_wasm2js_tests and not os.path.exists(expected_file): |
| 149 | + continue |
142 | 150 |
|
143 | | - print '..', wasm |
| 151 | + print '..', wasm |
144 | 152 |
|
145 | | - t = os.path.join(options.binaryen_test, wasm) |
| 153 | + t = os.path.join(options.binaryen_test, wasm) |
146 | 154 |
|
147 | | - all_out = [] |
| 155 | + all_out = [] |
148 | 156 |
|
149 | | - for module, asserts in split_wast(t): |
150 | | - with open('split.wast', 'w') as o: |
151 | | - o.write(module + '\n'.join(asserts)) |
| 157 | + for module, asserts in split_wast(t): |
| 158 | + with open('split.wast', 'w') as o: |
| 159 | + o.write(module + '\n'.join(asserts)) |
152 | 160 |
|
153 | | - cmd = WASM2JS + ['split.wast', '-O'] |
154 | | - if 'emscripten' in wasm: |
155 | | - cmd += ['--emscripten'] |
156 | | - out = run_command(cmd) |
157 | | - all_out.append(out) |
| 161 | + cmd = WASM2JS + ['split.wast'] |
| 162 | + if opt: |
| 163 | + cmd += ['-O'] |
| 164 | + if 'emscripten' in wasm: |
| 165 | + cmd += ['--emscripten'] |
| 166 | + out = run_command(cmd) |
| 167 | + all_out.append(out) |
158 | 168 |
|
159 | | - with open(expected_file, 'w') as o: |
160 | | - o.write(''.join(all_out)) |
| 169 | + with open(expected_file, 'w') as o: |
| 170 | + o.write(''.join(all_out)) |
161 | 171 |
|
162 | 172 | for wasm in assert_tests: |
163 | 173 | print '..', wasm |
|
0 commit comments