]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix test_faulthandler for sanitizers (#108245)
authorVictor Stinner <vstinner@python.org>
Tue, 22 Aug 2023 01:16:12 +0000 (03:16 +0200)
committerGitHub <noreply@github.com>
Tue, 22 Aug 2023 01:16:12 +0000 (01:16 +0000)
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

index 2e97de592712c099f05ed9daecb0b326672ef6f5..907c2cda86cbae1a6c7c4d0b856fab1df1ca9f65 100644 (file)
@@ -9,7 +9,6 @@ import sys
 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,20 @@ class FaultHandlerTests(unittest.TestCase):
         pass_fds = []
         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'):
+            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)
+            process = script_helper.spawn_python('-c', code,
+                                                 pass_fds=pass_fds,
+                                                 env=env)
             with process:
                 output, stderr = process.communicate()
                 exitcode = process.wait()
@@ -304,8 +315,6 @@ class FaultHandlerTests(unittest.TestCase):
             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 +330,6 @@ class FaultHandlerTests(unittest.TestCase):
 
     @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: