Visitar URL original
[3.10] bpo-46633: Skip tests on ASAN and/or MSAN builds (GH-31632) by vstinner · Pull Request #31634 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add skips to crashing tests under sanitizers instead of manually skip…
…ping them (GH-30897)

(cherry picked from commit a275053)
  • Loading branch information
pablogsal authored and vstinner committed Mar 1, 2022
commit cd983cc750a266c502fb54ce62578595d50b5379
17 changes: 11 additions & 6 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"requires_IEEE_754", "requires_zlib",
"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", "check_impl_detail", "unix_shell",
"setswitchinterval",
Expand Down Expand Up @@ -367,13 +367,11 @@ def wrapper(*args, **kw):
return decorator


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 ''
Expand All @@ -389,11 +387,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)


Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_crypt.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_idle.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_tix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_tk.py
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_ttk_guionly.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down