Skip to content

Commit

Permalink
[test] Use with_both_eh_sjlj in test_other.py. NFC (emscripten-core#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Mar 18, 2024
1 parent a739086 commit cb0d16c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 68 deletions.
34 changes: 34 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,40 @@ def metafunc(self, standalone):
return decorated


# Tests exception handling / setjmp/longjmp handling in Emscripten EH/SjLj mode
# and if possible, new wasm EH/SjLj mode. This tests two combinations:
# - Emscripten EH + Emscripten SjLj
# - Wasm EH + Wasm SjLj
def with_both_eh_sjlj(f):
assert callable(f)

def metafunc(self, is_native):
if is_native:
# Wasm EH is currently supported only in wasm backend and V8
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')
self.set_setting('SUPPORT_LONGJMP', 'wasm')
f(self)
else:
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
self.set_setting('SUPPORT_LONGJMP', 'emscripten')
# DISABLE_EXCEPTION_CATCHING=0 exports __cxa_can_catch and
# __cxa_is_pointer_type, so if we don't build in C++ mode, wasm-ld will
# error out because libc++abi is not included. See
# https://github.com/emscripten-core/emscripten/pull/14192 for details.
self.set_setting('DEFAULT_TO_CXX')
f(self)

metafunc._parameterize = {'': (False,),
'wasm': (True,)}
return metafunc


# This works just like `with_both_eh_sjlj` above but doesn't enable exceptions.
# Use this for tests that use setjmp/longjmp but not exceptions handling.
def with_both_sjlj(f):
Expand Down
36 changes: 1 addition & 35 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
from common import with_both_sjlj, also_with_standalone_wasm, can_do_standalone, no_wasm64
from common import with_both_eh_sjlj, with_both_sjlj, also_with_standalone_wasm, can_do_standalone, no_wasm64
from common import NON_ZERO, WEBIDL_BINDER, EMBUILDER, PYTHON
import clang_native

Expand Down Expand Up @@ -92,40 +92,6 @@ def decorated(self):
return decorated


# Tests exception handling / setjmp/longjmp handling in Emscripten EH/SjLj mode
# and if possible, new wasm EH/SjLj mode. This tests two combinations:
# - Emscripten EH + Emscripten SjLj
# - Wasm EH + Wasm SjLj
def with_both_eh_sjlj(f):
assert callable(f)

def metafunc(self, is_native):
if is_native:
# Wasm EH is currently supported only in wasm backend and V8
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')
self.set_setting('SUPPORT_LONGJMP', 'wasm')
f(self)
else:
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
self.set_setting('SUPPORT_LONGJMP', 'emscripten')
# DISABLE_EXCEPTION_CATCHING=0 exports __cxa_can_catch and
# __cxa_is_pointer_type, so if we don't build in C++ mode, wasm-ld will
# error out because libc++abi is not included. See
# https://github.com/emscripten-core/emscripten/pull/14192 for details.
self.set_setting('DEFAULT_TO_CXX')
f(self)

metafunc._parameterize = {'': (False,),
'wasm': (True,)}
return metafunc


def no_wasm2js(note=''):
assert not callable(note)

Expand Down
44 changes: 11 additions & 33 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_both_sjlj, also_with_standalone_wasm
from common import requires_wasm_eh, crossplatform, with_both_eh_sjlj, with_both_sjlj, also_with_standalone_wasm
from common import also_with_minimal_runtime, also_with_wasm_bigint, also_with_wasm64, flaky
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER
from common import requires_network
Expand Down Expand Up @@ -8843,11 +8843,8 @@ def test_exceptions_c_linker(self):
stderr = self.expect_fail([EMCC, '-sSTRICT', test_file('other/test_exceptions_c_linker.c')])
self.assertContained('error: undefined symbol: __cxa_find_matching_catch_1', stderr)

@parameterized({
'': (False,),
'wasm': (True,),
})
def test_exceptions_stack_trace_and_message(self, wasm_eh):
@with_both_eh_sjlj
def test_exceptions_stack_trace_and_message(self):
src = r'''
#include <stdexcept>

Expand All @@ -8864,7 +8861,7 @@ def test_exceptions_stack_trace_and_message(self, wasm_eh):
return 0;
}
'''
self.emcc_args = ['-g']
self.emcc_args += ['-g']

# Stack trace and message example for this example code:
# exiting due to exception: [object WebAssembly.Exception],Error: std::runtime_error,my message
Expand All @@ -8884,18 +8881,14 @@ def test_exceptions_stack_trace_and_message(self, wasm_eh):
'at (src.wasm.)?foo',
'at (src.wasm.)?main']

if wasm_eh:
if '-fwasm-excpeptions' in self.emcc_args:
# FIXME Node v18.13 (LTS as of Jan 2023) has not yet implemented the new
# optional 'traceStack' option in WebAssembly.Exception constructor
# (https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Exception/Exception)
# and embeds stack traces unconditionally. Change this back to
# self.require_wasm_eh() if this issue is fixed later.
self.require_v8()

self.emcc_args += ['-fwasm-exceptions']
else:
self.emcc_args += ['-fexceptions']

# Stack traces are enabled when either of ASSERTIONS or
# EXCEPTION_STACK_TRACES is enabled. You can't disable
# EXCEPTION_STACK_TRACES when ASSERTIONS is enabled.
Expand Down Expand Up @@ -8926,23 +8919,16 @@ def test_exceptions_stack_trace_and_message(self, wasm_eh):
for check in stack_trace_checks:
self.assertFalse(re.search(check, err), 'Expected regex "%s" to not match on:\n%s' % (check, err))

@parameterized({
'': (False,),
'wasm': (True,),
})
def test_exceptions_rethrow_stack_trace_and_message(self, wasm_eh):
self.emcc_args = ['-g']
if wasm_eh:
@with_both_eh_sjlj
def test_exceptions_rethrow_stack_trace_and_message(self):
self.emcc_args += ['-g']
if '-fwasm-excpeptions' in self.emcc_args:
# FIXME Node v18.13 (LTS as of Jan 2023) has not yet implemented the new
# optional 'traceStack' option in WebAssembly.Exception constructor
# (https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Exception/Exception)
# and embeds stack traces unconditionally. Change this back to
# self.require_wasm_eh() if this issue is fixed later.
self.require_v8()
self.emcc_args += ['-fwasm-exceptions']
else:
self.emcc_args += ['-fexceptions']

# Rethrowing exception currently loses the stack trace before the rethrowing
# due to how rethrowing is implemented. So in the examples below we don't
# print 'bar' at the moment.
Expand Down Expand Up @@ -8998,17 +8984,9 @@ def test_exceptions_rethrow_stack_trace_and_message(self, wasm_eh):
expected_output=rethrow_stack_trace_checks, regex=True)
self.assertNotContained('important_function', err)

@parameterized({
'': (False,),
'wasm': (True,),
})
def test_exceptions_exit_runtime(self, wasm_eh):
@with_both_eh_sjlj
def test_exceptions_exit_runtime(self):
self.set_setting('EXIT_RUNTIME')
if wasm_eh:
self.require_wasm_eh()
self.emcc_args.append('-fwasm-exceptions')
else:
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
self.do_other_test('test_exceptions_exit_runtime.cpp')

@requires_node
Expand Down

0 comments on commit cb0d16c

Please sign in to comment.