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-112536: Add TSAN builds on Github Actions #116872

Merged
merged 28 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
34cd372
gh-112536: Setting up TSAN test at Github Action
corona10 Mar 15, 2024
8f789df
Apply TSAN to the default build too
corona10 Mar 15, 2024
432c3a2
Update
corona10 Mar 15, 2024
7c04959
Use gcc 11 to resolve compiler issue
corona10 Mar 15, 2024
4d271cb
Remove test_logging from the TSAN test for the temporary
corona10 Mar 15, 2024
853ea8c
Test --with-pydebug
corona10 Mar 15, 2024
43135d4
Use Ubuntu 22.04
corona10 Mar 15, 2024
7304fca
Use --disable-ipv6 sigh..
corona10 Mar 15, 2024
37d048d
revert --with-pydebug
corona10 Mar 15, 2024
b05c9f7
Use clang
corona10 Mar 15, 2024
7e373ee
Reduce ASLR to avoid TSAN crashing
corona10 Mar 15, 2024
920d8b4
Rebirth test_logging
corona10 Mar 15, 2024
73cbf74
Add --with-pydebug
corona10 Mar 15, 2024
0ff8212
Update Tools/tsan/supressions.txt
corona10 Mar 15, 2024
c6dfb25
Add ccache
corona10 Mar 15, 2024
e2e90ee
Address code review
corona10 Mar 16, 2024
2d29262
Don't use sem_clockwait with TSAN
corona10 Mar 16, 2024
e2265a5
Skip tests from test_threading and test_concurrent_futures
corona10 Mar 16, 2024
414c0e9
Revert Tools/tsan/supressions.txt changes
corona10 Mar 16, 2024
71dc4aa
Add skip_if_tsan
corona10 Mar 16, 2024
f399bd2
nit
corona10 Mar 16, 2024
ec743ff
Use reusable workflow
corona10 Mar 16, 2024
e99087f
nit
corona10 Mar 16, 2024
8bfee01
Rename to .github/workflows/reusable-tsan.yml
corona10 Mar 16, 2024
8577792
fix
corona10 Mar 16, 2024
f9c6e56
fix
corona10 Mar 16, 2024
d9afff0
Fix
corona10 Mar 16, 2024
e88086f
nit
corona10 Mar 16, 2024
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
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,24 @@ jobs:
- name: Tests
run: xvfb-run make test

build_tsan:
name: 'Thread sanitizer'
needs: check_source
if: needs.check_source.outputs.run_tests == 'true'
uses: ./.github/workflows/reusable-tsan.yml
with:
config_hash: ${{ needs.check_source.outputs.config_hash }}
options: ./configure --config-cache --with-thread-sanitizer --with-pydebug

build_tsan_free_threading:
name: 'Thread sanitizer (free-threading)'
corona10 marked this conversation as resolved.
Show resolved Hide resolved
needs: check_source
if: needs.check_source.outputs.run_tests == 'true'
uses: ./.github/workflows/reusable-tsan.yml
with:
config_hash: ${{ needs.check_source.outputs.config_hash }}
options: ./configure --config-cache --disable-gil --with-thread-sanitizer --with-pydebug

# CIFuzz job based on https://google.github.io/oss-fuzz/getting-started/continuous-integration/
cifuzz:
name: CIFuzz
Expand Down Expand Up @@ -542,6 +560,8 @@ jobs:
- build_windows_free_threading
- test_hypothesis
- build_asan
- build_tsan
- build_tsan_free_threading
- cifuzz

runs-on: ubuntu-latest
Expand Down Expand Up @@ -575,6 +595,8 @@ jobs:
build_windows,
build_windows_free_threading,
build_asan,
build_tsan,
build_tsan_free_threading,
'
|| ''
}}
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/reusable-tsan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
on:
workflow_call:
inputs:
config_hash:
required: true
type: string
options:
required: true
type: string

jobs:
build_tsan_reusable:
name: 'Thread sanitizer'
runs-on: ubuntu-22.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- name: Runner image version
run: echo "IMAGE_VERSION=${ImageVersion}" >> $GITHUB_ENV
- name: Restore config.cache
uses: actions/cache@v4
with:
path: config.cache
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }}
- name: Install Dependencies
run: |
sudo ./.github/workflows/posix-deps-apt.sh
sudo apt install -y clang
# Reduce ASLR to avoid TSAN crashing
sudo sysctl -w vm.mmap_rnd_bits=28
- name: TSAN Option Setup
run: |
echo "TSAN_OPTIONS=suppressions=${GITHUB_WORKSPACE}/Tools/tsan/supressions.txt" >> $GITHUB_ENV
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
- name: Add ccache to PATH
run: |
echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
- name: Configure ccache action
uses: hendrikmuhs/[email protected]
with:
save: ${{ github.event_name == 'push' }}
max-size: "200M"
- name: Configure CPython
run: ${{ inputs.options }}
- name: Build CPython
run: make -j4
- name: Display build info
run: make pythoninfo
- name: Tests
run: ./python -m test --tsan -j4
4 changes: 4 additions & 0 deletions Lib/test/test_concurrent_futures/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def get_context(self):
self.skipTest("ProcessPoolExecutor unavailable on this system")
if sys.platform == "win32":
self.skipTest("require unix system")
if support.check_sanitizer(thread=True):
self.skipTest("TSAN doesn't support threads after fork")
return super().get_context()


Expand All @@ -111,6 +113,8 @@ def get_context(self):
self.skipTest("ProcessPoolExecutor unavailable on this system")
if sys.platform == "win32":
self.skipTest("require unix system")
if support.check_sanitizer(thread=True):
self.skipTest("TSAN doesn't support threads after fork")
return super().get_context()


Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
skip_if_asan_fork = unittest.skipIf(
support.HAVE_ASAN_FORK_BUG,
"libasan has a pthread_create() dead lock related to thread+fork")
skip_if_tsan_fork = unittest.skipIf(
support.check_sanitizer(thread=True),
"TSAN doesn't support threads after fork")


class BaseTest(unittest.TestCase):
Expand Down Expand Up @@ -731,6 +734,7 @@ def remove_loop(fname, tries):
@support.requires_fork()
@threading_helper.requires_working_threading()
@skip_if_asan_fork
@skip_if_tsan_fork
def test_post_fork_child_no_deadlock(self):
"""Ensure child logging locks are not held; bpo-6721 & bpo-36533."""
class _OurHandler(logging.Handler):
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def skip_unless_reliable_fork(test):
return test


skip_if_tsan_fork = unittest.skipIf(
support.check_sanitizer(thread=True),
"TSAN doesn't support threads after fork")


def requires_subinterpreters(meth):
"""Decorator to skip a test if subinterpreters are not supported."""
return unittest.skipIf(interpreters is None,
Expand Down Expand Up @@ -634,6 +639,7 @@ def test_daemon_param(self):
self.assertTrue(t.daemon)

@skip_unless_reliable_fork
@skip_if_tsan_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.
Expand Down Expand Up @@ -703,6 +709,7 @@ def f():

@skip_unless_reliable_fork
@unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
@skip_if_tsan_fork
def test_main_thread_after_fork(self):
code = """if 1:
import os, threading
Expand Down Expand Up @@ -1271,6 +1278,7 @@ def test_2_join_in_forked_process(self):
self._run_and_join(script)

@skip_unless_reliable_fork
@skip_if_tsan_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.
Expand Down
4 changes: 4 additions & 0 deletions Python/thread_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
#endif
#endif

/* Thread sanitizer doesn't currently support sem_clockwait */
#ifdef _Py_THREAD_SANITIZER
#undef HAVE_SEM_CLOCKWAIT
#endif

/* Whether or not to use semaphores directly rather than emulating them with
* mutexes and condition variables:
Expand Down
Loading