Skip to content

Commit 65d2c51

Browse files
webknjazhugovk
andauthored
GH-111758: Merge TSan and UBSan reusable GHA workflows (#136820)
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 8f59fbb commit 65d2c51

File tree

4 files changed

+139
-183
lines changed

4 files changed

+139
-183
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -585,31 +585,31 @@ jobs:
585585
- name: Tests
586586
run: xvfb-run make ci
587587

588-
build-tsan:
589-
name: >-
590-
Thread sanitizer
591-
${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }}
588+
build-san:
589+
name: >- # ${{ '' } is a hack to nest jobs under the same sidebar category
590+
Sanitizers${{ '' }}
592591
needs: build-context
593592
if: needs.build-context.outputs.run-tests == 'true'
594593
strategy:
595594
fail-fast: false
596595
matrix:
596+
check-name:
597+
- Thread
597598
free-threading:
598599
- false
599600
- true
600-
uses: ./.github/workflows/reusable-tsan.yml
601+
sanitizer:
602+
- TSan
603+
include:
604+
- check-name: Undefined behavior
605+
sanitizer: UBSan
606+
free-threading: false
607+
uses: ./.github/workflows/reusable-san.yml
601608
with:
609+
sanitizer: ${{ matrix.sanitizer }}
602610
config_hash: ${{ needs.build-context.outputs.config-hash }}
603611
free-threading: ${{ matrix.free-threading }}
604612

605-
build-ubsan:
606-
name: Undefined behavior sanitizer
607-
needs: build-context
608-
if: needs.build-context.outputs.run-tests == 'true'
609-
uses: ./.github/workflows/reusable-ubsan.yml
610-
with:
611-
config_hash: ${{ needs.build-context.outputs.config-hash }}
612-
613613
cross-build-linux:
614614
name: Cross build Linux
615615
runs-on: ubuntu-latest
@@ -708,7 +708,7 @@ jobs:
708708
- build-wasi
709709
- test-hypothesis
710710
- build-asan
711-
- build-tsan
711+
- build-san
712712
- cross-build-linux
713713
- cifuzz
714714
if: always()
@@ -743,7 +743,7 @@ jobs:
743743
build-wasi,
744744
test-hypothesis,
745745
build-asan,
746-
build-tsan,
746+
build-san,
747747
cross-build-linux,
748748
'
749749
|| ''

.github/workflows/reusable-san.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Reusable Sanitizer
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
sanitizer:
7+
required: true
8+
type: string
9+
config_hash:
10+
required: true
11+
type: string
12+
free-threading:
13+
description: Whether to use free-threaded mode
14+
required: false
15+
type: boolean
16+
default: false
17+
18+
env:
19+
FORCE_COLOR: 1
20+
21+
jobs:
22+
build-san-reusable:
23+
name: >-
24+
${{ inputs.sanitizer }}${{
25+
inputs.free-threading
26+
&& ' (free-threading)'
27+
|| ''
28+
}}
29+
runs-on: ubuntu-24.04
30+
timeout-minutes: 60
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
persist-credentials: false
35+
- name: Runner image version
36+
run: echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"
37+
- name: Restore config.cache
38+
uses: actions/cache@v4
39+
with:
40+
path: config.cache
41+
key: ${{ github.job }}-${{ env.IMAGE_OS_VERSION }}-${{ inputs.sanitizer }}-${{ inputs.config_hash }}
42+
- name: Install dependencies
43+
run: |
44+
sudo ./.github/workflows/posix-deps-apt.sh
45+
# Install clang
46+
wget https://apt.llvm.org/llvm.sh
47+
chmod +x llvm.sh
48+
49+
if [ "${SANITIZER}" = "TSan" ]; then
50+
sudo ./llvm.sh 17 # gh-121946: llvm-18 package is temporarily broken
51+
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100
52+
sudo update-alternatives --set clang /usr/bin/clang-17
53+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 100
54+
sudo update-alternatives --set clang++ /usr/bin/clang++-17
55+
# Reduce ASLR to avoid TSan crashing
56+
sudo sysctl -w vm.mmap_rnd_bits=28
57+
else
58+
sudo ./llvm.sh 20
59+
fi
60+
61+
- name: Sanitizer option setup
62+
run: |
63+
if [ "${SANITIZER}" = "TSan" ]; then
64+
echo "TSAN_OPTIONS=${SAN_LOG_OPTION} suppressions=${GITHUB_WORKSPACE}/Tools/tsan/suppressions${{
65+
fromJSON(inputs.free-threading)
66+
&& '_free_threading'
67+
|| ''
68+
}}.txt handle_segv=0" >> "$GITHUB_ENV"
69+
else
70+
echo "UBSAN_OPTIONS=${SAN_LOG_OPTION}" >> "$GITHUB_ENV"
71+
fi
72+
echo "CC=clang" >> "$GITHUB_ENV"
73+
echo "CXX=clang++" >> "$GITHUB_ENV"
74+
env:
75+
SANITIZER: ${{ inputs.sanitizer }}
76+
SAN_LOG_OPTION: log_path=${{ github.workspace }}/san_log
77+
- name: Add ccache to PATH
78+
run: |
79+
echo "PATH=/usr/lib/ccache:$PATH" >> "$GITHUB_ENV"
80+
- name: Configure ccache action
81+
uses: hendrikmuhs/ccache-action@v1.2
82+
with:
83+
save: ${{ github.event_name == 'push' }}
84+
max-size: "200M"
85+
- name: Configure CPython
86+
run: >-
87+
./configure
88+
--config-cache
89+
${{
90+
inputs.sanitizer == 'TSan'
91+
&& '--with-thread-sanitizer'
92+
|| '--with-undefined-behavior-sanitizer'
93+
}}
94+
--with-pydebug
95+
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
96+
- name: Build CPython
97+
run: make -j4
98+
- name: Display build info
99+
run: make pythoninfo
100+
- name: Tests
101+
run: >-
102+
./python -m test
103+
${{ inputs.sanitizer == 'TSan' && '--tsan' || '' }}
104+
-j4
105+
- name: Parallel tests
106+
if: >-
107+
inputs.sanitizer == 'TSan'
108+
&& fromJSON(inputs.free-threading)
109+
run: ./python -m test --tsan-parallel --parallel-threads=4 -j4
110+
- name: Display logs
111+
if: always()
112+
run: find "${GITHUB_WORKSPACE}" -name 'san_log.*' | xargs head -n 1000
113+
- name: Archive logs
114+
if: always()
115+
uses: actions/upload-artifact@v4
116+
with:
117+
name: >-
118+
${{ inputs.sanitizer }}-logs-${{
119+
fromJSON(inputs.free-threading)
120+
&& 'free-threading'
121+
|| 'default'
122+
}}
123+
path: san_log.*
124+
if-no-files-found: ignore

.github/workflows/reusable-tsan.yml

Lines changed: 0 additions & 94 deletions
This file was deleted.

.github/workflows/reusable-ubsan.yml

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)