From cb0d16c6de9778cb95016cc5e06a77b0aa1d83cb Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 18 Mar 2024 16:00:12 -0700 Subject: [PATCH] [test] Use with_both_eh_sjlj in test_other.py. NFC (#21559) Followup to #21554 --- test/common.py | 34 ++++++++++++++++++++++++++++++++++ test/test_core.py | 36 +----------------------------------- test/test_other.py | 44 +++++++++++--------------------------------- 3 files changed, 46 insertions(+), 68 deletions(-) diff --git a/test/common.py b/test/common.py index 43aa9f56bc86d..48521757b40e4 100644 --- a/test/common.py +++ b/test/common.py @@ -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): diff --git a/test/test_core.py b/test/test_core.py index 926cf96c2758d..f8141e97df301 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -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 @@ -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) diff --git a/test/test_other.py b/test/test_other.py index c2f2575d7098c..0e66e719fa6de 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -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 @@ -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 @@ -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 @@ -8884,7 +8881,7 @@ 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) @@ -8892,10 +8889,6 @@ def test_exceptions_stack_trace_and_message(self, wasm_eh): # 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. @@ -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. @@ -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