Skip to content

Commit 96da074

Browse files
webknjazhugovk
andcommitted
[3.13] pythonGH-111758: Merge TSan and UBSan reusable GHA workflows (python#136820)
(cherry picked from commit 65d2c51) Co-authored-by: Hugo van Kemenade <[email protected]> Co-authored-by: Sviatoslav Sydorenko <[email protected]>
1 parent 9ab885e commit 96da074

File tree

2 files changed

+130
-7
lines changed

2 files changed

+130
-7
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,20 +545,24 @@ jobs:
545545
- name: Tests
546546
run: xvfb-run make test
547547

548-
build-tsan:
549-
name: >-
550-
Thread sanitizer
551-
${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }}
548+
build-san:
549+
name: >- # ${{ '' } is a hack to nest jobs under the same sidebar category
550+
Sanitizers${{ '' }}
552551
needs: build-context
553552
if: needs.build-context.outputs.run-tests == 'true'
554553
strategy:
555554
fail-fast: false
556555
matrix:
556+
check-name:
557+
- Thread
557558
free-threading:
558559
- false
559560
- true
560-
uses: ./.github/workflows/reusable-tsan.yml
561+
sanitizer:
562+
- TSan
563+
uses: ./.github/workflows/reusable-san.yml
561564
with:
565+
sanitizer: ${{ matrix.sanitizer }}
562566
config_hash: ${{ needs.build-context.outputs.config-hash }}
563567
free-threading: ${{ matrix.free-threading }}
564568

@@ -619,7 +623,7 @@ jobs:
619623
- build-wasi
620624
- test-hypothesis
621625
- build-asan
622-
- build-tsan
626+
- build-san
623627
- cifuzz
624628
if: always()
625629

@@ -651,7 +655,7 @@ jobs:
651655
build-wasi,
652656
test-hypothesis,
653657
build-asan,
654-
build-tsan,
658+
build-san,
655659
'
656660
|| ''
657661
}}

.github/workflows/reusable-san.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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/[email protected]
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: Display logs
106+
if: always()
107+
run: find "${GITHUB_WORKSPACE}" -name 'san_log.*' | xargs head -n 1000
108+
- name: Archive logs
109+
if: always()
110+
uses: actions/upload-artifact@v4
111+
with:
112+
name: >-
113+
${{ inputs.sanitizer }}-logs-${{
114+
fromJSON(inputs.free-threading)
115+
&& 'free-threading'
116+
|| 'default'
117+
}}
118+
path: san_log.*
119+
if-no-files-found: ignore

0 commit comments

Comments
 (0)