Skip to content

Commit 58f9c63

Browse files
authored
Fix test_faulthandler for sanitizers (#108245)
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.
1 parent c965cf6 commit 58f9c63

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Lib/test/test_faulthandler.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from test import support
1010
from test.support import os_helper
1111
from test.support import script_helper, is_android
12-
from test.support import skip_if_sanitizer
1312
import tempfile
1413
import unittest
1514
from textwrap import dedent
@@ -64,8 +63,20 @@ def get_output(self, code, filename=None, fd=None):
6463
pass_fds = []
6564
if fd is not None:
6665
pass_fds.append(fd)
66+
env = dict(os.environ)
67+
68+
# Sanitizers must not handle SIGSEGV (ex: for test_enable_fd())
69+
option = 'handle_segv=0'
70+
for name in ('ASAN_OPTIONS', 'MSAN_OPTIONS', 'UBSAN_OPTIONS'):
71+
if name in env:
72+
env[name] += f':{option}'
73+
else:
74+
env[name] = option
75+
6776
with support.SuppressCrashReport():
68-
process = script_helper.spawn_python('-c', code, pass_fds=pass_fds)
77+
process = script_helper.spawn_python('-c', code,
78+
pass_fds=pass_fds,
79+
env=env)
6980
with process:
7081
output, stderr = process.communicate()
7182
exitcode = process.wait()
@@ -304,8 +315,6 @@ def test_gil_released(self):
304315
3,
305316
'Segmentation fault')
306317

307-
@skip_if_sanitizer(memory=True, ub=True, reason="sanitizer "
308-
"builds change crashing process output.")
309318
@skip_segfault_on_android
310319
def test_enable_file(self):
311320
with temporary_filename() as filename:
@@ -321,8 +330,6 @@ def test_enable_file(self):
321330

322331
@unittest.skipIf(sys.platform == "win32",
323332
"subprocess doesn't support pass_fds on Windows")
324-
@skip_if_sanitizer(memory=True, ub=True, reason="sanitizer "
325-
"builds change crashing process output.")
326333
@skip_segfault_on_android
327334
def test_enable_fd(self):
328335
with tempfile.TemporaryFile('wb+') as fp:

0 commit comments

Comments
 (0)