Skip to content

Commit a44231a

Browse files
committed
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.
1 parent b31dd92 commit a44231a

File tree

3 files changed

+26
-44
lines changed

3 files changed

+26
-44
lines changed

test/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ def metafunc(self, with_minimal_runtime, *args, **kwargs):
504504
assert self.get_setting('MINIMAL_RUNTIME') is None
505505
if with_minimal_runtime:
506506
self.set_setting('MINIMAL_RUNTIME', 1)
507+
# This extra helper code is needed to cleanly handle calls to exit() which throw
508+
# an ExitCode exception.
509+
self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')]
507510
f(self, *args, **kwargs)
508511

509512
parameterize(metafunc, {'': (False,),

test/test_core.py

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5597,24 +5597,14 @@ def test_utf8_textdecoder(self):
55975597
self.do_runf('benchmark/benchmark_utf8.c', 'OK.')
55985598

55995599
# Test that invalid character in UTF8 does not cause decoding to crash.
5600+
@also_with_minimal_runtime
56005601
@parameterized({
5601-
'': [[]],
5602-
'textdecoder': [['-sTEXTDECODER']],
5602+
'': ([],),
5603+
'textdecoder': (['-sTEXTDECODER'],),
56035604
})
56045605
def test_utf8_invalid(self, args):
56055606
self.do_runf('test_utf8_invalid.c', 'OK.', emcc_args=args)
56065607

5607-
# Test that invalid character in UTF8 does not cause decoding to crash.
5608-
@no_asan('TODO: ASan support in minimal runtime')
5609-
@parameterized({
5610-
'': [[]],
5611-
'textdecoder': [['-sTEXTDECODER']],
5612-
})
5613-
def test_minimal_runtime_utf8_invalid(self, args):
5614-
self.set_setting('MINIMAL_RUNTIME')
5615-
self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')]
5616-
self.do_runf('test_utf8_invalid.c', 'OK.', emcc_args=args)
5617-
56185608
def test_utf16_textdecoder(self):
56195609
self.emcc_args += ['--embed-file', test_file('utf16_corpus.txt') + '@/utf16_corpus.txt']
56205610
self.do_runf('benchmark/benchmark_utf16.cpp', 'OK.')
@@ -6931,34 +6921,29 @@ def test_EXPORTED_RUNTIME_METHODS(self):
69316921
self.set_setting('EXPORTED_RUNTIME_METHODS', ['dynCall', 'addFunction', 'lengthBytesUTF8', 'getTempRet0', 'setTempRet0'])
69326922
self.do_core_test('EXPORTED_RUNTIME_METHODS.c')
69336923

6934-
@parameterized({
6935-
'': [],
6936-
'minimal_runtime': ['-sMINIMAL_RUNTIME=1']
6937-
})
6938-
def test_dyncall_specific(self, *args):
6924+
@also_with_minimal_runtime
6925+
def test_dyncall_specific(self):
69396926
if self.get_setting('MEMORY64'):
69406927
self.skipTest('not compatible with MEMORY64')
69416928
if self.get_setting('WASM_BIGINT') != 0 and not self.is_wasm2js():
69426929
# define DYNCALLS because this test does test calling them directly, and
69436930
# in WASM_BIGINT mode we do not enable them by default (since we can do
69446931
# more without them - we don't need to legalize)
6945-
args = list(args) + ['-sDYNCALLS', '-DWASM_BIGINT']
6932+
self.emcc_args += ['-sDYNCALLS', '-DWASM_BIGINT']
69466933
cases = [
69476934
('DIRECT', []),
69486935
('DYNAMIC_SIG', ['-sDYNCALLS']),
69496936
]
6950-
if '-sMINIMAL_RUNTIME=1' in args:
6951-
self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')]
6952-
else:
6937+
if self.get_setting('MINIMAL_RUNTIME') == 0:
69536938
cases += [
69546939
('EXPORTED', []),
69556940
('EXPORTED_DYNAMIC_SIG', ['-sDYNCALLS', '-sEXPORTED_RUNTIME_METHODS=dynCall']),
69566941
('FROM_OUTSIDE', ['-sEXPORTED_RUNTIME_METHODS=dynCall_iiji'])
69576942
]
69586943

69596944
for which, extra_args in cases:
6960-
print(str(args) + ' ' + which)
6961-
self.do_core_test('test_dyncall_specific.c', emcc_args=['-D' + which] + list(args) + extra_args)
6945+
print(str(extra_args) + ' ' + which)
6946+
self.do_core_test('test_dyncall_specific.c', emcc_args=['-D' + which] + extra_args)
69626947

69636948
@parameterized({
69646949
'': ([],),
@@ -8602,6 +8587,7 @@ def test_postrun_exit_runtime(self):
86028587
self.do_runf('hello_world.c', 'post run')
86038588

86048589
# Tests that building with -sDECLARE_ASM_MODULE_EXPORTS=0 works
8590+
@also_with_minimal_runtime
86058591
def test_no_declare_asm_module_exports(self):
86068592
self.set_setting('DECLARE_ASM_MODULE_EXPORTS', 0)
86078593
self.set_setting('WASM_ASYNC_COMPILATION', 0)
@@ -8619,17 +8605,6 @@ def test_no_declare_asm_module_exports(self):
86198605
else:
86208606
print(occurances)
86218607

8622-
# Tests that building with -sDECLARE_ASM_MODULE_EXPORTS=0 works
8623-
@no_wasmfs('https://github.com/emscripten-core/emscripten/issues/16816')
8624-
@no_asan('TODO: ASan support in minimal runtime')
8625-
def test_minimal_runtime_no_declare_asm_module_exports(self):
8626-
self.set_setting('DECLARE_ASM_MODULE_EXPORTS', 0)
8627-
self.set_setting('WASM_ASYNC_COMPILATION', 0)
8628-
self.maybe_closure()
8629-
self.set_setting('MINIMAL_RUNTIME')
8630-
self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')]
8631-
self.do_runf('declare_asm_module_exports.c', 'jsFunction: 1')
8632-
86338608
# Tests that -sMINIMAL_RUNTIME works well in different build modes
86348609
@no_wasmfs('https://github.com/emscripten-core/emscripten/issues/16816')
86358610
@parameterized({
@@ -9359,20 +9334,12 @@ def test_Module_dynamicLibraries(self, args):
93599334
force_c=True)
93609335

93619336
# Tests the emscripten_get_exported_function() API.
9337+
@also_with_minimal_runtime
93629338
def test_get_exported_function(self):
93639339
self.set_setting('ALLOW_TABLE_GROWTH')
93649340
self.emcc_args += ['-lexports.js']
93659341
self.do_core_test('test_get_exported_function.cpp')
93669342

9367-
# Tests the emscripten_get_exported_function() API.
9368-
@no_asan('TODO: ASan support in minimal runtime')
9369-
def test_minimal_runtime_get_exported_function(self):
9370-
self.set_setting('ALLOW_TABLE_GROWTH')
9371-
self.set_setting('MINIMAL_RUNTIME')
9372-
self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')]
9373-
self.emcc_args += ['-lexports.js']
9374-
self.do_core_test('test_get_exported_function.cpp')
9375-
93769343
# Marked as impure since the WASI reactor modules (modules without main)
93779344
# are not yet suppored by the wasm engines we test against.
93789345
@also_with_standalone_wasm(impure=True)

test/test_other.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8470,13 +8470,15 @@ def test_run_order(self):
84708470
''')
84718471
create_file('src.c', r'''
84728472
#include <stdio.h>
8473+
#include <stdlib.h>
84738474
void foo();
84748475
__attribute__((constructor)) void ctor() {
84758476
printf("ctor\n");
84768477
}
84778478
int main() {
84788479
printf("main\n");
84798480
foo();
8481+
exit(0);
84808482
}
84818483
''')
84828484
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):
1553915541
}
1554015542
''')
1554115543
self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++20', '-fmodules'])
15544+
15545+
def test_cxx20_modules_std(self):
15546+
create_file('main.cpp', r'''
15547+
import std;
15548+
int main(void) {
15549+
std::cout << "Hello world" << std::endl;
15550+
return 0;
15551+
}
15552+
''')
15553+
self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++23', '-fmodules', '-fbuiltin-module-map'])

0 commit comments

Comments
 (0)