Skip to content

Commit

Permalink
Cleanup test_async_compile. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Feb 5, 2024
1 parent aef8142 commit d69c187
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions test/browser/test_async_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ int main() {
int result = EM_ASM_INT({
return Module.sawAsyncCompilation | 0;
});
printf("sawAsyncCompilation => %d\n", result);
return result;
}

29 changes: 14 additions & 15 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4469,7 +4469,16 @@ def test_in_flight_memfile_request(self, args, expected):
# should happen when there is a mem init file (-O2+)
self.btest('in_flight_memfile_request.c', expected=expected)

def test_async_compile(self):
@parameterized({
'': ([], 1),
'O1': (['-O1'], 1),
'O2': (['-O2'], 1),
'O3': (['-O3'], 1),
# force it on
'force': (['-sWASM_ASYNC_COMPILATION'], 1),
'off': (['-sWASM_ASYNC_COMPILATION=0'], 0),
})
def test_async_compile(self, opts, returncode):
# notice when we use async compilation
script = '''
<script>
Expand All @@ -4478,11 +4487,13 @@ def test_async_compile(self):
var real_wasm_instantiateStreaming = WebAssembly.instantiateStreaming;
if (typeof real_wasm_instantiateStreaming === 'function') {
WebAssembly.instantiateStreaming = (a, b) => {
console.log('instantiateStreaming called');
Module.sawAsyncCompilation = true;
return real_wasm_instantiateStreaming(a, b);
};
} else {
WebAssembly.instantiate = (a, b) => {
console.log('instantiate called');
Module.sawAsyncCompilation = true;
return real_wasm_instantiate(a, b);
};
Expand All @@ -4497,21 +4508,9 @@ def test_async_compile(self):
'''
shell_with_script('shell.html', 'shell.html', script)
common_args = ['--shell-file', 'shell.html']
for opts, returncode in [
([], 1),
(['-O1'], 1),
(['-O2'], 1),
(['-O3'], 1),
# force it on
(['-sWASM_ASYNC_COMPILATION'], 1),
# force it off. note that we use -O3 here to make the binary small enough
# for chrome to allow compiling it synchronously
(['-O3', '-sWASM_ASYNC_COMPILATION=0'], 0),
]:
print(opts, returncode)
self.btest_exit('test_async_compile.c', assert_returncode=returncode, args=common_args + opts)
self.btest_exit('test_async_compile.c', assert_returncode=returncode, args=common_args + opts)
# Ensure that compilation still works and is async without instantiateStreaming available
no_streaming = ' <script> WebAssembly.instantiateStreaming = undefined;</script>'
no_streaming = '<script>WebAssembly.instantiateStreaming = undefined;</script>'
shell_with_script('shell.html', 'shell.html', no_streaming + script)
self.btest_exit('test_async_compile.c', assert_returncode=1, args=common_args)

Expand Down

0 comments on commit d69c187

Please sign in to comment.