Skip to content

Commit fb745db

Browse files
pitrouvstinner
authored andcommitted
pythongh-112536: Add test_threading to TSAN tests (python#116898)
1 parent efc1975 commit fb745db

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

Lib/test/libregrtest/tsan.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'test_syslog',
1515
'test_thread',
1616
'test_threadedtempfile',
17+
'test_threading',
1718
'test_threading_local',
1819
'test_threadsignals',
1920
]

Lib/test/support/script_helper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ class _PythonRunResult(collections.namedtuple("_PythonRunResult",
6363
"""Helper for reporting Python subprocess run results"""
6464
def fail(self, cmd_line):
6565
"""Provide helpful details about failed subcommand runs"""
66-
# Limit to 80 lines to ASCII characters
67-
maxlen = 80 * 100
66+
# Limit to 300 lines of ASCII characters
67+
maxlen = 300 * 100
6868
out, err = self.out, self.err
6969
if len(out) > maxlen:
7070
out = b'(... truncated stdout ...)' + out[-maxlen:]

Lib/test/test_threading.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,11 @@ def skip_unless_reliable_fork(test):
4747
return unittest.skip("due to known OS bug related to thread+fork")(test)
4848
if support.HAVE_ASAN_FORK_BUG:
4949
return unittest.skip("libasan has a pthread_create() dead lock related to thread+fork")(test)
50+
if support.check_sanitizer(thread=True):
51+
return unittest.skip("TSAN doesn't support threads after fork")
5052
return test
5153

5254

53-
skip_if_tsan_fork = unittest.skipIf(
54-
support.check_sanitizer(thread=True),
55-
"TSAN doesn't support threads after fork")
56-
57-
5855
def requires_subinterpreters(meth):
5956
"""Decorator to skip a test if subinterpreters are not supported."""
6057
return unittest.skipIf(interpreters is None,
@@ -428,6 +425,10 @@ def test_finalize_running_thread(self):
428425
# Issue 1402: the PyGILState_Ensure / _Release functions may be called
429426
# very late on python exit: on deallocation of a running thread for
430427
# example.
428+
if support.check_sanitizer(thread=True):
429+
# the thread running `time.sleep(100)` below will still be alive
430+
# at process exit
431+
self.skipTest("TSAN would report thread leak")
431432
import_module("ctypes")
432433

433434
rc, out, err = assert_python_failure("-c", """if 1:
@@ -460,6 +461,11 @@ def waitingThread():
460461
def test_finalize_with_trace(self):
461462
# Issue1733757
462463
# Avoid a deadlock when sys.settrace steps into threading._shutdown
464+
if support.check_sanitizer(thread=True):
465+
# the thread running `time.sleep(2)` below will still be alive
466+
# at process exit
467+
self.skipTest("TSAN would report thread leak")
468+
463469
assert_python_ok("-c", """if 1:
464470
import sys, threading
465471
@@ -639,7 +645,6 @@ def test_daemon_param(self):
639645
self.assertTrue(t.daemon)
640646

641647
@skip_unless_reliable_fork
642-
@skip_if_tsan_fork
643648
def test_dummy_thread_after_fork(self):
644649
# Issue #14308: a dummy thread in the active list doesn't mess up
645650
# the after-fork mechanism.
@@ -709,7 +714,6 @@ def f():
709714

710715
@skip_unless_reliable_fork
711716
@unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
712-
@skip_if_tsan_fork
713717
def test_main_thread_after_fork(self):
714718
code = """if 1:
715719
import os, threading
@@ -1278,7 +1282,6 @@ def test_2_join_in_forked_process(self):
12781282
self._run_and_join(script)
12791283

12801284
@skip_unless_reliable_fork
1281-
@skip_if_tsan_fork
12821285
def test_3_join_in_forked_from_thread(self):
12831286
# Like the test above, but fork() was called from a worker thread
12841287
# In the forked process, the main Thread object must be marked as stopped.
@@ -1311,6 +1314,11 @@ def test_4_daemon_threads(self):
13111314
# Check that a daemon thread cannot crash the interpreter on shutdown
13121315
# by manipulating internal structures that are being disposed of in
13131316
# the main thread.
1317+
if support.check_sanitizer(thread=True):
1318+
# some of the threads running `random_io` below will still be alive
1319+
# at process exit
1320+
self.skipTest("TSAN would report thread leak")
1321+
13141322
script = """if True:
13151323
import os
13161324
import random

0 commit comments

Comments
 (0)