Skip to content

Commit 694f071

Browse files
encukouwebknjaz
andcommitted
Merge reusable-tsan.yml and reusable-ubsan.yml
Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
1 parent 588d9fb commit 694f071

File tree

4 files changed

+126
-170
lines changed

4 files changed

+126
-170
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,17 +597,19 @@ jobs:
597597
free-threading:
598598
- false
599599
- true
600-
uses: ./.github/workflows/reusable-tsan.yml
600+
uses: ./.github/workflows/reusable-san.yml
601601
with:
602+
sanitizer: TSan
602603
config_hash: ${{ needs.build-context.outputs.config-hash }}
603604
free-threading: ${{ matrix.free-threading }}
604605

605606
build-ubsan:
606607
name: Undefined behavior sanitizer
607608
needs: build-context
608609
if: needs.build-context.outputs.run-tests == 'true'
609-
uses: ./.github/workflows/reusable-ubsan.yml
610+
uses: ./.github/workflows/reusable-san.yml
610611
with:
612+
sanitizer: UBSan
611613
config_hash: ${{ needs.build-context.outputs.config-hash }}
612614

613615
cross-build-linux:

.github/workflows/reusable-san.yml

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