Skip to content

Commit a275053

Browse files
authored
Add skips to crashing tests under sanitizers instead of manually skipping them (GH-30897)
1 parent a0efc0c commit a275053

File tree

7 files changed

+37
-7
lines changed

7 files changed

+37
-7
lines changed

.github/workflows/build.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,7 @@ jobs:
311311
#
312312
# Skip multiprocessing and concurrent.futures tests which are affected by
313313
# bpo-45200 bug: libasan dead lock in pthread_create().
314-
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"
314+
#
315+
# test___all__ is skipped because importing some modules directly can trigger
316+
# known problems with ASAN (like tk or crypt).
317+
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"

Lib/test/support/__init__.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"has_subprocess_support", "requires_subprocess",
4444
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
4545
"check__all__", "skip_if_buggy_ucrt_strfptime",
46-
"check_disallow_instantiation", "skip_if_sanitizer",
46+
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
4747
# sys
4848
"is_jython", "is_android", "is_emscripten", "is_wasi",
4949
"check_impl_detail", "unix_shell", "setswitchinterval",
@@ -384,13 +384,11 @@ def skip_if_buildbot(reason=None):
384384
isbuildbot = os.environ.get('USER') == 'buildbot'
385385
return unittest.skipIf(isbuildbot, reason)
386386

387-
def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False):
388-
"""Decorator raising SkipTest if running with a sanitizer active."""
387+
def check_sanitizer(*, address=False, memory=False, ub=False):
388+
"""Returns True if Python is compiled with sanitizer support"""
389389
if not (address or memory or ub):
390390
raise ValueError('At least one of address, memory, or ub must be True')
391391

392-
if not reason:
393-
reason = 'not working with sanitizers active'
394392

395393
_cflags = sysconfig.get_config_var('CFLAGS') or ''
396394
_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):
406404
'-fsanitize=undefined' in _cflags or
407405
'--with-undefined-behavior-sanitizer' in _config_args
408406
)
409-
skip = (
407+
return (
410408
(memory and memory_sanitizer) or
411409
(address and address_sanitizer) or
412410
(ub and ub_sanitizer)
413411
)
412+
413+
414+
def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False):
415+
"""Decorator raising SkipTest if running with a sanitizer active."""
416+
if not reason:
417+
reason = 'not working with sanitizers active'
418+
skip = check_sanitizer(address=address, memory=memory, ub=ub)
414419
return unittest.skipIf(skip, reason)
415420

416421

Lib/test/test_crypt.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import sys
22
import unittest
3+
from test.support import check_sanitizer
34

45

56
try:
7+
if check_sanitizer(address=True, memory=True):
8+
raise unittest.SkipTest("The crypt module SEGFAULTs on ASAN/MSAN builds")
69
import crypt
710
IMPORT_ERROR = None
811
except ImportError as ex:

Lib/test/test_idle.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import unittest
22
from test.support.import_helper import import_module
3+
from test.support import check_sanitizer
4+
5+
if check_sanitizer(address=True, memory=True):
6+
raise unittest.SkipTest("Tests involvin libX11 can SEGFAULT on ASAN/MSAN builds")
37

48
# Skip test_idle if _tkinter wasn't built, if tkinter is missing,
59
# if tcl/tk is not the 8.5+ needed for ttk widgets,

Lib/test/test_tix.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import unittest
33
from test import support
44
from test.support import import_helper
5+
from test.support import check_sanitizer
6+
7+
if check_sanitizer(address=True, memory=True):
8+
raise unittest.SkipTest("Tests involvin libX11 can SEGFAULT on ASAN/MSAN builds")
9+
510

611
# Skip this test if the _tkinter module wasn't built.
712
_tkinter = import_helper.import_module('_tkinter')

Lib/test/test_tk.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import unittest
12
from test import support
23
from test.support import import_helper
4+
from test.support import check_sanitizer
5+
6+
if check_sanitizer(address=True, memory=True):
7+
raise unittest.SkipTest("Tests involvin libX11 can SEGFAULT on ASAN/MSAN builds")
8+
39
# Skip test if _tkinter wasn't built.
410
import_helper.import_module('_tkinter')
511

Lib/test/test_ttk_guionly.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import unittest
22
from test import support
33
from test.support import import_helper
4+
from test.support import check_sanitizer
5+
6+
if check_sanitizer(address=True, memory=True):
7+
raise unittest.SkipTest("Tests involvin libX11 can SEGFAULT on ASAN/MSAN builds")
48

59
# Skip this test if _tkinter wasn't built.
610
import_helper.import_module('_tkinter')

0 commit comments

Comments
 (0)