summaryrefslogtreecommitdiffstats
path: root/Lib/test/support/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/support/__init__.py')
-rw-r--r--Lib/test/support/__init__.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 53804f1..c4115a8 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -54,7 +54,7 @@ __all__ = [
"requires_IEEE_754", "skip_unless_xattr", "requires_zlib",
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__", "skip_if_buggy_ucrt_strfptime",
- "ignore_warnings",
+ "ignore_warnings", "check_sanitizer", "skip_if_sanitizer",
# sys
"is_jython", "is_android", "check_impl_detail", "unix_shell",
"setswitchinterval",
@@ -644,6 +644,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)