Skip to content

Commit 455bb8a

Browse files
committed
CI: add pyyaml to ci-nightly tests; integrate #3342 stack-reserve fix
Finding 1 (ci-nightly.yml): The driver-hash test added by the eMudhra backport imports `yaml`, which is not in stdlib. Add `pyyaml==6.0.3 pathspec==0.12.1` to the pip install in the CI-tools unit test step, matching what `main` does. Without this, `ci-nightly` would fail at test collection with ModuleNotFoundError. Finding 2 (coverage.yml): Integrate #3342 ("Fix Windows coverage test stack overflows") onto this branch. Add a `stack-reserve` input to setup-hardened-python; both Windows coverage jobs (build wheel + test wheel) request 8 MiB, letting the action patch the base interpreter with `pefile` and verify the reserve at runtime. Switch the Windows pytest steps from `run_pytest_with_stack.py` to direct `python -m pytest`, since the patched interpreter now provides a larger stack on the main thread and in child processes. The old MSVC `editbin` step is implicitly replaced by the action. Identified in review by rwgk.
1 parent 8ecac04 commit 455bb8a

3 files changed

Lines changed: 56 additions & 11 deletions

File tree

‎.github/actions/setup-hardened-python/action.yml‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ inputs:
3131
venv:
3232
description: Directory for the venv. Defaults to a new directory under RUNNER_TEMP.
3333
default: ""
34+
stack-reserve:
35+
description: >-
36+
Windows only. Raise the base interpreter's main-thread stack reserve to at
37+
least this many bytes. Empty (default) leaves the interpreter unchanged.
38+
default: ""
3439

3540
outputs:
3641
python-path:
@@ -148,3 +153,41 @@ runs:
148153
"${PYTHON}" -m pip install \
149154
"pip @ https://files.pythonhosted.org/packages/3f/06/3e4420302363fbb71be3c7f35ce042f54bfca330e3e66b3a2e3c4cca579f/pip-26.2.2-py3-none-any.whl#sha256=fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70"
150155
fi
156+
157+
- name: Raise the interpreter's stack reserve
158+
if: runner.os == 'Windows' && inputs.stack-reserve != ''
159+
shell: bash --noprofile --norc -xeuo pipefail {0}
160+
env:
161+
PYTHON: ${{ steps.venv.outputs.python-path }}
162+
STACK_RESERVE: ${{ inputs.stack-reserve }}
163+
run: |
164+
# sys.stdout.write avoids a trailing CR from Windows Python's CRLF.
165+
base="$("${PYTHON}" -c 'import sys; sys.stdout.write(sys._base_executable)')"
166+
# Windows cannot overwrite a running executable. Prepare a copy and
167+
# replace the original after the patching interpreter exits.
168+
uv run --no-project --isolated --with pefile==2024.8.26 --python "${base}" python - "${base}" "${STACK_RESERVE}" <<'EOF'
169+
import sys
170+
171+
import pefile
172+
173+
path, reserve = sys.argv[1], int(sys.argv[2])
174+
if reserve <= 0:
175+
raise ValueError("stack-reserve must be a positive number of bytes")
176+
with pefile.PE(path) as pe:
177+
pe.OPTIONAL_HEADER.SizeOfStackReserve = max(pe.OPTIONAL_HEADER.SizeOfStackReserve, reserve)
178+
pe.write(path + ".stack-reserve")
179+
EOF
180+
mv -f -- "${base}.stack-reserve" "${base}"
181+
# Verify the running interpreter's stack, rather than just its header.
182+
"${base}" - "${STACK_RESERVE}" <<'EOF'
183+
import ctypes
184+
import sys
185+
186+
lo, hi = ctypes.c_size_t(), ctypes.c_size_t()
187+
get_limits = ctypes.windll.kernel32.GetCurrentThreadStackLimits
188+
get_limits.argtypes = [ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t)]
189+
get_limits.restype = None
190+
get_limits(ctypes.byref(lo), ctypes.byref(hi))
191+
print("main-thread stack reserve:", hi.value - lo.value)
192+
sys.exit(hi.value - lo.value < int(sys.argv[1]))
193+
EOF

‎.github/workflows/ci-nightly.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949

5050
- name: Run CI tools unit tests
5151
run: |
52-
python -m pip install pytest
52+
python -m pip install pytest pyyaml==6.0.3 pathspec==0.12.1
5353
# Standalone CI tool tests; skip repo-root conftest.py (imports cuda.pathfinder).
5454
python -m pytest -v --noconftest ci/tools/tests
5555

‎.github/workflows/coverage.yml‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,11 @@ jobs:
235235
filter: blob:none
236236

237237
- name: Set up Python
238-
uses: ./.github/actions/setup-hardened-python
238+
uses: $/.github/actions/setup-hardened-python
239239
with:
240240
python-version: ${{ env.PY_VER }}
241241
venv: .venv
242+
stack-reserve: 8388608
242243

243244
- name: Set up MSVC
244245
uses: step-security/msvc-dev-cmd@22c98154b708dbd743e6f27a933cf6ceba3305c4 # v1.13.1
@@ -363,10 +364,11 @@ jobs:
363364
nvidia-smi
364365
365366
- name: Set up Python
366-
uses: ./.github/actions/setup-hardened-python
367+
uses: $/.github/actions/setup-hardened-python
367368
with:
368369
python-version: ${{ env.PY_VER }}
369370
venv: .venv
371+
stack-reserve: 8388608
370372

371373
- name: Set up mini CTK
372374
uses: ./.github/actions/fetch_ctk
@@ -417,22 +419,22 @@ jobs:
417419
cd "${{ steps.install-root.outputs.INSTALL_ROOT }}"
418420
"$GITHUB_WORKSPACE/.venv/Scripts/pytest" -v --cov=./cuda --cov-append --cov-context=test --cov-config="$GITHUB_WORKSPACE/.coveragerc" "$GITHUB_WORKSPACE/cuda_pathfinder/tests"
419421
420-
# Cython linetrace under coverage on Windows needs more stack than the
421-
# default 1 MB thread size. The helper runs pytest on an 8 MB thread.
422-
- name: Run cuda.bindings tests (with 8MB stack)
422+
# The patched interpreter provides the larger stack on the main thread
423+
# and in child interpreters. Deferred cleanup needs pytest on the main thread.
424+
- name: Run cuda.bindings tests
423425
continue-on-error: true
424426
run: |
425-
"$GITHUB_WORKSPACE/.venv/Scripts/python" "$GITHUB_WORKSPACE/ci/tools/run_pytest_with_stack.py" \
426-
--cwd "${{ steps.install-root.outputs.INSTALL_ROOT }}" \
427+
cd "${{ steps.install-root.outputs.INSTALL_ROOT }}"
428+
"$GITHUB_WORKSPACE/.venv/Scripts/python" -m pytest \
427429
-v --cov=./cuda --cov-append --cov-context=test \
428430
--cov-config="$GITHUB_WORKSPACE/.coveragerc" \
429431
"$GITHUB_WORKSPACE/cuda_bindings/tests"
430432
431-
- name: Run cuda.core tests (with 8MB stack)
433+
- name: Run cuda.core tests
432434
continue-on-error: true
433435
run: |
434-
"$GITHUB_WORKSPACE/.venv/Scripts/python" "$GITHUB_WORKSPACE/ci/tools/run_pytest_with_stack.py" \
435-
--cwd "${{ steps.install-root.outputs.INSTALL_ROOT }}" \
436+
cd "${{ steps.install-root.outputs.INSTALL_ROOT }}"
437+
"$GITHUB_WORKSPACE/.venv/Scripts/python" -m pytest \
436438
-v --cov=./cuda --cov-append --cov-context=test \
437439
--cov-config="$GITHUB_WORKSPACE/.coveragerc" \
438440
"$GITHUB_WORKSPACE/cuda_core/tests"

0 commit comments

Comments
 (0)