| 1 |
name: Test with compiler sanitizers |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- main |
| 7 |
pull_request: |
| 8 |
branches: |
| 9 |
- main |
| 10 |
- maintenance/** |
| 11 |
paths-ignore: |
| 12 |
- '**.pyi' |
| 13 |
- '**.md' |
| 14 |
- '**.rst' |
| 15 |
|
| 16 |
defaults: |
| 17 |
run: |
| 18 |
shell: bash |
| 19 |
|
| 20 |
concurrency: |
| 21 |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 22 |
cancel-in-progress: true |
| 23 |
|
| 24 |
permissions: |
| 25 |
contents: read # to fetch code (actions/checkout) |
| 26 |
|
| 27 |
jobs: |
| 28 |
clang_ASAN_UBSAN: |
| 29 |
# To enable this workflow on a fork, comment out: |
| 30 |
if: github.repository == 'numpy/numpy' |
| 31 |
runs-on: macos-latest |
| 32 |
steps: |
| 33 |
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 34 |
with: |
| 35 |
submodules: recursive |
| 36 |
fetch-tags: true |
| 37 |
persist-credentials: false |
| 38 |
- name: Set up pyenv |
| 39 |
run: | |
| 40 |
git clone https://github.com/pyenv/pyenv.git "$HOME/.pyenv" |
| 41 |
PYENV_ROOT="$HOME/.pyenv" |
| 42 |
PYENV_BIN="$PYENV_ROOT/bin" |
| 43 |
PYENV_SHIMS="$PYENV_ROOT/shims" |
| 44 |
echo "$PYENV_BIN" >> $GITHUB_PATH |
| 45 |
echo "$PYENV_SHIMS" >> $GITHUB_PATH |
| 46 |
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV |
| 47 |
- name: Check pyenv is working |
| 48 |
run: |
| 49 |
pyenv --version |
| 50 |
- name: Set up LLVM |
| 51 |
run: | |
| 52 |
brew install llvm@20 |
| 53 |
LLVM_PREFIX=$(brew --prefix llvm@20) |
| 54 |
echo CC="$LLVM_PREFIX/bin/clang" >> $GITHUB_ENV |
| 55 |
echo CXX="$LLVM_PREFIX/bin/clang++" >> $GITHUB_ENV |
| 56 |
echo LDFLAGS="-L$LLVM_PREFIX/lib" >> $GITHUB_ENV |
| 57 |
echo CPPFLAGS="-I$LLVM_PREFIX/include" >> $GITHUB_ENV |
| 58 |
- name: Build Python with address sanitizer |
| 59 |
run: | |
| 60 |
CONFIGURE_OPTS="--with-address-sanitizer" pyenv install 3.14 |
| 61 |
pyenv global 3.14 |
| 62 |
- name: Install dependencies |
| 63 |
run: | |
| 64 |
pip install -r requirements/build_requirements.txt |
| 65 |
pip install -r requirements/ci_requirements.txt |
| 66 |
pip install -r requirements/test_requirements.txt |
| 67 |
# xdist captures stdout/stderr, but we want the ASAN output |
| 68 |
pip uninstall -y pytest-xdist |
| 69 |
- name: Build |
| 70 |
run: |
| 71 |
python -m spin build -- -Db_sanitize=address,undefined -Db_lundef=false |
| 72 |
- name: Test |
| 73 |
run: | |
| 74 |
# pass -s to pytest to see ASAN errors and warnings, otherwise pytest captures them |
| 75 |
# Ignore test_casting_floatingpoint_errors on macOS for now - causes crash inside UBSAN |
| 76 |
ASAN_OPTIONS=detect_leaks=0:symbolize=1:strict_init_order=true:allocator_may_return_null=1 \ |
| 77 |
UBSAN_OPTIONS=halt_on_error=1:suppressions=${GITHUB_WORKSPACE}/tools/ci/ubsan_suppressions_arm64.txt \ |
| 78 |
python -m spin test -- -k "not test_casting_floatingpoint_errors" -v -s --timeout=600 --durations=10 |
| 79 |
|
| 80 |
clang_TSAN: |
| 81 |
# To enable this workflow on a fork, comment out: |
| 82 |
if: github.repository == 'numpy/numpy' |
| 83 |
runs-on: ubuntu-latest |
| 84 |
container: |
| 85 |
image: ghcr.io/nascheme/numpy-tsan:3.14t |
| 86 |
options: --shm-size=2g # increase memory for large matrix ops |
| 87 |
|
| 88 |
steps: |
| 89 |
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 90 |
- name: Trust working directory and initialize submodules |
| 91 |
run: | |
| 92 |
git config --global --add safe.directory /__w/numpy/numpy |
| 93 |
git submodule update --init --recursive |
| 94 |
- name: Uninstall pytest-xdist (conflicts with TSAN) |
| 95 |
run: pip uninstall -y pytest-xdist |
| 96 |
|
| 97 |
- name: Upgrade spin (gh-29777) |
| 98 |
run: pip install -U spin |
| 99 |
|
| 100 |
- name: Build NumPy with ThreadSanitizer |
| 101 |
run: python -m spin build -- -Db_sanitize=thread |
| 102 |
|
| 103 |
- name: Run tests under prebuilt TSAN container |
| 104 |
run: | |
| 105 |
export TSAN_OPTIONS="halt_on_error=0:allocator_may_return_null=1:suppressions=$GITHUB_WORKSPACE/tools/ci/tsan_suppressions.txt" |
| 106 |
echo "TSAN_OPTIONS=$TSAN_OPTIONS" |
| 107 |
python -m spin test \ |
| 108 |
`find numpy -name "test*.py" | xargs grep -l "import threading" | tr '\n' ' '` \ |
| 109 |
-- -v -s --timeout=600 --durations=10 |