From a44231ae38ee69cbe31bfcdbf6e017350e37a437 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 | 55 ++++++++++------------------------------------ test/test_other.py | 12 ++++++++++ 3 files changed, 26 insertions(+), 44 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 f3122613c43e8..e1d896ffbcecd 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5597,24 +5597,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. - @no_asan('TODO: ASan support in minimal runtime') - @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.') @@ -6931,25 +6921,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']), @@ -6957,8 +6942,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({ '': ([],), @@ -8602,6 +8587,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) @@ -8619,17 +8605,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') - @no_asan('TODO: ASan support in minimal runtime') - 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({ @@ -9359,20 +9334,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. - @no_asan('TODO: ASan support in minimal runtime') - 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) diff --git a/test/test_other.py b/test/test_other.py index 067cce39f5311..e5a15e531ab66 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -8470,6 +8470,7 @@ def test_run_order(self): ''') create_file('src.c', r''' #include + #include void foo(); __attribute__((constructor)) void ctor() { printf("ctor\n"); @@ -8477,6 +8478,7 @@ def test_run_order(self): int main() { printf("main\n"); foo(); + exit(0); } ''') self.do_runf('src.c', 'addAtInit\nctor\naddAtPostCtor\nmain\n', emcc_args=['--js-library', 'lib.js']) @@ -15539,3 +15541,13 @@ def test_cxx20_modules_std_headers(self): } ''') self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++20', '-fmodules']) + + def test_cxx20_modules_std(self): + create_file('main.cpp', r''' + import std; + int main(void) { + std::cout << "Hello world" << std::endl; + return 0; + } + ''') + self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++23', '-fmodules', '-fbuiltin-module-map'])