diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index 6d4e23bb8624f3..50c7b7c00d14ef 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -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)) @@ -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") @@ -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) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 209cee1b760af1..389215153385b5 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -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 '' @@ -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