Skip to content

[test] Add more testing for instantiateWasm module API. NFC #23577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4209,9 +4209,10 @@ def test_async_compile(self, opts, returncode):
# Test that implementing Module.instantiateWasm() callback works.
@also_with_asan
def test_manual_wasm_instantiate(self):
self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js'])
self.set_setting('EXIT_RUNTIME')
self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js'], reporting=Reporting.JS_ONLY)
shutil.copy(test_file('test_manual_wasm_instantiate.html'), '.')
self.run_browser('test_manual_wasm_instantiate.html', '/report_result?1')
self.run_browser('test_manual_wasm_instantiate.html', '/report_result?exit:0')

def test_wasm_locate_file(self):
# Test that it is possible to define "Module.locateFile(foo)" function to locate where worker.js will be loaded from.
Expand Down
15 changes: 7 additions & 8 deletions test/test_manual_wasm_instantiate.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <assert.h>
#include <stdio.h>
#include <emscripten/emscripten.h>
#include <emscripten/em_asm.h>

int main()
{
printf("OK\n");
#ifdef REPORT_RESULT
int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;});
REPORT_RESULT(result);
#endif
int main() {
printf("in main\n");
int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;});
assert(result);
return 0;
}
15 changes: 15 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -15542,3 +15542,18 @@ def test_invalid_export_name(self):
create_file('test.c', '__attribute__((export_name("my.func"))) void myfunc() {}')
err = self.expect_fail([EMCC, 'test.c'])
self.assertContained('emcc: error: invalid export name: my.func', err)

def test_instantiate_wasm(self):
create_file('pre.js', '''
Module['instantiateWasm'] = (imports, successCallback) => {
var wasmFile = findWasmBinary();
getWasmBinary(wasmFile).then((bytes) => {
WebAssembly.instantiate(bytes, imports).then((res) => {
out('wasm instantiation succeeded');
Module['testWasmInstantiationSucceeded'] = 1;
successCallback(res.instance, res.module);
});
});
return {}; // Compiling asynchronously, no exports.
}''')
self.do_runf('test_manual_wasm_instantiate.c', emcc_args=['--pre-js=pre.js'])