Skip to content

Commit fd5700d

Browse files
rluo8rwgk
andauthored
[no-ci] coverage: fix Linux git ownership and add Windows stack wrapper (#1829)
* coverage: add git safe.directory for linux builds * coverage: run coverage for linux without root * coverage: change github workspace owner for Linux coverage * coverage: run cuda core tests in coverage using 8M thread * Add coverage test helper to run pytest using larger stack --------- Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com>
1 parent cb3c132 commit fd5700d

File tree

2 files changed

+71
-34
lines changed

2 files changed

+71
-34
lines changed

.github/workflows/coverage.yml

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ jobs:
6868
with:
6969
fetch-depth: 0
7070

71+
- name: Fix workspace ownership
72+
run: |
73+
chown -R $(id -u):$(id -g) "$GITHUB_WORKSPACE"
74+
7175
- name: Install dependencies
7276
uses: ./.github/actions/install_unix_deps
7377
continue-on-error: false
@@ -342,46 +346,25 @@ jobs:
342346
cd "${{ steps.install-root.outputs.INSTALL_ROOT }}"
343347
"$GITHUB_WORKSPACE/.venv/Scripts/pytest" -v --cov=./cuda --cov-append --cov-context=test --cov-config="$GITHUB_WORKSPACE/.coveragerc" "$GITHUB_WORKSPACE/cuda_pathfinder/tests"
344348
349+
# Cython linetrace under coverage on Windows needs more stack than the
350+
# default 1 MB thread size. The helper runs pytest on an 8 MB thread.
345351
- name: Run cuda.bindings tests (with 8MB stack)
346352
continue-on-error: true
347353
run: |
348-
cd "${{ steps.install-root.outputs.INSTALL_ROOT }}"
349-
# Run pytest in 8MB stack thread (Cython linetrace requirement)
350-
"$GITHUB_WORKSPACE/.venv/Scripts/python" << PYTEST_EOF
351-
import os
352-
import sys
353-
import threading
354-
import pytest
355-
356-
os.chdir(r'${{ steps.install-root.outputs.INSTALL_ROOT }}')
357-
threading.stack_size(8 * 1024 * 1024)
358-
result = {'code': 1}
359-
360-
def _run():
361-
workspace = os.environ['GITHUB_WORKSPACE']
362-
result['code'] = pytest.main([
363-
'-v',
364-
'--cov=./cuda',
365-
'--cov-append',
366-
'--cov-context=test',
367-
f'--cov-config={workspace}/.coveragerc',
368-
f'{workspace}/cuda_bindings/tests'
369-
])
370-
371-
t = threading.Thread(target=_run)
372-
t.start()
373-
t.join()
374-
375-
print(f'Bindings tests exit code: {result["code"]}')
376-
# Exit with actual code (continue-on-error handles it)
377-
sys.exit(result['code'])
378-
PYTEST_EOF
354+
"$GITHUB_WORKSPACE/.venv/Scripts/python" "$GITHUB_WORKSPACE/ci/tools/run_pytest_with_stack.py" \
355+
--cwd "${{ steps.install-root.outputs.INSTALL_ROOT }}" \
356+
-v --cov=./cuda --cov-append --cov-context=test \
357+
--cov-config="$GITHUB_WORKSPACE/.coveragerc" \
358+
"$GITHUB_WORKSPACE/cuda_bindings/tests"
379359
380-
- name: Run cuda.core tests
360+
- name: Run cuda.core tests (with 8MB stack)
381361
continue-on-error: true
382362
run: |
383-
cd "${{ steps.install-root.outputs.INSTALL_ROOT }}"
384-
"$GITHUB_WORKSPACE/.venv/Scripts/pytest" -v --cov=./cuda --cov-append --cov-context=test --cov-config="$GITHUB_WORKSPACE/.coveragerc" "$GITHUB_WORKSPACE/cuda_core/tests"
363+
"$GITHUB_WORKSPACE/.venv/Scripts/python" "$GITHUB_WORKSPACE/ci/tools/run_pytest_with_stack.py" \
364+
--cwd "${{ steps.install-root.outputs.INSTALL_ROOT }}" \
365+
-v --cov=./cuda --cov-append --cov-context=test \
366+
--cov-config="$GITHUB_WORKSPACE/.coveragerc" \
367+
"$GITHUB_WORKSPACE/cuda_core/tests"
385368
386369
- name: Copy Windows coverage file to workspace
387370
run: |

ci/tools/run_pytest_with_stack.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
"""Run pytest on a thread with a larger stack size.
8+
9+
Cython linetrace instrumentation under coverage on Windows can exceed the
10+
default 1 MB thread stack. This helper spawns a single worker thread with
11+
a configurable stack (default 8 MB) so the rest of the CI workflow stays
12+
readable.
13+
14+
Usage:
15+
python run_pytest_with_stack.py [--stack-mb N] [--cwd DIR] [pytest args ...]
16+
"""
17+
18+
import argparse
19+
import concurrent.futures
20+
import os
21+
import sys
22+
import threading
23+
24+
import pytest
25+
26+
27+
def main():
28+
parser = argparse.ArgumentParser(description=__doc__)
29+
parser.add_argument(
30+
"--stack-mb",
31+
type=int,
32+
default=8,
33+
help="Thread stack size in megabytes (default: 8)",
34+
)
35+
parser.add_argument(
36+
"--cwd",
37+
default=None,
38+
help="Working directory for the test run",
39+
)
40+
args, pytest_args = parser.parse_known_args()
41+
42+
if args.cwd:
43+
os.chdir(args.cwd)
44+
45+
threading.stack_size(args.stack_mb * 1024 * 1024)
46+
47+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
48+
code = pool.submit(pytest.main, pytest_args).result()
49+
50+
sys.exit(code)
51+
52+
53+
if __name__ == "__main__":
54+
main()

0 commit comments

Comments
 (0)