Skip to content

Commit 2f7684c

Browse files
miss-islingtonwebknjazhugovk
authored
[3.14] GH-111758: Merge TSan and UBSan reusable GHA workflows (GH-136820) (#136883)
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua> Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 2caae15 commit 2f7684c

File tree

3 files changed

+139
-101
lines changed

3 files changed

+139
-101
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,20 +557,28 @@ jobs:
557557
- name: Tests
558558
run: xvfb-run make ci
559559

560-
build-tsan:
561-
name: >-
562-
Thread sanitizer
563-
${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }}
560+
build-san:
561+
name: >- # ${{ '' } is a hack to nest jobs under the same sidebar category
562+
Sanitizers${{ '' }}
564563
needs: build-context
565564
if: needs.build-context.outputs.run-tests == 'true'
566565
strategy:
567566
fail-fast: false
568567
matrix:
568+
check-name:
569+
- Thread
569570
free-threading:
570571
- false
571572
- true
572-
uses: ./.github/workflows/reusable-tsan.yml
573+
sanitizer:
574+
- TSan
575+
include:
576+
- check-name: Undefined behavior
577+
sanitizer: UBSan
578+
free-threading: false
579+
uses: ./.github/workflows/reusable-san.yml
573580
with:
581+
sanitizer: ${{ matrix.sanitizer }}
574582
config_hash: ${{ needs.build-context.outputs.config-hash }}
575583
free-threading: ${{ matrix.free-threading }}
576584

@@ -671,7 +679,7 @@ jobs:
671679
- build-wasi
672680
- test-hypothesis
673681
- build-asan
674-
- build-tsan
682+
- build-san
675683
- cross-build-linux
676684
- cifuzz
677685
if: always()
@@ -704,7 +712,7 @@ jobs:
704712
build-wasi,
705713
test-hypothesis,
706714
build-asan,
707-
build-tsan,
715+
build-san,
708716
cross-build-linux,
709717
'
710718
|| ''

.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.

0 commit comments

Comments
 (0)