From 32eb8e08ea1e6e950e644d6882e89e1f3b968d90 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 5 Feb 2025 19:07:23 +0000 Subject: [PATCH 1/3] gh-129694: Add `--parallel-threads` TSAN job to CI For now, this just adds a single test suite to the TSAN CI to be run with `--parallel-threads`. --- .github/workflows/reusable-tsan.yml | 3 +++ Lib/test/libregrtest/cmdline.py | 4 ++++ Lib/test/libregrtest/main.py | 6 +++++- Lib/test/libregrtest/tsan.py | 11 +++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-tsan.yml b/.github/workflows/reusable-tsan.yml index 1d2548565d50ef..2f756faf26736e 100644 --- a/.github/workflows/reusable-tsan.yml +++ b/.github/workflows/reusable-tsan.yml @@ -74,6 +74,9 @@ jobs: run: make pythoninfo - name: Tests run: ./python -m test --tsan -j4 + - name: Paralell Tests + if: fromJSON(inputs.free-threading) + run: ./python -m test --tsan-parallel --parallel-threads=4 -j4 - name: Display TSAN logs if: always() run: find "${GITHUB_WORKSPACE}" -name 'tsan_log.*' | xargs head -n 1000 diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py index 1f3b2381c71d45..81c7106ac0c0f4 100644 --- a/Lib/test/libregrtest/cmdline.py +++ b/Lib/test/libregrtest/cmdline.py @@ -168,6 +168,7 @@ def __init__(self, **kwargs) -> None: self.pgo = False self.pgo_extended = False self.tsan = False + self.tsan_parallel = False self.worker_json = None self.start = None self.timeout = None @@ -351,6 +352,9 @@ def _create_parser(): help='enable extended PGO training (slower training)') group.add_argument('--tsan', dest='tsan', action='store_true', help='run a subset of test cases that are proper for the TSAN test') + group.add_argument('--tsan-parallel', action='store_true', + help='run a subset of test cases that are appropriate ' + 'for TSAN with `--parallel-threads=N`') group.add_argument('--fail-env-changed', action='store_true', help='if a test file alters the environment, mark ' 'the test as failed') diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index de377f185f7ed9..2f8fd4c92c119d 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -20,7 +20,7 @@ from .runtests import RunTests, HuntRefleak from .setup import setup_process, setup_test_dir from .single import run_single_test, PROGRESS_MIN_TIME -from .tsan import setup_tsan_tests +from .tsan import setup_tsan_tests, setup_tsan_parallel_tests from .utils import ( StrPath, StrJSON, TestName, TestList, TestTuple, TestFilter, strip_py_suffix, count, format_duration, @@ -60,6 +60,7 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False): self.pgo: bool = ns.pgo self.pgo_extended: bool = ns.pgo_extended self.tsan: bool = ns.tsan + self.tsan_parallel: bool = ns.tsan_parallel # Test results self.results: TestResults = TestResults() @@ -195,6 +196,9 @@ def find_tests(self, tests: TestList | None = None) -> tuple[TestTuple, TestList if self.tsan: setup_tsan_tests(self.cmdline_args) + if self.tsan_parallel: + setup_tsan_parallel_tests(self.cmdline_args) + exclude_tests = set() if self.exclude: for arg in self.cmdline_args: diff --git a/Lib/test/libregrtest/tsan.py b/Lib/test/libregrtest/tsan.py index 00d5779d950e72..1b32deec12bd75 100644 --- a/Lib/test/libregrtest/tsan.py +++ b/Lib/test/libregrtest/tsan.py @@ -28,7 +28,18 @@ 'test_free_threading.test_slots', ] +# Tests that should be run with `--parallel-threads=N` under TSAN. These tests +# typically do not use threads, but are run multiple times in parallel by +# the regression test runner with the `--parallel-threads` option enabled. +TSAN_PARALLEL_TESTS = [ + 'test_abc', +] + def setup_tsan_tests(cmdline_args) -> None: if not cmdline_args: cmdline_args[:] = TSAN_TESTS[:] + +def setup_tsan_parallel_tests(cmdline_args) -> None: + if not cmdline_args: + cmdline_args[:] = TSAN_PARALLEL_TESTS[:] From 85020e47fe1b704f9e89473aad365baf887fcadc Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 5 Feb 2025 19:42:52 +0000 Subject: [PATCH 2/3] Fix typo --- .github/workflows/reusable-tsan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-tsan.yml b/.github/workflows/reusable-tsan.yml index 2f756faf26736e..b92e066aeafedb 100644 --- a/.github/workflows/reusable-tsan.yml +++ b/.github/workflows/reusable-tsan.yml @@ -74,7 +74,7 @@ jobs: run: make pythoninfo - name: Tests run: ./python -m test --tsan -j4 - - name: Paralell Tests + - name: Parallel Tests if: fromJSON(inputs.free-threading) run: ./python -m test --tsan-parallel --parallel-threads=4 -j4 - name: Display TSAN logs From 67aab779e3c0221e8ffdea71a1d8d8a4ab02f54f Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Thu, 6 Feb 2025 09:55:55 -0500 Subject: [PATCH 3/3] Update .github/workflows/reusable-tsan.yml Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- .github/workflows/reusable-tsan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-tsan.yml b/.github/workflows/reusable-tsan.yml index b92e066aeafedb..8ac2f84099e563 100644 --- a/.github/workflows/reusable-tsan.yml +++ b/.github/workflows/reusable-tsan.yml @@ -74,7 +74,7 @@ jobs: run: make pythoninfo - name: Tests run: ./python -m test --tsan -j4 - - name: Parallel Tests + - name: Parallel tests if: fromJSON(inputs.free-threading) run: ./python -m test --tsan-parallel --parallel-threads=4 -j4 - name: Display TSAN logs