diff --git a/test/common.py b/test/common.py index d26f1f3ee8f29..6569e5e65cfba 100644 --- a/test/common.py +++ b/test/common.py @@ -1147,7 +1147,7 @@ def setup_nodefs_test(self): if self.get_setting('WASMFS'): # without this the JS setup code in setup_nodefs.js doesn't work self.set_setting('FORCE_FILESYSTEM') - self.emcc_args += ['-DNODEFS', '-lnodefs.js', '--pre-js', test_file('setup_nodefs.js')] + self.emcc_args += ['-DNODEFS', '-lnodefs.js', '--pre-js', test_file('setup_nodefs.js'), '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]'] def setup_noderawfs_test(self): self.require_node() @@ -1336,17 +1336,17 @@ def in_dir(self, *pathelems): def add_pre_run(self, code): assert not self.get_setting('MINIMAL_RUNTIME') create_file('prerun.js', 'Module.preRun = function() { %s }\n' % code) - self.emcc_args += ['--pre-js', 'prerun.js'] + self.emcc_args += ['--pre-js', 'prerun.js', '-sINCOMING_MODULE_JS_API=[preRun]'] def add_post_run(self, code): assert not self.get_setting('MINIMAL_RUNTIME') create_file('postrun.js', 'Module.postRun = function() { %s }\n' % code) - self.emcc_args += ['--pre-js', 'postrun.js'] + self.emcc_args += ['--pre-js', 'postrun.js', '-sINCOMING_MODULE_JS_API=[postRun]'] def add_on_exit(self, code): assert not self.get_setting('MINIMAL_RUNTIME') create_file('onexit.js', 'Module.onExit = function() { %s }\n' % code) - self.emcc_args += ['--pre-js', 'onexit.js'] + self.emcc_args += ['--pre-js', 'onexit.js', '-sINCOMING_MODULE_JS_API=[onExit]'] # returns the full list of arguments to pass to emcc # param @main_file whether this is the main file of the test. some arguments diff --git a/test/core/test_core_types.c b/test/core/test_core_types.c index 881df580ae2e2..1dd736e5b4d51 100644 --- a/test/core/test_core_types.c +++ b/test/core/test_core_types.c @@ -77,7 +77,10 @@ // We prefer to use __EMSCRIPTEN__, but for compatibility, we define // EMSCRIPTEN too. -#ifndef EMSCRIPTEN +#if defined(IN_STRICT_MODE) && defined(EMSCRIPTEN) +#error When compiling in -sSTRICT mode, EMSCRIPTEN should not be defined, but it was! +#endif +#if !defined(IN_STRICT_MODE) && !defined(EMSCRIPTEN) #error EMSCRIPTEN is not defined #endif diff --git a/test/core/test_getValue_setValue.cpp b/test/core/test_getValue_setValue.cpp index c2d68b520d816..e2e3aaec87c10 100644 --- a/test/core/test_getValue_setValue.cpp +++ b/test/core/test_getValue_setValue.cpp @@ -15,20 +15,20 @@ int main() { setValue($0, 1234, 'i32'); out('i32: ' + getValue($0, 'i32')); #ifdef WASM_BIGINT - i64 = getValue($1, 'i64'); + var i64 = getValue($1, 'i64'); out('i64: 0x' + i64.toString(16) + ' ' + typeof(i64)); #endif - ptr = getValue($1, '*'); + var ptr = getValue($1, '*'); out('ptr: 0x' + ptr.toString(16) + ' ' + typeof(ptr)); #else out('i32: ' + getValue($0, 'i32')); Module['setValue']($0, 1234, 'i32'); out('i32: ' + Module['getValue']($0, 'i32')); #ifdef WASM_BIGINT - i64 = Module['getValue']($1, 'i64'); + var i64 = Module['getValue']($1, 'i64'); out('i64: 0x' + i64.toString(16) + ' ' + typeof(i64)); #endif - ptr = Module['getValue']($1, '*'); + var ptr = Module['getValue']($1, '*'); out('ptr: 0x' + ptr.toString(16) + ' ' + typeof(ptr)); #endif diff --git a/test/test_core.py b/test/test_core.py index 15f0b694f3527..38c4c0ff14f4b 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -383,6 +383,7 @@ def decorated(self, textdecoder, *args, **kwargs): no_minimal_runtime = make_no_decorator_for_setting('MINIMAL_RUNTIME') no_safe_heap = make_no_decorator_for_setting('SAFE_HEAP') +no_strict = make_no_decorator_for_setting('STRICT') def is_sanitizing(args): @@ -646,6 +647,8 @@ def test_sha1(self): self.do_runf('third_party/sha1.c', 'SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6') def test_core_types(self): + if self.get_setting('STRICT'): + self.emcc_args += ['-DIN_STRICT_MODE=1'] self.do_runf('core/test_core_types.c') def test_cube2md5(self): @@ -2649,6 +2652,7 @@ def test_pthread_abort(self): # handler will only be present in the main thread (much like it would if it # was passed in by pre-populating the module object on prior to loading). self.add_pre_run("Module.onAbort = () => console.log('onAbort called');") + self.emcc_args += ['-sINCOMING_MODULE_JS_API=[preRun,onAbort]'] self.do_run_in_out_file_test('pthread/test_pthread_abort.c', assert_returncode=NON_ZERO) @node_pthreads @@ -4159,7 +4163,7 @@ def test_dylink_locate_file(self): } }; ''' % (so_name, so_dir)) - self.do_basic_dylink_test(so_dir=so_dir, so_name=so_name, main_emcc_args=['--pre-js', 'pre.js']) + self.do_basic_dylink_test(so_dir=so_dir, so_name=so_name, main_emcc_args=['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[locateFile]']) @with_dylink_reversed def test_dylink_function_pointer_equality(self): @@ -5209,7 +5213,7 @@ class Bar : public Foo { @needs_dylink def test_dylink_argv_argc(self): # Verify that argc and argv can be sent to main when main is in a side module - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '--no-entry', '-sINCOMING_MODULE_JS_API=[arguments]'] create_file('pre.js', "Module['arguments'] = ['hello', 'world!']") self.dylink_test( '', # main module is empty. @@ -5424,6 +5428,7 @@ def test_langinfo(self): self.do_core_test('test_langinfo.c') @no_modularize_instance('uses Module object directly') + @no_strict('TODO: Fails in -sSTRICT mode due to an unknown reason.') def test_files(self): # Use closure here, to test we don't break FS stuff if '-O3' in self.emcc_args and self.is_wasm2js(): @@ -5435,7 +5440,7 @@ def test_files(self): else: self.maybe_closure() - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[preRun]'] self.set_setting('FORCE_FILESYSTEM') create_file('pre.js', ''' @@ -5467,7 +5472,7 @@ def test_module_stdin(self): stdout: (x) => out('got: ' + x) }; ''') - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[stdin,stdout]'] src = r''' #include @@ -5916,7 +5921,7 @@ def test_fs_no_main(self): ''') self.set_setting('EXPORTED_FUNCTIONS', '_foo') self.set_setting('FORCE_FILESYSTEM') - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[preRun, onRuntimeInitialized]'] self.do_run('int foo() { return 42; }', '', force_c=True) @also_with_noderawfs @@ -6159,6 +6164,8 @@ def test_posixtime(self): self.do_core_test('test_posixtime.c') def test_uname(self): + if self.get_setting('STRICT'): + self.emcc_args += ['-lstubs'] self.do_core_test('test_uname.c', regex=True) def test_unary_literal(self): @@ -6188,6 +6195,8 @@ def test_stddef(self): self.do_core_test('test_stddef.cpp', force_c=True) def test_getloadavg(self): + if self.get_setting('STRICT'): + self.emcc_args += ['-lstubs'] self.do_core_test('test_getloadavg.c') def test_nl_types(self): @@ -6717,6 +6726,10 @@ def test_gcc_unmangler(self): @needs_make('configure script') @is_slow_test def test_freetype(self): + # Not needed for js, but useful for debugging + shutil.copy(test_file('freetype/LiberationSansBold.ttf'), 'font.ttf') + ftlib = self.get_freetype_library() + if self.get_setting('WASMFS'): self.emcc_args += ['-sFORCE_FILESYSTEM'] @@ -6724,10 +6737,6 @@ def test_freetype(self): list(bytearray(read_binary(test_file('freetype/LiberationSansBold.ttf')))), )) - # Not needed for js, but useful for debugging - shutil.copy(test_file('freetype/LiberationSansBold.ttf'), 'font.ttf') - ftlib = self.get_freetype_library() - # Main self.do_run_in_out_file_test('freetype/main.c', args=['font.ttf', 'test!', '150', '120', '25'], @@ -6763,6 +6772,8 @@ def test_freetype(self): 'pthreads': (True,), }) def test_sqlite(self, use_pthreads): + if self.get_setting('STRICT'): + self.emcc_args += ['-lstubs'] if use_pthreads: self.emcc_args.append('-pthread') self.setup_node_pthreads() @@ -6847,7 +6858,7 @@ def test_poppler(self): out("Data: " + JSON.stringify(FileData.map(function(x) { return unSign(x, 8) }))); }; ''') - self.emcc_args += ['--pre-js', 'pre.js', '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$unSign'] + self.emcc_args += ['--pre-js', 'pre.js', '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$unSign', '-sINCOMING_MODULE_JS_API=[preRun, postRun]'] ppm_data = str(list(bytearray(read_binary(test_file('poppler/ref.ppm'))))) self.do_run('', ppm_data.replace(' ', ''), @@ -6935,7 +6946,7 @@ def image_compare(output): assert diff_mean < 0.01, diff_mean self.emcc_args += ['--minify=0'] # to compare the versions - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[preRun,postRun]'] output = self.do_runf('third_party/openjpeg/codec/j2k_to_image.c', 'Successfully generated', # The real test for valid output is in image_compare @@ -7135,6 +7146,7 @@ def test(output_prefix='', args=None, assert_returncode=0): test(args=['-sFORCE_FILESYSTEM']) @no_modularize_instance('uses Module object directly') + @no_strict('This test verifies legacy behavior that does not apply to -sSTRICT builds.') def test_legacy_exported_runtime_numbers(self): # these used to be exported, but no longer are by default def test(expected, args=None, assert_returncode=0): @@ -7573,7 +7585,7 @@ def test_embind_val_coro(self): create_file('pre.js', r'''Module.onRuntimeInitialized = () => { Module.asyncCoro().then(console.log); }''') - self.emcc_args += ['-std=c++20', '--bind', '--pre-js=pre.js'] + self.emcc_args += ['-std=c++20', '--bind', '--pre-js=pre.js', '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]', '--no-entry'] self.do_runf('embind/test_val_coro.cpp', '34\n') def test_embind_val_coro_caught(self): @@ -7584,7 +7596,7 @@ def test_embind_val_coro_caught(self): err => console.error(`rejected with: ${err.stack}`) ); }''') - self.emcc_args += ['-std=c++20', '--bind', '--pre-js=pre.js', '-fexceptions'] + self.emcc_args += ['-std=c++20', '--bind', '--pre-js=pre.js', '-fexceptions', '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]', '--no-entry'] self.do_runf('embind/test_val_coro.cpp', 'rejected with: std::runtime_error: bang from throwingCoro!\n') def test_embind_dynamic_initialization(self): @@ -7688,6 +7700,7 @@ def test_embind_wasm_workers(self): 'all_growth': ('ALL', True), }) @no_modularize_instance('uses Module global') + @no_strict('TODO: Fails in -sSTRICT mode due to an unknown reason.') def test_webidl(self, mode, allow_memory_growth): self.set_setting('WASM_ASYNC_COMPILATION', 0) if self.maybe_closure(): @@ -8055,7 +8068,7 @@ def test_exit_status(self): assert(status == EXITSTATUS); }; ''') - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[onExit]'] print('.. exit') self.do_runf('exit.c', 'hello, world!\ncleanup\nI see exit status: 117', assert_returncode=117, emcc_args=['-DNORMAL_EXIT']) print('.. _exit') @@ -8172,7 +8185,7 @@ def test_async_ccall_bad(self): } }; ''') - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]'] self.do_runf('main.c', 'The call to main is running asynchronously.') @with_asyncify_and_jspi @@ -8197,7 +8210,7 @@ def test_async_ccall_good(self): ccall('main', null, ['number', 'string'], [2, 'waka'], { async: true }); }; ''') - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]'] self.do_runf('main.c', 'HelloWorld') @parameterized({ @@ -8242,7 +8255,7 @@ def test_async_ccall_promise(self, exit_runtime): }); }; ''') - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]'] self.do_runf('main.c', 'stringf: first\nsecond\n6.4') @no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1') @@ -8582,7 +8595,7 @@ def test_fs_dict(self): out(typeof NODEFS); }; ''') - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[preRun]'] self.do_run('int main() { return 0; }', 'object\nobject\nobject\nobject\nobject\nobject') def test_fs_dict_none(self): @@ -8606,7 +8619,7 @@ def test_fs_dict_none(self): } }; ''') - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[preRun]'] expected = '''\ object undefined @@ -8715,7 +8728,7 @@ def test_postrun_exception(self): def test_postrun_exit_runtime(self): create_file('pre.js', "Module['postRun'] = () => err('post run\\n');") self.set_setting('EXIT_RUNTIME') - self.emcc_args.append('--pre-js=pre.js') + self.emcc_args += ['--pre-js=pre.js', '-sINCOMING_MODULE_JS_API=[postRun]'] self.do_runf('hello_world.c', 'post run') # Tests that building with -sDECLARE_ASM_MODULE_EXPORTS=0 works @@ -9233,7 +9246,7 @@ def test_pthread_exceptions(self): def test_pthread_exit_process(self): self.set_setting('PROXY_TO_PTHREAD') self.set_setting('EXIT_RUNTIME') - self.emcc_args += ['-DEXIT_RUNTIME', '--pre-js', test_file('core/pthread/test_pthread_exit_runtime.pre.js')] + self.emcc_args += ['-DEXIT_RUNTIME', '--pre-js', test_file('core/pthread/test_pthread_exit_runtime.pre.js'), '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized, onExit]'] self.do_run_in_out_file_test('core/pthread/test_pthread_exit_runtime.c', assert_returncode=42) @node_pthreads @@ -9401,6 +9414,10 @@ def test_pthread_dylink_longjmp(self): @needs_dylink @node_pthreads def test_pthread_dylink_main_module_1(self): + # TODO: For some reason, -lhtml5 must be passed in -sSTRICT mode, but can NOT + # be passed when not compiling in -sSTRICT mode. That does not seem intentional? + if self.get_setting('STRICT'): + self.emcc_args += ['-lhtml5'] self.emcc_args += ['-Wno-experimental', '-pthread'] self.set_setting('MAIN_MODULE') self.do_runf('hello_world.c') @@ -9413,7 +9430,7 @@ def test_pthread_dylink_main_module_1(self): def test_Module_dynamicLibraries(self, args): # test that Module.dynamicLibraries works with pthreads self.emcc_args += args - self.emcc_args += ['--pre-js', 'pre.js'] + self.emcc_args += ['--pre-js', 'pre.js', '-sINCOMING_MODULE_JS_API=[dynamicLibraries]'] self.emcc_args += ['--js-library', 'lib.js'] # This test is for setting dynamicLibraries at runtime, so we don't # want emscripten loading `liblib.so` automatically (which it would @@ -9534,7 +9551,7 @@ def test_abort_on_exceptions(self): self.set_setting('ABORT_ON_WASM_EXCEPTIONS') self.set_setting('ALLOW_TABLE_GROWTH') self.set_setting('EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap']) - self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$addFunction']) + self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$addFunction', '$addOnPostRun']) self.emcc_args += ['-lembind', '--post-js', test_file('core/test_abort_on_exceptions_post.js')] self.do_core_test('test_abort_on_exceptions.cpp', interleaved_output=False) @@ -9561,6 +9578,10 @@ def test_abort_on_exceptions_pthreads(self): @needs_dylink def test_gl_main_module(self): + # TODO: For some reason, -lGL must be passed in -sSTRICT mode, but can NOT + # be passed when not compiling in -sSTRICT mode. That does not seem intentional? + if self.get_setting('STRICT'): + self.emcc_args += ['-lGL'] self.set_setting('MAIN_MODULE') self.emcc_args += ['-sGL_ENABLE_GET_PROC_ADDRESS'] self.do_runf('core/test_gl_get_proc_address.c') @@ -9589,6 +9610,8 @@ def test_embind_lib_with_asyncify(self, args): '-sASYNCIFY_IMPORTS=sleep_and_return', '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$ASSERTIONS', '--post-js', test_file('core/embind_lib_with_asyncify.test.js'), + '--no-entry', + '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]', ] self.emcc_args += args self.do_core_test('embind_lib_with_asyncify.cpp')