]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-46633: Skip tests on ASAN and/or MSAN builds (GH-31632) (GH-31634)
authorVictor Stinner <vstinner@python.org>
Wed, 2 Mar 2022 16:05:14 +0000 (17:05 +0100)
committerGitHub <noreply@github.com>
Wed, 2 Mar 2022 16:05:14 +0000 (17:05 +0100)
* Refactor sanitiser skip tests into test.support (GH-30889)

* Refactor sanitizer skip tests into test.support

(cherry picked from commit b1cb8430504931f7854eac5d32cba74770078a4e)

* Add skips to crashing tests under sanitizers instead of manually skipping them (GH-30897)

(cherry picked from commit a27505345e34d462139f5f8b6b5e7c9a59955150)

* bpo-46633: Skip tests on ASAN and/or MSAN builds (GH-31632)

Skip tests on ASAN and/or MSAN builds:

* multiprocessing tests
* test___all__
* test_concurrent_futures
* test_decimal
* test_peg_generator
* test_tools

(cherry picked from commit 9204bb72a2da5885facc747e63d2bd2d654606fe)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
14 files changed:
Lib/test/_test_multiprocessing.py
Lib/test/support/__init__.py
Lib/test/test___all__.py
Lib/test/test_concurrent_futures.py
Lib/test/test_crypt.py
Lib/test/test_decimal.py
Lib/test/test_faulthandler.py
Lib/test/test_idle.py
Lib/test/test_io.py
Lib/test/test_peg_generator/__init__.py
Lib/test/test_tix.py
Lib/test/test_tk.py
Lib/test/test_tools/__init__.py
Lib/test/test_ttk_guionly.py

index 3bc5b8f3d79b02c3df5dbc705ddfd1a91d3c1696..04657c08db92c04001aac5a0062e72c5992a44ba 100644 (file)
@@ -73,6 +73,12 @@ except ImportError:
     msvcrt = None
 
 
+if support.check_sanitizer(address=True):
+    # bpo-45200: Skip multiprocessing tests if Python is built with ASAN to
+    # work around a libasan race condition: dead lock in pthread_create().
+    raise unittest.SkipTest("libasan has a pthread_create() dead lock")
+
+
 def latin(s):
     return s.encode('latin')
 
index 44c5bd5820a75e2debee2eb4ed765ece4e1139ee..ed6f1979732d3bcbb4c2ac0e03518ecf0392bb88 100644 (file)
@@ -41,7 +41,7 @@ __all__ = [
     "requires_IEEE_754", "requires_zlib",
     "anticipate_failure", "load_package_tests", "detect_api_mismatch",
     "check__all__", "skip_if_buggy_ucrt_strfptime",
-    "check_disallow_instantiation",
+    "check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
     # sys
     "is_jython", "is_android", "check_impl_detail", "unix_shell",
     "setswitchinterval",
@@ -367,6 +367,41 @@ def requires_mac_ver(*min_version):
     return decorator
 
 
+def check_sanitizer(*, address=False, memory=False, ub=False):
+    """Returns True if Python is compiled with sanitizer support"""
+    if not (address or memory or ub):
+        raise ValueError('At least one of address, memory, or ub must be True')
+
+
+    _cflags = sysconfig.get_config_var('CFLAGS') or ''
+    _config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
+    memory_sanitizer = (
+        '-fsanitize=memory' in _cflags or
+        '--with-memory-sanitizer' in _config_args
+    )
+    address_sanitizer = (
+        '-fsanitize=address' in _cflags or
+        '--with-memory-sanitizer' in _config_args
+    )
+    ub_sanitizer = (
+        '-fsanitize=undefined' in _cflags or
+        '--with-undefined-behavior-sanitizer' in _config_args
+    )
+    return (
+        (memory and memory_sanitizer) or
+        (address and address_sanitizer) or
+        (ub and ub_sanitizer)
+    )
+
+
+def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False):
+    """Decorator raising SkipTest if running with a sanitizer active."""
+    if not reason:
+        reason = 'not working with sanitizers active'
+    skip = check_sanitizer(address=address, memory=memory, ub=ub)
+    return unittest.skipIf(skip, reason)
+
+
 def system_must_validate_cert(f):
     """Skip the test on TLS certificate validation failures."""
     @functools.wraps(f)
index 15f42d2d114a68629182d539163a941eb0b8921e..6368ef02253b6d6f267407d7f78b9cfa0bf8d9c7 100644 (file)
@@ -5,6 +5,13 @@ import os
 import sys
 
 
+if support.check_sanitizer(address=True, memory=True):
+    # bpo-46633: test___all__ is skipped because importing some modules
+    # directly can trigger known problems with ASAN (like tk or crypt).
+    raise unittest.SkipTest("workaround ASAN build issues on loading tests "
+                            "like tk or crypt")
+
+
 class NoAll(RuntimeError):
     pass
 
index 29e041deeca57f7bac8642964d467fab93d92c11..50fa1f189b174f6b89616fd2267252007dccbe72 100644 (file)
@@ -32,6 +32,12 @@ import multiprocessing.process
 import multiprocessing.util
 
 
+if support.check_sanitizer(address=True, memory=True):
+    # bpo-46633: Skip the test because it is too slow when Python is built
+    # with ASAN/MSAN: between 5 and 20 minutes on GitHub Actions.
+    raise unittest.SkipTest("test too slow on ASAN/MSAN build")
+
+
 def create_future(state=PENDING, exception=None, result=None):
     f = Future()
     f._state = state
index 5dc83b4ecbfa008d78d41ef2d51bd1784ba2d111..877c575c5534ae76bdfec11f85394bb1f29a6ee6 100644 (file)
@@ -1,8 +1,11 @@
 import sys
 import unittest
+from test.support import check_sanitizer
 
 
 try:
+    if check_sanitizer(address=True, memory=True):
+        raise unittest.SkipTest("The crypt module SEGFAULTs on ASAN/MSAN builds")
     import crypt
     IMPORT_ERROR = None
 except ImportError as ex:
index b6173a5ffec96c46e24fba6d36d410ed89592fa3..310c105d9a0e8fa684c18a900f1a48088428b629 100644 (file)
@@ -34,7 +34,7 @@ import numbers
 import locale
 from test.support import (run_unittest, run_doctest, is_resource_enabled,
                           requires_IEEE_754, requires_docstrings,
-                          requires_legacy_unicode_capi)
+                          requires_legacy_unicode_capi, check_sanitizer)
 from test.support import (TestFailed,
                           run_with_locale, cpython_only,
                           darwin_malloc_err_warning)
@@ -43,17 +43,6 @@ from test.support import warnings_helper
 import random
 import inspect
 import threading
-import sysconfig
-_cflags = sysconfig.get_config_var('CFLAGS') or ''
-_config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
-MEMORY_SANITIZER = (
-    '-fsanitize=memory' in _cflags or
-    '--with-memory-sanitizer' in _config_args
-)
-
-ADDRESS_SANITIZER = (
-    '-fsanitize=address' in _cflags
-)
 
 
 if sys.platform == 'darwin':
@@ -5511,7 +5500,8 @@ class CWhitebox(unittest.TestCase):
     # Issue 41540:
     @unittest.skipIf(sys.platform.startswith("aix"),
                      "AIX: default ulimit: test is flaky because of extreme over-allocation")
-    @unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
+    @unittest.skipIf(check_sanitizer(address=True, memory=True),
+                     "ASAN/MSAN sanitizer defaults to crashing "
                      "instead of returning NULL for malloc failure.")
     def test_maxcontext_exact_arith(self):
 
index ee3f41a108a14c8a75c4dad5ae88945f8e995ed2..e0f09e821da0c991a00f146880853eaae051d187 100644 (file)
@@ -6,10 +6,10 @@ import re
 import signal
 import subprocess
 import sys
-import sysconfig
 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
@@ -21,16 +21,6 @@ except ImportError:
 
 TIMEOUT = 0.5
 MS_WINDOWS = (os.name == 'nt')
-_cflags = sysconfig.get_config_var('CFLAGS') or ''
-_config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
-UB_SANITIZER = (
-    '-fsanitize=undefined' in _cflags or
-    '--with-undefined-behavior-sanitizer' in _config_args
-)
-MEMORY_SANITIZER = (
-    '-fsanitize=memory' in _cflags or
-    '--with-memory-sanitizer' in _config_args
-)
 
 
 def expected_traceback(lineno1, lineno2, header, min_count=1):
@@ -310,8 +300,8 @@ class FaultHandlerTests(unittest.TestCase):
             3,
             'Segmentation fault')
 
-    @unittest.skipIf(UB_SANITIZER or MEMORY_SANITIZER,
-                     "sanitizer builds change crashing process output.")
+    @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:
@@ -327,8 +317,8 @@ class FaultHandlerTests(unittest.TestCase):
 
     @unittest.skipIf(sys.platform == "win32",
                      "subprocess doesn't support pass_fds on Windows")
-    @unittest.skipIf(UB_SANITIZER or MEMORY_SANITIZER,
-                     "sanitizer builds change crashing process output.")
+    @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:
index 8756b766334e831254d784669411338740290c2d..b94b18a541a7018258d91e0a8b3c00748d882179 100644 (file)
@@ -1,5 +1,9 @@
 import unittest
 from test.support.import_helper import import_module
+from test.support import check_sanitizer
+
+if check_sanitizer(address=True, memory=True):
+    raise unittest.SkipTest("Tests involvin libX11 can SEGFAULT on ASAN/MSAN builds")
 
 # Skip test_idle if _tkinter wasn't built, if tkinter is missing,
 # if tcl/tk is not the 8.5+ needed for ttk widgets,
index 35013b6a090cbb9a5afcf3604ce79b33c3e96cde..fb83762cb6af410a7fce8394e5fa1ee1d1f066d1 100644 (file)
@@ -28,7 +28,6 @@ import pickle
 import random
 import signal
 import sys
-import sysconfig
 import textwrap
 import threading
 import time
@@ -44,6 +43,7 @@ from test.support import import_helper
 from test.support import os_helper
 from test.support import threading_helper
 from test.support import warnings_helper
+from test.support import skip_if_sanitizer
 from test.support.os_helper import FakePath
 
 import codecs
@@ -66,17 +66,6 @@ else:
     class EmptyStruct(ctypes.Structure):
         pass
 
-_cflags = sysconfig.get_config_var('CFLAGS') or ''
-_config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
-MEMORY_SANITIZER = (
-    '-fsanitize=memory' in _cflags or
-    '--with-memory-sanitizer' in _config_args
-)
-
-ADDRESS_SANITIZER = (
-    '-fsanitize=address' in _cflags
-)
-
 # Does io.IOBase finalizer log the exception if the close() method fails?
 # The exception is ignored silently by default in release build.
 IOBASE_EMITS_UNRAISABLE = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
@@ -1550,8 +1539,8 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
 class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
     tp = io.BufferedReader
 
-    @unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
-                     "instead of returning NULL for malloc failure.")
+    @skip_if_sanitizer(memory=True, address=True, reason= "sanitizer defaults to crashing "
+                       "instead of returning NULL for malloc failure.")
     def test_constructor(self):
         BufferedReaderTest.test_constructor(self)
         # The allocation can succeed on 32-bit builds, e.g. with more
@@ -1915,8 +1904,8 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
 class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
     tp = io.BufferedWriter
 
-    @unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
-                     "instead of returning NULL for malloc failure.")
+    @skip_if_sanitizer(memory=True, address=True, reason= "sanitizer defaults to crashing "
+                       "instead of returning NULL for malloc failure.")
     def test_constructor(self):
         BufferedWriterTest.test_constructor(self)
         # The allocation can succeed on 32-bit builds, e.g. with more
@@ -2414,8 +2403,8 @@ class BufferedRandomTest(BufferedReaderTest, BufferedWriterTest):
 class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
     tp = io.BufferedRandom
 
-    @unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
-                     "instead of returning NULL for malloc failure.")
+    @skip_if_sanitizer(memory=True, address=True, reason= "sanitizer defaults to crashing "
+                       "instead of returning NULL for malloc failure.")
     def test_constructor(self):
         BufferedRandomTest.test_constructor(self)
         # The allocation can succeed on 32-bit builds, e.g. with more
index fa855f2104c586e77b35a66635113387499ac818..77f72fcc7c6e3bb4e0669307e63d000e397572e0 100644 (file)
@@ -1,7 +1,15 @@
-import os
-
+import os.path
+import unittest
+from test import support
 from test.support import load_package_tests
 
+
+if support.check_sanitizer(address=True, memory=True):
+    # bpo-46633: Skip the test because it is too slow when Python is built
+    # with ASAN/MSAN: between 5 and 20 minutes on GitHub Actions.
+    raise unittest.SkipTest("test too slow on ASAN/MSAN build")
+
+
 # Load all tests in package
 def load_tests(*args):
     return load_package_tests(os.path.dirname(__file__), *args)
index 8a60c7c8e1fbd57fcafce8e474bf901325ea31bf..454baeb38a93425a1d32d57ec530b4e43a42fd7d 100644 (file)
@@ -2,6 +2,11 @@ import sys
 import unittest
 from test import support
 from test.support import import_helper
+from test.support import check_sanitizer
+
+if check_sanitizer(address=True, memory=True):
+    raise unittest.SkipTest("Tests involvin libX11 can SEGFAULT on ASAN/MSAN builds")
+
 
 # Skip this test if the _tkinter module wasn't built.
 _tkinter = import_helper.import_module('_tkinter')
index 69cc2322cd9aa8732277864ac94f2bf561b0da6e..8f90cbaba9f7c4ebf589a03696d86248f0ce7358 100644 (file)
@@ -1,5 +1,11 @@
+import unittest
 from test import support
 from test.support import import_helper
+from test.support import check_sanitizer
+
+if check_sanitizer(address=True, memory=True):
+    raise unittest.SkipTest("Tests involvin libX11 can SEGFAULT on ASAN/MSAN builds")
+
 # Skip test if _tkinter wasn't built.
 import_helper.import_module('_tkinter')
 
index 61af6578e09530eac0d2e6ebb9e634a2f3450db7..34b0d3b8fb3eb08dc505ad66f00af7b73d33931c 100644 (file)
@@ -6,6 +6,13 @@ import unittest
 from test import support
 from test.support import import_helper
 
+
+if support.check_sanitizer(address=True, memory=True):
+    # bpo-46633: Skip the test because it is too slow when Python is built
+    # with ASAN/MSAN: between 5 and 20 minutes on GitHub Actions.
+    raise unittest.SkipTest("test too slow on ASAN/MSAN build")
+
+
 basepath = os.path.normpath(
         os.path.dirname(                 # <src/install dir>
             os.path.dirname(                # Lib
index 8f59839d066e682d58312ed418a03db87e457a5e..c4919045d75cb7b43449328bcf3375c8151f0653 100644 (file)
@@ -1,6 +1,10 @@
 import unittest
 from test import support
 from test.support import import_helper
+from test.support import check_sanitizer
+
+if check_sanitizer(address=True, memory=True):
+    raise unittest.SkipTest("Tests involvin libX11 can SEGFAULT on ASAN/MSAN builds")
 
 # Skip this test if _tkinter wasn't built.
 import_helper.import_module('_tkinter')