-
Notifications
You must be signed in to change notification settings - Fork 7
372 lines (341 loc) · 13.5 KB
/
tests-with-pydebug.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
name: Tests with PyDebug
on:
push:
branches:
- main
pull_request:
paths:
- setup.py
- setup.cfg
- pyproject.toml
- MANIFEST.in
- CMakeLists.txt
- include/**
- src/**
- tests/**
- optree/**
- .github/workflows/tests-with-pydebug.yml
# Allow to trigger the workflow manually
workflow_dispatch:
permissions:
contents: read
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
CMAKE_BUILD_TYPE: "Debug"
OPTREE_CXX_WERROR: "ON"
PYTHON: "python" # to be updated
PYTHON_TAG: "py3" # to be updated
PYTHON_VERSION: "3" # to be updated
PYENV_ROOT: "~/.pyenv" # to be updated
COLUMNS: "128"
jobs:
test:
name: Test for CPython ${{ matrix.python-version }}${{ matrix.python-abiflags }} on ${{ matrix.runner }}
runs-on: ${{ matrix.runner }}
strategy:
matrix:
runner: [ubuntu-latest, macos-latest, windows-latest]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
python-abiflags: ["d", "td"]
exclude:
- python-version: "3.8"
python-abiflags: "td"
- python-version: "3.9"
python-abiflags: "td"
- python-version: "3.10"
python-abiflags: "td"
- python-version: "3.11"
python-abiflags: "td"
- python-version: "3.12"
python-abiflags: "td"
fail-fast: false
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up pyenv
id: setup-pyenv-unix
if: runner.os != 'Windows'
run: |
export PYENV_ROOT="${HOME}/.pyenv"
export PATH="${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}"
export PATH="${PWD}/venv/bin:${PATH}"
git clone https://github.com/pyenv/pyenv.git "${PYENV_ROOT}"
echo "PYENV_ROOT=${PYENV_ROOT}" >> "${GITHUB_ENV}"
echo "PATH=${PATH}" >> "${GITHUB_ENV}"
if [[ "${{ runner.os }}" == 'Linux' ]]; then
sudo apt-get update -qq && sudo apt-get install -yqq --no-install-recommends \
make \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libsqlite3-dev \
libncurses-dev \
libreadline-dev \
libgdbm-dev \
liblzma-dev
elif [[ "${{ runner.os }}" == 'macOS' ]]; then
brew install --only-dependencies python@3
fi
- name: Set up pyenv
id: setup-pyenv-windows
if: runner.os == 'Windows'
shell: pwsh
run: |
$Env:PYENV_ROOT = "$Env:USERPROFILE\.pyenv"
$Env:PATH = "$Env:PYENV_ROOT\pyenv-win\bin;$Env:PYENV_ROOT\pyenv-win\shims;$Env:PATH"
$Env:PATH = "$(Get-Location)\venv\Scripts;$Env:PATH"
git clone https://github.com/pyenv-win/pyenv-win.git "$Env:PYENV_ROOT"
Write-Output "PYENV_ROOT=$Env:PYENV_ROOT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PATH=$Env:PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Determine Python version
shell: bash
run: |
if [[ "${{ runner.os }}" == 'Windows' ]]; then
pyenv update
fi
echo "::group::pyenv install --list"
pyenv install --list
echo "::endgroup::"
if [[ "${{ matrix.python-abiflags }}" == *t* ]]; then
echo "PYTHON_GIL=0" >> "${GITHUB_ENV}"
fi
if [[ "${{ runner.os }}" != 'Windows' && "${{ matrix.python-abiflags }}" == *t* ]]; then
PYTHON_VERSION="$(
pyenv install --list | tr -d ' ' | grep -E "^${{ matrix.python-version }}" |
grep -vF '-' | grep -E '[0-9]t$' | sort -rV | head -n 1
)"
elif ! PYTHON_VERSION="$(pyenv latest --known "${{ matrix.python-version }}")"; then
PYTHON_VERSION="$(
pyenv install --list | tr -d ' ' | grep -E "^${{ matrix.python-version }}" |
grep -vF '-' | grep -E '[0-9]$' | sort -rV | head -n 1
)"
fi
echo "PYTHON_VERSION=${PYTHON_VERSION}" | tee -a "${GITHUB_ENV}"
- uses: actions/cache@v4
id: pyenv-cache
with:
path: ${{ env.PYENV_ROOT }}
key: ${{ runner.os }}-pyenv-${{ matrix.python-version }}${{ matrix.python-abiflags }}-${{ env.PYTHON_VERSION }}
- name: Set up Python
if: steps.pyenv-cache.outputs.cache-hit != 'true'
shell: bash
run: |
set -x
PYENV_INSTALL_ARGS=()
if [[ "${{ runner.os }}" != 'Windows' ]]; then
if [[ "${{ matrix.python-abiflags }}" == *d* ]]; then
PYENV_INSTALL_ARGS+=("--debug")
fi
else
pyenv update
fi
pyenv install ${{ env.PYTHON_VERSION }} "${PYENV_INSTALL_ARGS[@]}"
if [[ "${{ runner.os }}" == 'Windows' ]]; then
INSTALL_ARGS=(
"SimpleInstall=1"
"InstallAllUsers=0"
"Include_dev=1"
"Include_lib=1"
"Include_exe=1"
"Include_pip=1"
"Include_tools=1"
"Include_launcher=0"
"Include_test=0"
)
if [[ "${{ matrix.python-abiflags }}" == *d* ]]; then
INSTALL_ARGS+=(
"Include_debug=1"
"Include_symbols=1"
)
fi
if [[ "${{ matrix.python-abiflags }}" == *t* ]]; then
INSTALL_ARGS+=(
"Include_freethreaded=1"
)
fi
INSTALL_ARGS+=(
'TargetDir="${{ env.PYENV_ROOT }}\pyenv-win\versions\${{ env.PYTHON_VERSION }}"'
)
INSTALLER='${{ env.PYENV_ROOT }}\pyenv-win\install_cache\'"$(
cd '${{ env.PYENV_ROOT }}\pyenv-win\install_cache' &&
find . -name "*-${{ env.PYTHON_VERSION }}-*.exe" |
head -n 1 | cut -c3-
)"
pyenv uninstall ${{ env.PYTHON_VERSION }}
pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command \
"${INSTALLER} /quiet /uninstall 2>&1 | Out-Default"
pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command \
"${INSTALLER} /quiet ${INSTALL_ARGS[*]} 2>&1 | Out-Default"
fi
pyenv versions
pyenv global "$(pyenv versions | grep -F '${{ env.PYTHON_VERSION }}' | tr -d ' ')"
pyenv rehash
- name: Set up Environment
shell: bash
run: |
set -x
echo "::group::pyenv shims"
pyenv shims
echo "::endgroup::"
PYTHON_EXE="${{ env.PYTHON }}"
if [[ "${{ runner.os }}" == 'Windows' ]]; then
if [[ "${{ matrix.python-abiflags }}" == *t* ]]; then
PYTHON_EXE="${PYTHON_EXE}${{ matrix.python-version }}t"
fi
if [[ "${{ matrix.python-abiflags }}" == *d* ]]; then
PYTHON_EXE="${PYTHON_EXE}_d"
export PYTHON="${PYTHON}_d"
echo "PYTHON=${PYTHON}" | tee -a "${GITHUB_ENV}"
else
echo "CMAKE_BUILD_TYPE=Release" | tee -a "${GITHUB_ENV}"
fi
fi
"${PYTHON_EXE}" -m venv venv # PATH is already updated in step setup-pyenv
echo "::group::Python executables"
if [[ "${{ runner.os }}" != 'Windows' ]]; then
ls -alh venv/bin
else
ls -alh venv/Scripts
fi
echo "::endgroup::"
"${PYTHON}" -VV
echo "::group::Upgrade pip"
"${PYTHON}" -m pip install --upgrade pip setuptools wheel rich
echo "::endgroup::"
echo "::group::Python sysconfig"
"${PYTHON}" -c 'import rich, sysconfig; rich.print(sysconfig.get_config_vars())'
echo "::endgroup::"
export PYTHON_TAG="$(
echo 'import sys; print(
"{0.name[0]}p{1.major}{1.minor}".format(
sys.implementation,
sys.version_info,
).lower(),
)' | "${PYTHON}" -
)${{ matrix.python-abiflags }}"
echo "PYTHON_TAG=${PYTHON_TAG}" | tee -a "${GITHUB_ENV}"
- name: Enable core dump generation (Linux)
if: runner.os == 'Linux'
run: |
sudo sysctl -w kernel.core_pattern="core.${PYTHON_TAG}.%P"
sudo sysctl -w kernel.core_uses_pid=0
sudo sysctl -w fs.suid_dumpable=1
sysctl kernel.core_pattern kernel.core_uses_pid fs.suid_dumpable
- name: Enable core dump generation (macOS)
if: runner.os == 'macOS'
run: |
sudo sysctl -w kern.corefile="core.${PYTHON_TAG}.%P"
sudo sysctl -w kern.coredump=1
sudo sysctl -w kern.sugid_coredump=1
sysctl kern.corefile kern.coredump kern.sugid_coredump
- name: Enable core dump generation (Windows)
if: runner.os == 'Windows'
run: |
$pwd = Get-Location
$Env:_NT_SOURCE_PATH = "$pwd;${{ env.PYENV_ROOT }}\pyenv-win\versions\${{ env.PYTHON_VERSION }}"
$Env:_NT_SYMBOL_PATH = "cache*$pwd\.symcache;$Env:_NT_SOURCE_PATH;srv*https://msdl.microsoft.com/download/symbols"
Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits" -Directory | Sort-Object -Property Name
$WindowsKitsDir = "C:\Program Files (x86)\Windows Kits\10"
$DebuggersDir = "$WindowsKitsDir\Debuggers\x64"
Get-ChildItem -Path $DebuggersDir
$Env:PATH = "$DebuggersDir;$Env:PATH"
$PYTEST = 'cdb -gG -o -c ".dump /ma /u core.dmp; !py; g; q" ${{ env.PYTHON }} -X dev -m pytest'
Write-Output "_NT_SOURCE_PATH=$Env:_NT_SOURCE_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "_NT_SYMBOL_PATH=$Env:_NT_SYMBOL_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PATH=$Env:PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PYTEST=$PYTEST" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
cdb -version
- name: Install OpTree
run: |
${{ env.PYTHON }} -m pip install -vv --editable '.[test]'
- name: Test with pytest
shell: bash
run: |
set -x
ulimit -c unlimited
ulimit -a
PYTESTOPTS=(
"--exitfirst"
"--cov-report=xml:coverage-${{ env.PYTHON_TAG }}-${{ runner.os }}.xml"
"--junit-xml=junit-${{ env.PYTHON_TAG }}-${{ runner.os }}.xml"
)
make test PYTESTOPTS="${PYTESTOPTS[*]}"
if [[ -n "$(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")" ]]; then
exit 1
fi
- name: List generated files
if: ${{ !cancelled() }}
shell: bash
run: |
find . -type f -name '*.py[co]' -delete
find . -depth -type d -name "__pycache__" -exec rm -r "{}" +
if git status --ignored --porcelain | grep -qvE '/$'; then
ls -alh $(git status --ignored --porcelain | grep -vE '/$' | cut -d ' ' -f2)
fi
- name: Collect backtraces from coredumps (if any)
if: ${{ !cancelled() }}
shell: bash
run: |
if [[ -n "$(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")" ]]; then
echo "Found core dumps:"
ls -alh $(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")
BACKTRACE_COMMAND=""
if [[ "${{ runner.os }}" == 'Linux' ]]; then
echo "::group::Install GDB"
(
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update -qq && sudo apt-get install -yqq gdb
)
echo "::endgroup::"
BACKTRACE_COMMAND="gdb --exec ${{ env.PYTHON }} --core '{}' -ex 'bt -full' -ex 'q'"
elif [[ "${{ runner.os }}" == 'macOS' ]]; then
echo "::group::Install LLDB"
brew install llvm --quiet
echo "::endgroup::"
BACKTRACE_COMMAND="lldb --file ${{ env.PYTHON }} --core '{}' -o 'bt all' -o 'q'"
elif [[ "${{ runner.os }}" == 'Windows' ]]; then
BACKTRACE_COMMAND="cdb -z '{}' -c \"!py; !analyze -vv; .ecxr; kP; q\""
fi
if [[ -n "${BACKTRACE_COMMAND}" ]]; then
echo "Collecting backtraces:"
find . -iname "core.*.[1-9]*" -exec bash -xc "
echo '::group::backtrace from: {}';
${BACKTRACE_COMMAND};
echo '::endgroup::';
" ';'
find . -iname "core_*.dmp" -exec bash -xc "
echo '::group::backtrace from: {}';
${BACKTRACE_COMMAND};
echo '::endgroup::';
" ';'
fi
fi
- name: Upload JUnit results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: tests/junit-${{ env.PYTHON_TAG }}.xml
flags: junit-${{ env.PYTHON_TAG }}
name: junit-umbrella
verbose: true
fail_ci_if_error: false
- name: Upload core dump file
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: coredump-${{ env.PYTHON_TAG }}-${{ runner.os }}
path: |
tests/core.*
tests/core_*.dmp
if-no-files-found: ignore