Skip to content

Commit

Permalink
Inject minimal_runtime_exit_handling.js as part of `also_with_minim…
Browse files Browse the repository at this point in the history
…al_runtime`. NFC

This allows `also_with_minimal_runtime` to be used in more places
removing a bunch of duplication.
  • Loading branch information
sbc100 committed Jan 31, 2025
1 parent b31dd92 commit a44231a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
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
55 changes: 11 additions & 44 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -6931,34 +6921,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 @@ -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)
Expand All @@ -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({
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8470,13 +8470,15 @@ def test_run_order(self):
''')
create_file('src.c', r'''
#include <stdio.h>
#include <stdlib.h>
void foo();
__attribute__((constructor)) void ctor() {
printf("ctor\n");
}
int main() {
printf("main\n");
foo();
exit(0);
}
''')
self.do_runf('src.c', 'addAtInit\nctor\naddAtPostCtor\nmain\n', emcc_args=['--js-library', 'lib.js'])
Expand Down Expand Up @@ -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'])

0 comments on commit a44231a

Please sign in to comment.