[Python-checkins] Add skips to crashing tests under sanitizers instead of manually skipping them (GH-30897)

pablogsal webhook-mailer at python.org
Tue Jan 25 18:14:08 EST 2022


https://github.com/python/cpython/commit/a27505345e34d462139f5f8b6b5e7c9a59955150
commit: a27505345e34d462139f5f8b6b5e7c9a59955150
branch: main
author: Pablo Galindo Salgado <Pablogsal at gmail.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2022-01-25T23:14:03Z
summary:

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

files:
M .github/workflows/build.yml
M Lib/test/support/__init__.py
M Lib/test/test_crypt.py
M Lib/test/test_idle.py
M Lib/test/test_tix.py
M Lib/test/test_tk.py
M Lib/test/test_ttk_guionly.py

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index d6af174d1c3a7..5d36dffa80108 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -311,4 +311,7 @@ jobs:
       #
       # Skip multiprocessing and concurrent.futures tests which are affected by
       # bpo-45200 bug: libasan dead lock in pthread_create().
-      run: xvfb-run make buildbottest TESTOPTS="-j4 -uall,-cpu -x test_ctypes test_crypt test_decimal test_faulthandler test_interpreters test___all__ test_idle test_tix test_tk test_ttk_guionly test_ttk_textonly test_multiprocessing_fork test_multiprocessing_forkserver test_multiprocessing_spawn test_tools test_peg_generator test_concurrent_futures"
+      #
+      # test___all__ is skipped because importing some modules directly can trigger
+      # known problems with ASAN (like tk or crypt).
+      run: xvfb-run make buildbottest TESTOPTS="-j4 -uall,-cpu -x test___all__ test_multiprocessing_fork test_multiprocessing_forkserver test_multiprocessing_spawn test_tools test_peg_generator test_concurrent_futures"
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 583d94f41e563..d71cfe5ee44fd 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -43,7 +43,7 @@
     "has_subprocess_support", "requires_subprocess",
     "anticipate_failure", "load_package_tests", "detect_api_mismatch",
     "check__all__", "skip_if_buggy_ucrt_strfptime",
-    "check_disallow_instantiation", "skip_if_sanitizer",
+    "check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
     # sys
     "is_jython", "is_android", "is_emscripten", "is_wasi",
     "check_impl_detail", "unix_shell", "setswitchinterval",
@@ -384,13 +384,11 @@ def skip_if_buildbot(reason=None):
         isbuildbot = os.environ.get('USER') == 'buildbot'
     return unittest.skipIf(isbuildbot, reason)
 
-def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False):
-    """Decorator raising SkipTest if running with a sanitizer active."""
+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')
 
-    if not reason:
-        reason = 'not working with sanitizers active'
 
     _cflags = sysconfig.get_config_var('CFLAGS') or ''
     _config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
@@ -406,11 +404,18 @@ def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False):
         '-fsanitize=undefined' in _cflags or
         '--with-undefined-behavior-sanitizer' in _config_args
     )
-    skip = (
+    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)
 
 
diff --git a/Lib/test/test_crypt.py b/Lib/test/test_crypt.py
index 5dc83b4ecbfa0..877c575c5534a 100644
--- a/Lib/test/test_crypt.py
+++ b/Lib/test/test_crypt.py
@@ -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:
diff --git a/Lib/test/test_idle.py b/Lib/test/test_idle.py
index 8756b766334e8..b94b18a541a70 100644
--- a/Lib/test/test_idle.py
+++ b/Lib/test/test_idle.py
@@ -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,
diff --git a/Lib/test/test_tix.py b/Lib/test/test_tix.py
index 8a60c7c8e1fbd..454baeb38a934 100644
--- a/Lib/test/test_tix.py
+++ b/Lib/test/test_tix.py
@@ -2,6 +2,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 this test if the _tkinter module wasn't built.
 _tkinter = import_helper.import_module('_tkinter')
diff --git a/Lib/test/test_tk.py b/Lib/test/test_tk.py
index 69cc2322cd9aa..8f90cbaba9f7c 100644
--- a/Lib/test/test_tk.py
+++ b/Lib/test/test_tk.py
@@ -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')
 
diff --git a/Lib/test/test_ttk_guionly.py b/Lib/test/test_ttk_guionly.py
index 8f59839d066e6..c4919045d75cb 100644
--- a/Lib/test/test_ttk_guionly.py
+++ b/Lib/test/test_ttk_guionly.py
@@ -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')



More information about the Python-checkins mailing list