Skip to content

Commit c6b2961

Browse files
committed
Skip some tests #if defined(THREAD_SANITIZER) (tested with TSAN using the Google-internal toolchain).
1 parent ed3c4df commit c6b2961

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/test_gil_scoped.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class PyVirtClass : public VirtClass {
3535
};
3636

3737
TEST_SUBMODULE(gil_scoped, m) {
38+
m.attr("defined_THREAD_SANITIZER") =
39+
#if defined(THREAD_SANITIZER)
40+
true;
41+
#else
42+
false;
43+
#endif
44+
3845
py::class_<VirtClass, PyVirtClass>(m, "VirtClass")
3946
.def(py::init<>())
4047
.def("virtual_func", &VirtClass::virtual_func)

tests/test_gil_scoped.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ def _run_in_threads(target, num_threads, parallel):
166166
thread.join()
167167

168168

169+
# m.defined_THREAD_SANITIZER is used below to skip tests triggering this error (#2754):
170+
# ThreadSanitizer: starting new threads after multi-threaded fork is not supported.
171+
169172
# TODO: FIXME, sometimes returns -11 (segfault) instead of 0 on macOS Python 3.9
173+
@pytest.mark.skipif(
174+
m.defined_THREAD_SANITIZER, reason="Not compatible with ThreadSanitizer"
175+
)
170176
@pytest.mark.parametrize("test_fn", ALL_BASIC_TESTS)
171177
def test_run_in_process_one_thread(test_fn):
172178
"""Makes sure there is no GIL deadlock when running in a thread.
@@ -177,6 +183,9 @@ def test_run_in_process_one_thread(test_fn):
177183

178184

179185
# TODO: FIXME on macOS Python 3.9
186+
@pytest.mark.skipif(
187+
m.defined_THREAD_SANITIZER, reason="Not compatible with ThreadSanitizer"
188+
)
180189
@pytest.mark.parametrize("test_fn", ALL_BASIC_TESTS)
181190
def test_run_in_process_multiple_threads_parallel(test_fn):
182191
"""Makes sure there is no GIL deadlock when running in a thread multiple times in parallel.
@@ -190,6 +199,9 @@ def test_run_in_process_multiple_threads_parallel(test_fn):
190199

191200

192201
# TODO: FIXME on macOS Python 3.9
202+
@pytest.mark.skipif(
203+
m.defined_THREAD_SANITIZER, reason="Not compatible with ThreadSanitizer"
204+
)
193205
@pytest.mark.parametrize("test_fn", ALL_BASIC_TESTS)
194206
def test_run_in_process_multiple_threads_sequential(test_fn):
195207
"""Makes sure there is no GIL deadlock when running in a thread multiple times sequentially.
@@ -206,6 +218,14 @@ def test_run_in_process_direct(test_fn):
206218
207219
This test is for completion, but it was never an issue.
208220
"""
221+
if m.defined_THREAD_SANITIZER and test_fn in (
222+
test_cross_module_gil_nested_custom_released,
223+
test_cross_module_gil_nested_custom_acquired,
224+
test_cross_module_gil_nested_pybind11_released,
225+
test_cross_module_gil_nested_pybind11_acquired,
226+
test_multi_acquire_release_cross_module,
227+
):
228+
pytest.skip("Not compatible with ThreadSanitizer")
209229
exitcode = _run_in_process(test_fn)
210230
if exitcode is None and env.PYPY and env.WIN: # Seems to be flaky.
211231
pytest.skip("Ignoring unexpected exitcode None (PYPY WIN)")

0 commit comments

Comments
 (0)