-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
CI: update sanitizer CI to use python compiled with ASAN and TSAN #28273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+256
−183
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
CI: update sanitizer CI to use python compiled with ASAN and TSAN
- Loading branch information
commit 04fda9bfca644e7be27b2e780ad327d5eb82f609
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
name: Test with compiler sanitizers | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
- maintenance/** | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
contents: read # to fetch code (actions/checkout) | ||
|
||
jobs: | ||
clang_ASAN: | ||
# To enable this workflow on a fork, comment out: | ||
if: github.repository == 'numpy/numpy' | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
submodules: recursive | ||
fetch-tags: true | ||
persist-credentials: false | ||
- name: Set up pyenv | ||
run: | | ||
git clone https://github.com/pyenv/pyenv.git "$HOME/.pyenv" | ||
PYENV_ROOT="$HOME/.pyenv" | ||
PYENV_BIN="$PYENV_ROOT/bin" | ||
PYENV_SHIMS="$PYENV_ROOT/shims" | ||
echo "$PYENV_BIN" >> $GITHUB_PATH | ||
echo "$PYENV_SHIMS" >> $GITHUB_PATH | ||
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV | ||
- name: Check pyenv is working | ||
run: | ||
pyenv --version | ||
- name: Set up LLVM | ||
run: | | ||
brew install llvm@19 | ||
LLVM_PREFIX=$(brew --prefix llvm@19) | ||
echo CC="$LLVM_PREFIX/bin/clang" >> $GITHUB_ENV | ||
echo CXX="$LLVM_PREFIX/bin/clang++" >> $GITHUB_ENV | ||
echo LDFLAGS="-L$LLVM_PREFIX/lib" >> $GITHUB_ENV | ||
echo CPPFLAGS="-I$LLVM_PREFIX/include" >> $GITHUB_ENV | ||
- name: Build Python with address sanitizer | ||
run: | | ||
CONFIGURE_OPTS="--with-address-sanitizer" pyenv install 3.13 | ||
pyenv global 3.13 | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements/build_requirements.txt | ||
pip install -r requirements/ci_requirements.txt | ||
pip install -r requirements/test_requirements.txt | ||
- name: Build | ||
run: | ||
python -m spin build -j2 -- -Db_sanitize=address | ||
- name: Test | ||
run: | | ||
# pass -s to pytest to see ASAN errors and warnings, otherwise pytest captures them | ||
ASAN_OPTIONS=detect_leaks=0:symbolize=1:strict_init_order=true:allocator_may_return_null=1:halt_on_error=1 \ | ||
python -m spin test -- -v -s --timeout=600 --durations=10 | ||
|
||
clang_TSAN: | ||
# To enable this workflow on a fork, comment out: | ||
if: github.repository == 'numpy/numpy' | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
submodules: recursive | ||
fetch-tags: true | ||
persist-credentials: false | ||
- name: Set up pyenv | ||
run: | | ||
git clone https://github.com/pyenv/pyenv.git "$HOME/.pyenv" | ||
PYENV_ROOT="$HOME/.pyenv" | ||
PYENV_BIN="$PYENV_ROOT/bin" | ||
PYENV_SHIMS="$PYENV_ROOT/shims" | ||
echo "$PYENV_BIN" >> $GITHUB_PATH | ||
echo "$PYENV_SHIMS" >> $GITHUB_PATH | ||
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV | ||
- name: Check pyenv is working | ||
run: | ||
pyenv --version | ||
- name: Set up LLVM | ||
run: | | ||
brew install llvm@19 | ||
LLVM_PREFIX=$(brew --prefix llvm@19) | ||
echo CC="$LLVM_PREFIX/bin/clang" >> $GITHUB_ENV | ||
echo CXX="$LLVM_PREFIX/bin/clang++" >> $GITHUB_ENV | ||
echo LDFLAGS="-L$LLVM_PREFIX/lib" >> $GITHUB_ENV | ||
echo CPPFLAGS="-I$LLVM_PREFIX/include" >> $GITHUB_ENV | ||
- name: Build Python with thread sanitizer support | ||
run: | | ||
# free-threaded Python is much more likely to trigger races | ||
CONFIGURE_OPTS="--with-thread-sanitizer" pyenv install 3.13t | ||
pyenv global 3.13t | ||
- name: Install dependencies | ||
run: | | ||
# TODO: remove when a released cython supports free-threaded python | ||
pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython | ||
pip install -r requirements/build_requirements.txt | ||
pip install -r requirements/ci_requirements.txt | ||
pip install -r requirements/test_requirements.txt | ||
- name: Build | ||
run: | ||
python -m spin build -j2 -- -Db_sanitize=thread | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this might also benefit from setting up ccache |
||
- name: Test | ||
run: | | ||
# pass -s to pytest to see TSAN errors and warnings, otherwise pytest captures them | ||
TSAN_OPTIONS=allocator_may_return_null=1:halt_on_error=1 \ | ||
python -m spin test -- -v -s --timeout=600 --durations=10 | ||
- name: Setup tmate session | ||
if: ${{ failure() }} | ||
uses: mxschmitt/action-tmate@v3 |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This takes about 10 minutes and Python releases happen infrequently enough I think we'd benefit from using a cache. Is it ok to add a new Github actions cache entry for this step? I don't think the Python installation is all that big on-disk but I can double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only five minutes on the CI run for this PR 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems fine to me. Not essential though if it's indeed 5 minutes - whatever you prefer.