summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_threading.py41
-rw-r--r--Misc/NEWS.d/next/Tests/2023-09-29-14-11-30.gh-issue-110031.fQnFnc.rst2
2 files changed, 27 insertions, 16 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 71fcad2..13bfacb 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -35,6 +35,23 @@ threading_helper.requires_working_threading(module=True)
platforms_to_skip = ('netbsd5', 'hp-ux11')
+# gh-89363: Skip fork() test if Python is built with Address Sanitizer (ASAN)
+# to work around a libasan race condition, dead lock in pthread_create().
+skip_if_asan_fork = support.skip_if_sanitizer(
+ "libasan has a pthread_create() dead lock",
+ address=True)
+
+
+def skip_unless_reliable_fork(test):
+ if not support.has_fork_support:
+ return unittest.skip("requires working os.fork()")(test)
+ if sys.platform in platforms_to_skip:
+ return unittest.skip("due to known OS bug related to thread+fork")(test)
+ if support.check_sanitizer(address=True):
+ return unittest.skip("libasan has a pthread_create() dead lock related to thread+fork")(test)
+ return test
+
+
def restore_default_excepthook(testcase):
testcase.addCleanup(setattr, threading, 'excepthook', threading.excepthook)
threading.excepthook = threading.__excepthook__
@@ -539,7 +556,7 @@ class ThreadTests(BaseTestCase):
t = threading.Thread(daemon=True)
self.assertTrue(t.daemon)
- @support.requires_fork()
+ @skip_unless_reliable_fork
def test_dummy_thread_after_fork(self):
# Issue #14308: a dummy thread in the active list doesn't mess up
# the after-fork mechanism.
@@ -571,11 +588,7 @@ class ThreadTests(BaseTestCase):
self.assertEqual(out, b'')
self.assertEqual(err, b'')
- @support.requires_fork()
- # gh-89363: Skip multiprocessing tests if Python is built with ASAN to
- # work around a libasan race condition: dead lock in pthread_create().
- @support.skip_if_sanitizer("libasan has a pthread_create() dead lock",
- address=True)
+ @skip_unless_reliable_fork
def test_is_alive_after_fork(self):
# Try hard to trigger #18418: is_alive() could sometimes be True on
# threads that vanished after a fork.
@@ -611,7 +624,7 @@ class ThreadTests(BaseTestCase):
th.start()
th.join()
- @support.requires_fork()
+ @skip_unless_reliable_fork
@unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
def test_main_thread_after_fork(self):
code = """if 1:
@@ -632,8 +645,7 @@ class ThreadTests(BaseTestCase):
self.assertEqual(err, b"")
self.assertEqual(data, "MainThread\nTrue\nTrue\n")
- @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
- @support.requires_fork()
+ @skip_unless_reliable_fork
@unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
def test_main_thread_after_fork_from_nonmain_thread(self):
code = """if 1:
@@ -1080,8 +1092,7 @@ class ThreadJoinOnShutdown(BaseTestCase):
"""
self._run_and_join(script)
- @support.requires_fork()
- @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
+ @skip_unless_reliable_fork
def test_2_join_in_forked_process(self):
# Like the test above, but from a forked interpreter
script = """if 1:
@@ -1101,8 +1112,7 @@ class ThreadJoinOnShutdown(BaseTestCase):
"""
self._run_and_join(script)
- @support.requires_fork()
- @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
+ @skip_unless_reliable_fork
def test_3_join_in_forked_from_thread(self):
# Like the test above, but fork() was called from a worker thread
# In the forked process, the main Thread object must be marked as stopped.
@@ -1172,8 +1182,7 @@ class ThreadJoinOnShutdown(BaseTestCase):
rc, out, err = assert_python_ok('-c', script)
self.assertFalse(err)
- @support.requires_fork()
- @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
+ @skip_unless_reliable_fork
def test_reinit_tls_after_fork(self):
# Issue #13817: fork() would deadlock in a multithreaded program with
# the ad-hoc TLS implementation.
@@ -1199,7 +1208,7 @@ class ThreadJoinOnShutdown(BaseTestCase):
for t in threads:
t.join()
- @support.requires_fork()
+ @skip_unless_reliable_fork
def test_clear_threads_states_after_fork(self):
# Issue #17094: check that threads states are cleared after fork()
diff --git a/Misc/NEWS.d/next/Tests/2023-09-29-14-11-30.gh-issue-110031.fQnFnc.rst b/Misc/NEWS.d/next/Tests/2023-09-29-14-11-30.gh-issue-110031.fQnFnc.rst
new file mode 100644
index 0000000..a8a163c
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2023-09-29-14-11-30.gh-issue-110031.fQnFnc.rst
@@ -0,0 +1,2 @@
+Skip test_threading tests using thread+fork if Python is built with Address
+Sanitizer (ASAN). Patch by Victor Stinner.