Skip to content
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

Inject minimal_runtime_exit_handling.js as part of also_with_minimal_runtime. NFC #23559

Merged
merged 1 commit into from
Jan 31, 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
3 changes: 3 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,),
Expand Down
52 changes: 11 additions & 41 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
sbc100 marked this conversation as resolved.
Show resolved Hide resolved
@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.')
Expand Down Expand Up @@ -6929,34 +6920,29 @@ 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']),
('FROM_OUTSIDE', ['-sEXPORTED_RUNTIME_METHODS=dynCall_iiji'])
]

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({
'': ([],),
Expand Down Expand Up @@ -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)
Expand All @@ -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({
Expand Down Expand Up @@ -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)
Expand Down