From c1b2a429af0b49f5c7cb23a9d6a8e08e9eeeb349 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 31 Jan 2025 11:16:32 -0800 Subject: [PATCH] Inject `minimal_runtime_exit_handling.js` as part of `also_with_minimal_runtime`. NFC This allows `also_with_minimal_runtime` to be used in more places removing a bunch of duplication. --- test/common.py | 3 +++ test/test_core.py | 52 ++++++++++------------------------------------- 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/test/common.py b/test/common.py index 619d95e26a3c7..54ddac40b763e 100644 --- a/test/common.py +++ b/test/common.py @@ -504,6 +504,9 @@ def metafunc(self, with_minimal_runtime, *args, **kwargs): assert self.get_setting('MINIMAL_RUNTIME') is None if with_minimal_runtime: self.set_setting('MINIMAL_RUNTIME', 1) + # This extra helper code is needed to cleanly handle calls to exit() which throw + # an ExitCode exception. + self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')] f(self, *args, **kwargs) parameterize(metafunc, {'': (False,), diff --git a/test/test_core.py b/test/test_core.py index 05b2719676f8a..cf3615bd2c439 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5596,23 +5596,14 @@ def test_utf8_textdecoder(self): self.do_runf('benchmark/benchmark_utf8.c', 'OK.') # Test that invalid character in UTF8 does not cause decoding to crash. + @also_with_minimal_runtime @parameterized({ - '': [[]], - 'textdecoder': [['-sTEXTDECODER']], + '': ([],), + 'textdecoder': (['-sTEXTDECODER'],), }) def test_utf8_invalid(self, args): self.do_runf('test_utf8_invalid.c', 'OK.', emcc_args=args) - # Test that invalid character in UTF8 does not cause decoding to crash. - @parameterized({ - '': [[]], - 'textdecoder': [['-sTEXTDECODER']], - }) - def test_minimal_runtime_utf8_invalid(self, args): - self.set_setting('MINIMAL_RUNTIME') - self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')] - self.do_runf('test_utf8_invalid.c', 'OK.', emcc_args=args) - def test_utf16_textdecoder(self): self.emcc_args += ['--embed-file', test_file('utf16_corpus.txt') + '@/utf16_corpus.txt'] self.do_runf('benchmark/benchmark_utf16.cpp', 'OK.') @@ -6929,25 +6920,20 @@ def test_EXPORTED_RUNTIME_METHODS(self): self.set_setting('EXPORTED_RUNTIME_METHODS', ['dynCall', 'addFunction', 'lengthBytesUTF8', 'getTempRet0', 'setTempRet0']) self.do_core_test('EXPORTED_RUNTIME_METHODS.c') - @parameterized({ - '': [], - 'minimal_runtime': ['-sMINIMAL_RUNTIME=1'] - }) - def test_dyncall_specific(self, *args): + @also_with_minimal_runtime + def test_dyncall_specific(self): if self.get_setting('MEMORY64'): self.skipTest('not compatible with MEMORY64') if self.get_setting('WASM_BIGINT') != 0 and not self.is_wasm2js(): # define DYNCALLS because this test does test calling them directly, and # in WASM_BIGINT mode we do not enable them by default (since we can do # more without them - we don't need to legalize) - args = list(args) + ['-sDYNCALLS', '-DWASM_BIGINT'] + self.emcc_args += ['-sDYNCALLS', '-DWASM_BIGINT'] cases = [ ('DIRECT', []), ('DYNAMIC_SIG', ['-sDYNCALLS']), ] - if '-sMINIMAL_RUNTIME=1' in args: - self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')] - else: + if self.get_setting('MINIMAL_RUNTIME') == 0: cases += [ ('EXPORTED', []), ('EXPORTED_DYNAMIC_SIG', ['-sDYNCALLS', '-sEXPORTED_RUNTIME_METHODS=dynCall']), @@ -6955,8 +6941,8 @@ def test_dyncall_specific(self, *args): ] for which, extra_args in cases: - print(str(args) + ' ' + which) - self.do_core_test('test_dyncall_specific.c', emcc_args=['-D' + which] + list(args) + extra_args) + print(str(extra_args) + ' ' + which) + self.do_core_test('test_dyncall_specific.c', emcc_args=['-D' + which] + extra_args) @parameterized({ '': ([],), @@ -8600,6 +8586,7 @@ def test_postrun_exit_runtime(self): self.do_runf('hello_world.c', 'post run') # Tests that building with -sDECLARE_ASM_MODULE_EXPORTS=0 works + @also_with_minimal_runtime def test_no_declare_asm_module_exports(self): self.set_setting('DECLARE_ASM_MODULE_EXPORTS', 0) self.set_setting('WASM_ASYNC_COMPILATION', 0) @@ -8617,16 +8604,6 @@ def test_no_declare_asm_module_exports(self): else: print(occurances) - # Tests that building with -sDECLARE_ASM_MODULE_EXPORTS=0 works - @no_wasmfs('https://github.com/emscripten-core/emscripten/issues/16816') - def test_minimal_runtime_no_declare_asm_module_exports(self): - self.set_setting('DECLARE_ASM_MODULE_EXPORTS', 0) - self.set_setting('WASM_ASYNC_COMPILATION', 0) - self.maybe_closure() - self.set_setting('MINIMAL_RUNTIME') - self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')] - self.do_runf('declare_asm_module_exports.c', 'jsFunction: 1') - # Tests that -sMINIMAL_RUNTIME works well in different build modes @no_wasmfs('https://github.com/emscripten-core/emscripten/issues/16816') @parameterized({ @@ -9354,19 +9331,12 @@ def test_Module_dynamicLibraries(self, args): force_c=True) # Tests the emscripten_get_exported_function() API. + @also_with_minimal_runtime def test_get_exported_function(self): self.set_setting('ALLOW_TABLE_GROWTH') self.emcc_args += ['-lexports.js'] self.do_core_test('test_get_exported_function.cpp') - # Tests the emscripten_get_exported_function() API. - def test_minimal_runtime_get_exported_function(self): - self.set_setting('ALLOW_TABLE_GROWTH') - self.set_setting('MINIMAL_RUNTIME') - self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')] - self.emcc_args += ['-lexports.js'] - self.do_core_test('test_get_exported_function.cpp') - # Marked as impure since the WASI reactor modules (modules without main) # are not yet suppored by the wasm engines we test against. @also_with_standalone_wasm(impure=True)