@@ -391,10 +391,10 @@ def skip_if_buildbot(reason=None):
391391 isbuildbot = False
392392 return unittest .skipIf (isbuildbot , reason )
393393
394- def check_sanitizer (* , address = False , memory = False , ub = False ):
394+ def check_sanitizer (* , address = False , memory = False , ub = False , thread = False ):
395395 """Returns True if Python is compiled with sanitizer support"""
396- if not (address or memory or ub ):
397- raise ValueError ('At least one of address, memory, or ub must be True' )
396+ if not (address or memory or ub or thread ):
397+ raise ValueError ('At least one of address, memory, ub or thread must be True' )
398398
399399
400400 cflags = sysconfig .get_config_var ('CFLAGS' ) or ''
@@ -411,18 +411,23 @@ def check_sanitizer(*, address=False, memory=False, ub=False):
411411 '-fsanitize=undefined' in cflags or
412412 '--with-undefined-behavior-sanitizer' in config_args
413413 )
414+ thread_sanitizer = (
415+ '-fsanitize=thread' in cflags or
416+ '--with-thread-sanitizer' in config_args
417+ )
414418 return (
415419 (memory and memory_sanitizer ) or
416420 (address and address_sanitizer ) or
417- (ub and ub_sanitizer )
421+ (ub and ub_sanitizer ) or
422+ (thread and thread_sanitizer )
418423 )
419424
420425
421- def skip_if_sanitizer (reason = None , * , address = False , memory = False , ub = False ):
426+ def skip_if_sanitizer (reason = None , * , address = False , memory = False , ub = False , thread = False ):
422427 """Decorator raising SkipTest if running with a sanitizer active."""
423428 if not reason :
424429 reason = 'not working with sanitizers active'
425- skip = check_sanitizer (address = address , memory = memory , ub = ub )
430+ skip = check_sanitizer (address = address , memory = memory , ub = ub , thread = thread )
426431 return unittest .skipIf (skip , reason )
427432
428433# gh-89363: True if fork() can hang if Python is built with Address Sanitizer
@@ -431,7 +436,7 @@ def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False):
431436
432437
433438def set_sanitizer_env_var (env , option ):
434- for name in ('ASAN_OPTIONS' , 'MSAN_OPTIONS' , 'UBSAN_OPTIONS' ):
439+ for name in ('ASAN_OPTIONS' , 'MSAN_OPTIONS' , 'UBSAN_OPTIONS' , 'TSAN_OPTIONS' ):
435440 if name in env :
436441 env [name ] += f':{ option } '
437442 else :
0 commit comments