Skip to content

Commit cb0d16c

Browse files
authored
[test] Use with_both_eh_sjlj in test_other.py. NFC (#21559)
Followup to #21554
1 parent a739086 commit cb0d16c

File tree

3 files changed

+46
-68
lines changed

3 files changed

+46
-68
lines changed

test/common.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,40 @@ def metafunc(self, standalone):
465465
return decorated
466466

467467

468+
# Tests exception handling / setjmp/longjmp handling in Emscripten EH/SjLj mode
469+
# and if possible, new wasm EH/SjLj mode. This tests two combinations:
470+
# - Emscripten EH + Emscripten SjLj
471+
# - Wasm EH + Wasm SjLj
472+
def with_both_eh_sjlj(f):
473+
assert callable(f)
474+
475+
def metafunc(self, is_native):
476+
if is_native:
477+
# Wasm EH is currently supported only in wasm backend and V8
478+
if self.is_wasm2js():
479+
self.skipTest('wasm2js does not support wasm EH/SjLj')
480+
self.require_wasm_eh()
481+
# FIXME Temporarily disabled. Enable this later when the bug is fixed.
482+
if '-fsanitize=address' in self.emcc_args:
483+
self.skipTest('Wasm EH does not work with asan yet')
484+
self.emcc_args.append('-fwasm-exceptions')
485+
self.set_setting('SUPPORT_LONGJMP', 'wasm')
486+
f(self)
487+
else:
488+
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
489+
self.set_setting('SUPPORT_LONGJMP', 'emscripten')
490+
# DISABLE_EXCEPTION_CATCHING=0 exports __cxa_can_catch and
491+
# __cxa_is_pointer_type, so if we don't build in C++ mode, wasm-ld will
492+
# error out because libc++abi is not included. See
493+
# https://github.com/emscripten-core/emscripten/pull/14192 for details.
494+
self.set_setting('DEFAULT_TO_CXX')
495+
f(self)
496+
497+
metafunc._parameterize = {'': (False,),
498+
'wasm': (True,)}
499+
return metafunc
500+
501+
468502
# This works just like `with_both_eh_sjlj` above but doesn't enable exceptions.
469503
# Use this for tests that use setjmp/longjmp but not exceptions handling.
470504
def with_both_sjlj(f):

test/test_core.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from common import env_modify, with_env_modify, disabled, flaky, node_pthreads, also_with_wasm_bigint
2929
from common import read_file, read_binary, requires_v8, requires_node, requires_wasm2js, requires_node_canary
3030
from common import compiler_for, crossplatform, no_4gb, no_2gb
31-
from common import with_both_sjlj, also_with_standalone_wasm, can_do_standalone, no_wasm64
31+
from common import with_both_eh_sjlj, with_both_sjlj, also_with_standalone_wasm, can_do_standalone, no_wasm64
3232
from common import NON_ZERO, WEBIDL_BINDER, EMBUILDER, PYTHON
3333
import clang_native
3434

@@ -92,40 +92,6 @@ def decorated(self):
9292
return decorated
9393

9494

95-
# Tests exception handling / setjmp/longjmp handling in Emscripten EH/SjLj mode
96-
# and if possible, new wasm EH/SjLj mode. This tests two combinations:
97-
# - Emscripten EH + Emscripten SjLj
98-
# - Wasm EH + Wasm SjLj
99-
def with_both_eh_sjlj(f):
100-
assert callable(f)
101-
102-
def metafunc(self, is_native):
103-
if is_native:
104-
# Wasm EH is currently supported only in wasm backend and V8
105-
if self.is_wasm2js():
106-
self.skipTest('wasm2js does not support wasm EH/SjLj')
107-
self.require_wasm_eh()
108-
# FIXME Temporarily disabled. Enable this later when the bug is fixed.
109-
if '-fsanitize=address' in self.emcc_args:
110-
self.skipTest('Wasm EH does not work with asan yet')
111-
self.emcc_args.append('-fwasm-exceptions')
112-
self.set_setting('SUPPORT_LONGJMP', 'wasm')
113-
f(self)
114-
else:
115-
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
116-
self.set_setting('SUPPORT_LONGJMP', 'emscripten')
117-
# DISABLE_EXCEPTION_CATCHING=0 exports __cxa_can_catch and
118-
# __cxa_is_pointer_type, so if we don't build in C++ mode, wasm-ld will
119-
# error out because libc++abi is not included. See
120-
# https://github.com/emscripten-core/emscripten/pull/14192 for details.
121-
self.set_setting('DEFAULT_TO_CXX')
122-
f(self)
123-
124-
metafunc._parameterize = {'': (False,),
125-
'wasm': (True,)}
126-
return metafunc
127-
128-
12995
def no_wasm2js(note=''):
13096
assert not callable(note)
13197

test/test_other.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from common import env_modify, no_mac, no_windows, only_windows, requires_native_clang, with_env_modify
3535
from common import create_file, parameterized, NON_ZERO, node_pthreads, TEST_ROOT, test_file
3636
from common import compiler_for, EMBUILDER, requires_v8, requires_node, requires_wasm64, requires_node_canary
37-
from common import requires_wasm_eh, crossplatform, with_both_sjlj, also_with_standalone_wasm
37+
from common import requires_wasm_eh, crossplatform, with_both_eh_sjlj, with_both_sjlj, also_with_standalone_wasm
3838
from common import also_with_minimal_runtime, also_with_wasm_bigint, also_with_wasm64, flaky
3939
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER
4040
from common import requires_network
@@ -8843,11 +8843,8 @@ def test_exceptions_c_linker(self):
88438843
stderr = self.expect_fail([EMCC, '-sSTRICT', test_file('other/test_exceptions_c_linker.c')])
88448844
self.assertContained('error: undefined symbol: __cxa_find_matching_catch_1', stderr)
88458845

8846-
@parameterized({
8847-
'': (False,),
8848-
'wasm': (True,),
8849-
})
8850-
def test_exceptions_stack_trace_and_message(self, wasm_eh):
8846+
@with_both_eh_sjlj
8847+
def test_exceptions_stack_trace_and_message(self):
88518848
src = r'''
88528849
#include <stdexcept>
88538850

@@ -8864,7 +8861,7 @@ def test_exceptions_stack_trace_and_message(self, wasm_eh):
88648861
return 0;
88658862
}
88668863
'''
8867-
self.emcc_args = ['-g']
8864+
self.emcc_args += ['-g']
88688865

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

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

8895-
self.emcc_args += ['-fwasm-exceptions']
8896-
else:
8897-
self.emcc_args += ['-fexceptions']
8898-
88998892
# Stack traces are enabled when either of ASSERTIONS or
89008893
# EXCEPTION_STACK_TRACES is enabled. You can't disable
89018894
# EXCEPTION_STACK_TRACES when ASSERTIONS is enabled.
@@ -8926,23 +8919,16 @@ def test_exceptions_stack_trace_and_message(self, wasm_eh):
89268919
for check in stack_trace_checks:
89278920
self.assertFalse(re.search(check, err), 'Expected regex "%s" to not match on:\n%s' % (check, err))
89288921

8929-
@parameterized({
8930-
'': (False,),
8931-
'wasm': (True,),
8932-
})
8933-
def test_exceptions_rethrow_stack_trace_and_message(self, wasm_eh):
8934-
self.emcc_args = ['-g']
8935-
if wasm_eh:
8922+
@with_both_eh_sjlj
8923+
def test_exceptions_rethrow_stack_trace_and_message(self):
8924+
self.emcc_args += ['-g']
8925+
if '-fwasm-excpeptions' in self.emcc_args:
89368926
# FIXME Node v18.13 (LTS as of Jan 2023) has not yet implemented the new
89378927
# optional 'traceStack' option in WebAssembly.Exception constructor
89388928
# (https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Exception/Exception)
89398929
# and embeds stack traces unconditionally. Change this back to
89408930
# self.require_wasm_eh() if this issue is fixed later.
89418931
self.require_v8()
8942-
self.emcc_args += ['-fwasm-exceptions']
8943-
else:
8944-
self.emcc_args += ['-fexceptions']
8945-
89468932
# Rethrowing exception currently loses the stack trace before the rethrowing
89478933
# due to how rethrowing is implemented. So in the examples below we don't
89488934
# print 'bar' at the moment.
@@ -8998,17 +8984,9 @@ def test_exceptions_rethrow_stack_trace_and_message(self, wasm_eh):
89988984
expected_output=rethrow_stack_trace_checks, regex=True)
89998985
self.assertNotContained('important_function', err)
90008986

9001-
@parameterized({
9002-
'': (False,),
9003-
'wasm': (True,),
9004-
})
9005-
def test_exceptions_exit_runtime(self, wasm_eh):
8987+
@with_both_eh_sjlj
8988+
def test_exceptions_exit_runtime(self):
90068989
self.set_setting('EXIT_RUNTIME')
9007-
if wasm_eh:
9008-
self.require_wasm_eh()
9009-
self.emcc_args.append('-fwasm-exceptions')
9010-
else:
9011-
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
90128990
self.do_other_test('test_exceptions_exit_runtime.cpp')
90138991

90148992
@requires_node

0 commit comments

Comments
 (0)