From 29cdcce4fc4472892f204cacc4193414af625338 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 22 Aug 2023 01:08:59 +0200 Subject: [PATCH 1/2] Fix test_faulthandler for sanitizers Set environment options to ask sanitizers to not handle SIGSEGV. This change allows running test_enable_fd() and test_enable_file() with sanitizers. Previously, they were skipped. --- Lib/test/test_faulthandler.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index 2e97de592712c0..efa357634f1308 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -9,7 +9,6 @@ from test import support from test.support import os_helper from test.support import script_helper, is_android -from test.support import skip_if_sanitizer import tempfile import unittest from textwrap import dedent @@ -64,8 +63,13 @@ def get_output(self, code, filename=None, fd=None): pass_fds = [] if fd is not None: pass_fds.append(fd) + env = dict(os.environ) + for name in ('ASAN_OPTIONS', 'MSAN_OPTIONS', 'UBSAN_OPTIONS'): + env[name] = 'handle_segv=0' with support.SuppressCrashReport(): - process = script_helper.spawn_python('-c', code, pass_fds=pass_fds) + process = script_helper.spawn_python('-c', code, + pass_fds=pass_fds, + env=env) with process: output, stderr = process.communicate() exitcode = process.wait() @@ -304,8 +308,6 @@ def test_gil_released(self): 3, 'Segmentation fault') - @skip_if_sanitizer(memory=True, ub=True, reason="sanitizer " - "builds change crashing process output.") @skip_segfault_on_android def test_enable_file(self): with temporary_filename() as filename: @@ -321,8 +323,6 @@ def test_enable_file(self): @unittest.skipIf(sys.platform == "win32", "subprocess doesn't support pass_fds on Windows") - @skip_if_sanitizer(memory=True, ub=True, reason="sanitizer " - "builds change crashing process output.") @skip_segfault_on_android def test_enable_fd(self): with tempfile.TemporaryFile('wb+') as fp: From 5c6e2a9442e48c2180b59281d6998ecf4bcb40fd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 22 Aug 2023 02:46:54 +0200 Subject: [PATCH 2/2] Don't override ASAN_OPTIONS options If the env var is already set, add our option at the end. --- Lib/test/test_faulthandler.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index efa357634f1308..907c2cda86cbae 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -64,8 +64,15 @@ def get_output(self, code, filename=None, fd=None): if fd is not None: pass_fds.append(fd) env = dict(os.environ) + + # Sanitizers must not handle SIGSEGV (ex: for test_enable_fd()) + option = 'handle_segv=0' for name in ('ASAN_OPTIONS', 'MSAN_OPTIONS', 'UBSAN_OPTIONS'): - env[name] = 'handle_segv=0' + if name in env: + env[name] += f':{option}' + else: + env[name] = option + with support.SuppressCrashReport(): process = script_helper.spawn_python('-c', code, pass_fds=pass_fds,