mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.10] bpo-46633: Skip tests on ASAN and/or MSAN builds (GH-31632) (GH-31634) (GH-31644)
* Refactor sanitiser skip tests into test.support (GH-30889) * Refactor sanitizer skip tests into test.support (cherry picked from commitb1cb843050) * Add skips to crashing tests under sanitizers instead of manually skipping them (GH-30897) (cherry picked from commita27505345e) * 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 commit9204bb72a2) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com> (cherry picked from commit93264452d9)
This commit is contained in:
parent
3ea2a8f425
commit
359bc392ba
14 changed files with 112 additions and 52 deletions
|
|
@ -69,6 +69,12 @@
|
||||||
msvcrt = None
|
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):
|
def latin(s):
|
||||||
return s.encode('latin')
|
return s.encode('latin')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@
|
||||||
"requires_IEEE_754", "skip_unless_xattr", "requires_zlib",
|
"requires_IEEE_754", "skip_unless_xattr", "requires_zlib",
|
||||||
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
|
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
|
||||||
"check__all__", "skip_if_buggy_ucrt_strfptime",
|
"check__all__", "skip_if_buggy_ucrt_strfptime",
|
||||||
"ignore_warnings",
|
"ignore_warnings", "check_sanitizer", "skip_if_sanitizer",
|
||||||
# sys
|
# sys
|
||||||
"is_jython", "is_android", "check_impl_detail", "unix_shell",
|
"is_jython", "is_android", "check_impl_detail", "unix_shell",
|
||||||
"setswitchinterval",
|
"setswitchinterval",
|
||||||
|
|
@ -644,6 +644,41 @@ def wrapper(*args, **kw):
|
||||||
return decorator
|
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):
|
def system_must_validate_cert(f):
|
||||||
"""Skip the test on TLS certificate validation failures."""
|
"""Skip the test on TLS certificate validation failures."""
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,13 @@
|
||||||
import sys
|
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):
|
class NoAll(RuntimeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,12 @@
|
||||||
import multiprocessing.util
|
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):
|
def create_future(state=PENDING, exception=None, result=None):
|
||||||
f = Future()
|
f = Future()
|
||||||
f._state = state
|
f._state = state
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
from test.support import check_sanitizer
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if check_sanitizer(address=True, memory=True):
|
||||||
|
raise unittest.SkipTest("The crypt module SEGFAULTs on ASAN/MSAN builds")
|
||||||
import crypt
|
import crypt
|
||||||
IMPORT_ERROR = None
|
IMPORT_ERROR = None
|
||||||
except ImportError as ex:
|
except ImportError as ex:
|
||||||
|
|
|
||||||
|
|
@ -33,24 +33,14 @@
|
||||||
import numbers
|
import numbers
|
||||||
import locale
|
import locale
|
||||||
from test.support import (run_unittest, run_doctest, is_resource_enabled,
|
from test.support import (run_unittest, run_doctest, is_resource_enabled,
|
||||||
requires_IEEE_754, requires_docstrings)
|
requires_IEEE_754, requires_docstrings,
|
||||||
from test.support import (import_fresh_module, TestFailed,
|
import_fresh_module, TestFailed,
|
||||||
run_with_locale, cpython_only,
|
run_with_locale, cpython_only,
|
||||||
darwin_malloc_err_warning)
|
darwin_malloc_err_warning,
|
||||||
|
check_sanitizer)
|
||||||
import random
|
import random
|
||||||
import inspect
|
import inspect
|
||||||
import threading
|
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':
|
if sys.platform == 'darwin':
|
||||||
|
|
@ -5497,7 +5487,8 @@ def __abs__(self):
|
||||||
# Issue 41540:
|
# Issue 41540:
|
||||||
@unittest.skipIf(sys.platform.startswith("aix"),
|
@unittest.skipIf(sys.platform.startswith("aix"),
|
||||||
"AIX: default ulimit: test is flaky because of extreme over-allocation")
|
"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.")
|
"instead of returning NULL for malloc failure.")
|
||||||
def test_maxcontext_exact_arith(self):
|
def test_maxcontext_exact_arith(self):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import sysconfig
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import script_helper, is_android
|
from test.support import script_helper, is_android
|
||||||
|
from test.support import skip_if_sanitizer
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
@ -19,16 +19,6 @@
|
||||||
|
|
||||||
TIMEOUT = 0.5
|
TIMEOUT = 0.5
|
||||||
MS_WINDOWS = (os.name == 'nt')
|
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):
|
def expected_traceback(lineno1, lineno2, header, min_count=1):
|
||||||
|
|
@ -271,8 +261,8 @@ def test_gil_released(self):
|
||||||
3,
|
3,
|
||||||
'Segmentation fault')
|
'Segmentation fault')
|
||||||
|
|
||||||
@unittest.skipIf(UB_SANITIZER or MEMORY_SANITIZER,
|
@skip_if_sanitizer(memory=True, ub=True, reason="sanitizer "
|
||||||
"sanitizer builds change crashing process output.")
|
"builds change crashing process output.")
|
||||||
@skip_segfault_on_android
|
@skip_segfault_on_android
|
||||||
def test_enable_file(self):
|
def test_enable_file(self):
|
||||||
with temporary_filename() as filename:
|
with temporary_filename() as filename:
|
||||||
|
|
@ -288,8 +278,8 @@ def test_enable_file(self):
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform == "win32",
|
@unittest.skipIf(sys.platform == "win32",
|
||||||
"subprocess doesn't support pass_fds on Windows")
|
"subprocess doesn't support pass_fds on Windows")
|
||||||
@unittest.skipIf(UB_SANITIZER or MEMORY_SANITIZER,
|
@skip_if_sanitizer(memory=True, ub=True, reason="sanitizer "
|
||||||
"sanitizer builds change crashing process output.")
|
"builds change crashing process output.")
|
||||||
@skip_segfault_on_android
|
@skip_segfault_on_android
|
||||||
def test_enable_fd(self):
|
def test_enable_fd(self):
|
||||||
with tempfile.TemporaryFile('wb+') as fp:
|
with tempfile.TemporaryFile('wb+') as fp:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import import_module
|
from test.support 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,
|
# Skip test_idle if _tkinter wasn't built, if tkinter is missing,
|
||||||
# if tcl/tk is not the 8.5+ needed for ttk widgets,
|
# if tcl/tk is not the 8.5+ needed for ttk widgets,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@
|
||||||
import random
|
import random
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import sysconfig
|
|
||||||
import textwrap
|
import textwrap
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
@ -40,7 +39,7 @@
|
||||||
from test import support
|
from test import support
|
||||||
from test.support.script_helper import (
|
from test.support.script_helper import (
|
||||||
assert_python_ok, assert_python_failure, run_python_until_end)
|
assert_python_ok, assert_python_failure, run_python_until_end)
|
||||||
from test.support import FakePath
|
from test.support import FakePath, skip_if_sanitizer
|
||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
import io # C implementation of io
|
import io # C implementation of io
|
||||||
|
|
@ -62,17 +61,6 @@ def byteslike(*pos, **kw):
|
||||||
class EmptyStruct(ctypes.Structure):
|
class EmptyStruct(ctypes.Structure):
|
||||||
pass
|
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?
|
# Does io.IOBase finalizer log the exception if the close() method fails?
|
||||||
# The exception is ignored silently by default in release build.
|
# The exception is ignored silently by default in release build.
|
||||||
IOBASE_EMITS_UNRAISABLE = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
|
IOBASE_EMITS_UNRAISABLE = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
|
||||||
|
|
@ -1543,8 +1531,8 @@ def test_truncate_on_read_only(self):
|
||||||
class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
|
class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
|
||||||
tp = io.BufferedReader
|
tp = io.BufferedReader
|
||||||
|
|
||||||
@unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
|
@skip_if_sanitizer(memory=True, address=True, reason= "sanitizer defaults to crashing "
|
||||||
"instead of returning NULL for malloc failure.")
|
"instead of returning NULL for malloc failure.")
|
||||||
def test_constructor(self):
|
def test_constructor(self):
|
||||||
BufferedReaderTest.test_constructor(self)
|
BufferedReaderTest.test_constructor(self)
|
||||||
# The allocation can succeed on 32-bit builds, e.g. with more
|
# The allocation can succeed on 32-bit builds, e.g. with more
|
||||||
|
|
@ -1892,8 +1880,8 @@ def test_slow_close_from_thread(self):
|
||||||
class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
|
class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
|
||||||
tp = io.BufferedWriter
|
tp = io.BufferedWriter
|
||||||
|
|
||||||
@unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
|
@skip_if_sanitizer(memory=True, address=True, reason= "sanitizer defaults to crashing "
|
||||||
"instead of returning NULL for malloc failure.")
|
"instead of returning NULL for malloc failure.")
|
||||||
def test_constructor(self):
|
def test_constructor(self):
|
||||||
BufferedWriterTest.test_constructor(self)
|
BufferedWriterTest.test_constructor(self)
|
||||||
# The allocation can succeed on 32-bit builds, e.g. with more
|
# The allocation can succeed on 32-bit builds, e.g. with more
|
||||||
|
|
@ -2391,8 +2379,8 @@ def test_interleaved_readline_write(self):
|
||||||
class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
|
class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
|
||||||
tp = io.BufferedRandom
|
tp = io.BufferedRandom
|
||||||
|
|
||||||
@unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
|
@skip_if_sanitizer(memory=True, address=True, reason= "sanitizer defaults to crashing "
|
||||||
"instead of returning NULL for malloc failure.")
|
"instead of returning NULL for malloc failure.")
|
||||||
def test_constructor(self):
|
def test_constructor(self):
|
||||||
BufferedRandomTest.test_constructor(self)
|
BufferedRandomTest.test_constructor(self)
|
||||||
# The allocation can succeed on 32-bit builds, e.g. with more
|
# The allocation can succeed on 32-bit builds, e.g. with more
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
import os
|
import os.path
|
||||||
|
import unittest
|
||||||
|
from test import support
|
||||||
from test.support import load_package_tests
|
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
|
# Load all tests in package
|
||||||
def load_tests(*args):
|
def load_tests(*args):
|
||||||
return load_package_tests(os.path.dirname(__file__), *args)
|
return load_package_tests(os.path.dirname(__file__), *args)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import check_sanitizer
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
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.
|
# Skip this test if the _tkinter module wasn't built.
|
||||||
_tkinter = support.import_module('_tkinter')
|
_tkinter = support.import_module('_tkinter')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,10 @@
|
||||||
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
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.
|
# Skip test if _tkinter wasn't built.
|
||||||
support.import_module('_tkinter')
|
support.import_module('_tkinter')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,13 @@
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
|
||||||
|
|
||||||
|
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(
|
basepath = os.path.normpath(
|
||||||
os.path.dirname( # <src/install dir>
|
os.path.dirname( # <src/install dir>
|
||||||
os.path.dirname( # Lib
|
os.path.dirname( # Lib
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
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.
|
# Skip this test if _tkinter wasn't built.
|
||||||
support.import_module('_tkinter')
|
support.import_module('_tkinter')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue