Skip to content

Commit 7924a23

Browse files
authored
[test] Add more testing for instantiateWasm module API. NFC (#23577)
See #23572
1 parent 1e2d834 commit 7924a23

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

test/test_browser.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4208,9 +4208,10 @@ def test_async_compile(self, opts, returncode):
42084208
# Test that implementing Module.instantiateWasm() callback works.
42094209
@also_with_asan
42104210
def test_manual_wasm_instantiate(self):
4211-
self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js'])
4211+
self.set_setting('EXIT_RUNTIME')
4212+
self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js'], reporting=Reporting.JS_ONLY)
42124213
shutil.copy(test_file('test_manual_wasm_instantiate.html'), '.')
4213-
self.run_browser('test_manual_wasm_instantiate.html', '/report_result?1')
4214+
self.run_browser('test_manual_wasm_instantiate.html', '/report_result?exit:0')
42144215

42154216
def test_wasm_locate_file(self):
42164217
# Test that it is possible to define "Module.locateFile(foo)" function to locate where worker.js will be loaded from.

test/test_manual_wasm_instantiate.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
// University of Illinois/NCSA Open Source License. Both these licenses can be
44
// found in the LICENSE file.
55

6+
#include <assert.h>
67
#include <stdio.h>
7-
#include <emscripten/emscripten.h>
8+
#include <emscripten/em_asm.h>
89

9-
int main()
10-
{
11-
printf("OK\n");
12-
#ifdef REPORT_RESULT
13-
int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;});
14-
REPORT_RESULT(result);
15-
#endif
10+
int main() {
11+
printf("in main\n");
12+
int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;});
13+
assert(result);
14+
return 0;
1615
}

test/test_other.py

+15
Original file line numberDiff line numberDiff line change
@@ -15542,3 +15542,18 @@ def test_invalid_export_name(self):
1554215542
create_file('test.c', '__attribute__((export_name("my.func"))) void myfunc() {}')
1554315543
err = self.expect_fail([EMCC, 'test.c'])
1554415544
self.assertContained('emcc: error: invalid export name: my.func', err)
15545+
15546+
def test_instantiate_wasm(self):
15547+
create_file('pre.js', '''
15548+
Module['instantiateWasm'] = (imports, successCallback) => {
15549+
var wasmFile = findWasmBinary();
15550+
getWasmBinary(wasmFile).then((bytes) => {
15551+
WebAssembly.instantiate(bytes, imports).then((res) => {
15552+
out('wasm instantiation succeeded');
15553+
Module['testWasmInstantiationSucceeded'] = 1;
15554+
successCallback(res.instance, res.module);
15555+
});
15556+
});
15557+
return {}; // Compiling asynchronously, no exports.
15558+
}''')
15559+
self.do_runf('test_manual_wasm_instantiate.c', emcc_args=['--pre-js=pre.js'])

0 commit comments

Comments
 (0)