Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ def get_build_info():
# --with-thread-sanitizer
if support.check_sanitizer(thread=True):
sanitizers.append("TSAN")
# --with-thread-sanitizer
if support.check_sanitizer(function=True):
sanitizers.append("fsanitize=function")
if sanitizers:
build.append('+'.join(sanitizers))

Expand Down Expand Up @@ -691,6 +694,7 @@ def display_header(use_resources: dict[str, str | None],
msan = support.check_sanitizer(memory=True)
ubsan = support.check_sanitizer(ub=True)
tsan = support.check_sanitizer(thread=True)
function_san = support.check_sanitizer(function=True)
sanitizers = []
if asan:
sanitizers.append("address")
Expand All @@ -700,12 +704,14 @@ def display_header(use_resources: dict[str, str | None],
sanitizers.append("undefined behavior")
if tsan:
sanitizers.append("thread")
if function_san:
sanitizers.append("function")
if sanitizers:
print(f"== sanitizers: {', '.join(sanitizers)}")
for sanitizer, env_var in (
(asan, "ASAN_OPTIONS"),
(msan, "MSAN_OPTIONS"),
(ubsan, "UBSAN_OPTIONS"),
(ubsan or function_san, "UBSAN_OPTIONS"),
(tsan, "TSAN_OPTIONS"),
):
options= os.environ.get(env_var)
Expand Down
13 changes: 8 additions & 5 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,11 @@ def skip_if_buildbot(reason=None):
return unittest.skipIf(isbuildbot, reason)

def check_sanitizer(*, address=False, memory=False, ub=False, thread=False,
function=True):
function=False):
"""Returns True if Python is compiled with sanitizer support"""
if not (address or memory or ub or thread):
raise ValueError('At least one of address, memory, ub or thread must be True')
if not (address or memory or ub or thread or function):
raise ValueError('At least one of address, memory, ub, '
'thread or function must be True')


cflags = sysconfig.get_config_var('CFLAGS') or ''
Expand Down Expand Up @@ -486,11 +487,13 @@ def configured_with_sanitizer(name):
)


def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False, thread=False):
def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False,
thread=False, function=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, thread=thread)
skip = check_sanitizer(address=address, memory=memory, ub=ub,
thread=thread, function=function)
return unittest.skipIf(skip, reason)

# gh-89363: True if fork() can hang if Python is built with Address Sanitizer
Expand Down
Loading