Skip to content

Commit

Permalink
[EH] Add more manual tests for new Wasm EH (#21913)
Browse files Browse the repository at this point in the history
The testing mode for the new Wasm EH (exnref) was added in
`with_all_eh_sjlj` and `with_all_sjlj` in #21906. But this adds the new
Wasm EH test mode for more tests that are not covered by those
decorators.
  • Loading branch information
aheejin authored May 10, 2024
1 parent 2a08958 commit 7e7c057
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 9 deletions.
11 changes: 11 additions & 0 deletions test/other/metadce/test_metadce_cxx_except_wasm_exnref.exports
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__indirect_function_table
__trap
__wasm_call_ctors
_emscripten_stack_alloc
dynCall_iiiiiijj
dynCall_iiiiij
dynCall_iiiiijj
dynCall_jiji
dynCall_viijii
main
memory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9807
10 changes: 10 additions & 0 deletions test/other/metadce/test_metadce_cxx_except_wasm_exnref.imports
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
env._abort_js
env._emscripten_memcpy_js
env.emscripten_resize_heap
env.strftime_l
wasi_snapshot_preview1.environ_get
wasi_snapshot_preview1.environ_sizes_get
wasi_snapshot_preview1.fd_close
wasi_snapshot_preview1.fd_read
wasi_snapshot_preview1.fd_seek
wasi_snapshot_preview1.fd_write
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24140
10 changes: 10 additions & 0 deletions test/other/metadce/test_metadce_cxx_except_wasm_exnref.sent
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_abort_js
_emscripten_memcpy_js
emscripten_resize_heap
environ_get
environ_sizes_get
fd_close
fd_read
fd_seek
fd_write
strftime_l
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
141975
14 changes: 11 additions & 3 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from common import env_modify, with_env_modify, disabled, flaky, node_pthreads, also_with_wasm_bigint
from common import read_file, read_binary, requires_v8, requires_node, requires_wasm2js, requires_node_canary
from common import compiler_for, crossplatform, no_4gb, no_2gb, also_with_minimal_runtime
from common import with_all_eh_sjlj, with_all_sjlj, also_with_standalone_wasm, can_do_standalone, no_wasm64
from common import with_all_eh_sjlj, with_all_sjlj, also_with_standalone_wasm, can_do_standalone, no_wasm64, requires_wasm_exnref
from common import NON_ZERO, WEBIDL_BINDER, EMBUILDER, PYTHON
import clang_native

Expand Down Expand Up @@ -896,6 +896,7 @@ def test_longjmp_zero(self):
self.skipTest('https://github.com/emscripten-core/emscripten/issues/21533')
self.do_core_test('test_longjmp_zero.c')

@requires_wasm_exnref
def test_longjmp_with_and_without_exceptions(self):
# Emscripten SjLj with and without Emscripten EH support
self.set_setting('SUPPORT_LONGJMP', 'emscripten')
Expand All @@ -908,13 +909,15 @@ def test_longjmp_with_and_without_exceptions(self):
self.set_setting('SUPPORT_LONGJMP', 'wasm')
if self.is_wasm2js():
self.skipTest('wasm2js does not support wasm EH/SjLj')
self.require_wasm_eh()
# FIXME Temporarily disabled. Enable this later when the bug is fixed.
if '-fsanitize=address' in self.emcc_args:
self.skipTest('Wasm EH does not work with asan yet')
self.emcc_args.append('-fwasm-exceptions')
for arg in ['-fwasm-exceptions', '-fno-exceptions']:
self.do_core_test('test_longjmp.c', emcc_args=[arg])
# Wasm SjLj with and with new EH (exnref) support
self.set_setting('WASM_EXNREF')
self.do_core_test('test_longjmp.c', emcc_args=['-fwasm-exceptions'])

@with_all_sjlj
def test_longjmp2(self):
Expand Down Expand Up @@ -1031,6 +1034,7 @@ def test_exceptions(self):
self.maybe_closure()
self.do_run_in_out_file_test('core/test_exceptions.cpp', out_suffix='_caught')

@requires_wasm_exnref
def test_exceptions_with_and_without_longjmp(self):
self.set_setting('EXCEPTION_DEBUG')
self.maybe_closure()
Expand All @@ -1043,14 +1047,18 @@ def test_exceptions_with_and_without_longjmp(self):
self.clear_setting('DISABLE_EXCEPTION_CATCHING')
if self.is_wasm2js():
self.skipTest('wasm2js does not support wasm EH/SjLj')
self.require_wasm_eh()
# FIXME Temporarily disabled. Enable this later when the bug is fixed.
if '-fsanitize=address' in self.emcc_args:
self.skipTest('Wasm EH does not work with asan yet')
self.emcc_args.append('-fwasm-exceptions')
for support_longjmp in [0, 'wasm']:
self.set_setting('SUPPORT_LONGJMP', support_longjmp)
self.do_run_in_out_file_test('core/test_exceptions.cpp', out_suffix='_caught')
# Wasm new EH (exnref) with and without Wasm SjLj support
self.set_setting('WASM_EXNREF')
for support_longjmp in [0, 'wasm']:
self.set_setting('SUPPORT_LONGJMP', support_longjmp)
self.do_run_in_out_file_test('core/test_exceptions.cpp', out_suffix='_caught')

def test_exceptions_off(self):
self.set_setting('DISABLE_EXCEPTION_CATCHING')
Expand Down
26 changes: 20 additions & 6 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from common import env_modify, no_mac, no_windows, only_windows, requires_native_clang, with_env_modify
from common import create_file, parameterized, NON_ZERO, node_pthreads, TEST_ROOT, test_file
from common import compiler_for, EMBUILDER, requires_v8, requires_node, requires_wasm64, requires_node_canary
from common import requires_wasm_eh, crossplatform, with_all_eh_sjlj, with_all_sjlj
from common import requires_wasm_exnref, crossplatform, with_all_eh_sjlj, with_all_sjlj
from common import also_with_standalone_wasm, also_with_env_modify, also_with_wasm2js
from common import also_with_minimal_runtime, also_with_wasm_bigint, also_with_wasm64, flaky
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER
Expand Down Expand Up @@ -3295,13 +3295,19 @@ def test_embind_tsgen_memory64(self):
self.get_emcc_args())
self.assertFileContents(test_file('other/embind_tsgen_memory64.d.ts'), read_file('embind_tsgen_memory64.d.ts'))

def test_embind_tsgen_exceptions(self):
@parameterized({
'': [0],
'wasm_exnref': [1]
})
def test_embind_tsgen_exceptions(self, wasm_exnref):
self.set_setting('WASM_EXNREF', wasm_exnref)
# Check that when Wasm exceptions and assertions are enabled bindings still generate.
self.run_process([EMXX, test_file('other/embind_tsgen.cpp'),
'-lembind', '-fwasm-exceptions', '-sASSERTIONS',
# Use the deprecated `--embind-emit-tsd` to ensure it
# still works until removed.
'--embind-emit-tsd', 'embind_tsgen.d.ts', '-Wno-deprecated'])
'--embind-emit-tsd', 'embind_tsgen.d.ts', '-Wno-deprecated'] +
self.get_emcc_args())
self.assertFileContents(test_file('other/embind_tsgen.d.ts'), read_file('embind_tsgen.d.ts'))

def test_embind_jsgen_method_pointer_stability(self):
Expand Down Expand Up @@ -8529,6 +8535,7 @@ def test_metadce_minimal_pthreads(self):
'-sDEMANGLE_SUPPORT', '-Wno-deprecated'], [], ['waka']), # noqa
# Wasm EH's code size increase is smaller than that of Emscripten EH
'except_wasm': (['-O2', '-fwasm-exceptions'], [], ['waka']), # noqa
'except_wasm_exnref': (['-O2', '-fwasm-exceptions', '-sWASM_EXNREF'], [], ['waka']), # noqa
# eval_ctors 1 can partially optimize, but runs into getenv() for locale
# code. mode 2 ignores those and fully optimizes out the ctors
'ctors1': (['-O2', '-sEVAL_CTORS'], [], ['waka']), # noqa
Expand Down Expand Up @@ -8828,7 +8835,8 @@ def test_lto(self, args):
@parameterized({
'noexcept': [],
'except': ['-sDISABLE_EXCEPTION_CATCHING=0'],
'except_wasm': ['-fwasm-exceptions']
'except_wasm': ['-fwasm-exceptions'],
'except_wasm_exnref': ['-fwasm-exceptions', '-sWASM_EXNREF']
})
def test_lto_libcxx(self, *args):
self.run_process([EMXX, test_file('hello_libcxx.cpp'), '-flto'] + list(args))
Expand All @@ -8847,11 +8855,14 @@ def test_lto_flags(self):

# We have LTO tests covered in 'wasmltoN' targets in test_core.py, but they
# don't run as a part of Emscripten CI, so we add a separate LTO test here.
@requires_wasm_eh
@requires_wasm_exnref
def test_lto_wasm_exceptions(self):
self.set_setting('EXCEPTION_DEBUG')
self.emcc_args += ['-fwasm-exceptions', '-flto']
self.do_run_in_out_file_test('core/test_exceptions.cpp', out_suffix='_caught')
# New Wasm EH with exnref
self.set_setting('WASM_EXNREF')
self.do_run_in_out_file_test('core/test_exceptions.cpp', out_suffix='_caught')

@parameterized({
'': ([],),
Expand Down Expand Up @@ -12267,13 +12278,16 @@ def test_standalone_export_main(self):
# We should consider making this a warning since the `_main` export is redundant.
self.run_process([EMCC, '-sEXPORTED_FUNCTIONS=_main', '-sSTANDALONE_WASM', test_file('core/test_hello_world.c')])

@requires_wasm_eh
@requires_wasm_exnref
def test_standalone_wasm_exceptions(self):
self.set_setting('STANDALONE_WASM')
self.set_setting('WASM_BIGINT')
self.wasm_engines = []
self.emcc_args += ['-fwasm-exceptions']
self.do_run_in_out_file_test('core/test_exceptions.cpp', out_suffix='_caught')
# New Wasm EH with exnref
self.set_setting('WASM_EXNREF')
self.do_run_in_out_file_test('core/test_exceptions.cpp', out_suffix='_caught')

def test_missing_malloc_export(self):
# we used to include malloc by default. show a clear error in builds with
Expand Down

0 comments on commit 7e7c057

Please sign in to comment.