Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-129694: Add test_exceptions to parallel TSAN jobs #129746

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/libregrtest/tsan.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# the regression test runner with the `--parallel-threads` option enabled.
TSAN_PARALLEL_TESTS = [
'test_abc',
'test_exceptions',
'test_hashlib',
]

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,7 @@ def force_not_colorized(func):
def wrapper(*args, **kwargs):
with no_color():
return func(*args, **kwargs)
return wrapper
return thread_unsafe(wrapper) # modifying the environment is thread-unsafe


def force_not_colorized_test_class(cls):
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def raise_catch(self, exc, excname):
self.assertEqual(buf1, buf2)
self.assertEqual(exc.__name__, excname)

@support.thread_unsafe("TESTFN")
def testRaising(self):
self.raise_catch(AttributeError, "AttributeError")
self.assertRaises(AttributeError, getattr, sys, "undefined_attribute")
Expand Down Expand Up @@ -1398,6 +1399,7 @@ def __str__(self):
self.assertRaises(TypeError, str, exc)

@no_tracing
@support.thread_unsafe("captures stderr")
def test_badisinstance(self):
# Bug #2542: if issubclass(e, MyException) raises an exception,
# it should be ignored
Expand Down Expand Up @@ -1521,6 +1523,7 @@ def test_recursion_normalizing_infinite_exception(self):
self.assertIn(b'Done.', out)


@support.thread_unsafe("uses sys.setrecursionlimit")
def test_recursion_in_except_handler(self):

def set_relative_recursion_limit(n):
Expand Down Expand Up @@ -1656,6 +1659,7 @@ class C(object):

@cpython_only
@unittest.skipIf(_testcapi is None, "requires _testcapi")
@support.thread_unsafe("gc_collect()")
def test_memory_error_cleanup(self):
# Issue #5437: preallocated MemoryError instances should not keep
# traceback objects alive.
Expand Down Expand Up @@ -1705,6 +1709,7 @@ def test_errno_ENOTDIR(self):
os.listdir(__file__)
self.assertEqual(cm.exception.errno, errno.ENOTDIR, cm.exception)

@support.thread_unsafe("uses catch_unraisable_exception")
def test_unraisable(self):
# Issue #22836: PyErr_WriteUnraisable() should give sensible reports
class BrokenDel:
Expand All @@ -1724,6 +1729,7 @@ def __del__(self):
f"deallocator {obj_repr}")
self.assertIsNotNone(cm.unraisable.exc_traceback)

@support.thread_unsafe("captures stderr")
def test_unhandled(self):
# Check for sensible reporting of unhandled exceptions
for exc_type in (ValueError, BrokenStrException):
Expand Down Expand Up @@ -1823,6 +1829,7 @@ def g():
next(i)

@unittest.skipUnless(__debug__, "Won't work if __debug__ is False")
@support.thread_unsafe("modifies global AssertionError")
def test_assert_shadowing(self):
# Shadowing AssertionError would cause the assert statement to
# misbehave.
Expand Down Expand Up @@ -1914,6 +1921,7 @@ def test_name_error_has_name(self):
except NameError as exc:
self.assertEqual("bluch", exc.name)

@support.thread_unsafe("captures stderr")
def test_issue45826(self):
# regression test for bpo-45826
def f():
Expand All @@ -1930,6 +1938,7 @@ def f():

self.assertIn("aab", err.getvalue())

@support.thread_unsafe("captures stderr")
def test_issue45826_focused(self):
def f():
try:
Expand Down Expand Up @@ -2050,6 +2059,7 @@ def test_reset_attributes(self):
self.assertEqual(exc.name, None)
self.assertEqual(exc.path, None)

@support.thread_unsafe("check_warnings")
def test_non_str_argument(self):
# Issue #15778
with check_warnings(('', BytesWarning), quiet=True):
Expand Down Expand Up @@ -2332,6 +2342,7 @@ class MySyntaxError(SyntaxError):
^^^^^
""", err.getvalue())

@support.thread_unsafe("TESTFN")
def test_encodings(self):
self.addCleanup(unlink, TESTFN)
source = (
Expand Down
1 change: 1 addition & 0 deletions Python/legacy_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
static Py_ssize_t
setup_tracing(PyThreadState *tstate, Py_tracefunc func, PyObject *arg, PyObject **old_traceobj)
{
assert(tstate->interp->sys_tracing_threads >= 0);
*old_traceobj = NULL;
/* Setup PEP 669 monitoring callbacks and events. */
if (!tstate->interp->sys_trace_initialized) {
Expand Down
7 changes: 7 additions & 0 deletions Tools/tsan/suppressions_free_threading.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ race_top:mi_block_set_nextx
# gh-127266: type slot updates are not thread-safe (test_opcache.test_load_attr_method_lazy_dict)
race_top:update_one_slot

# gh-129701: data race during modification of refcount when interning strings
race:intern_common

# gh-128130: race on _PyRuntime.signals.unhandled_keyboard_interrupt
race_top:_PyErr_Display
race_top:run_eval_code_obj

# https://gist.github.com/mpage/6962e8870606cfc960e159b407a0cb40
thread:pthread_create

Expand Down
Loading