|
| 1 | +name: Sanitizers |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: [master] |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }} |
| 9 | + cancel-in-progress: true |
| 10 | +defaults: |
| 11 | + run: |
| 12 | + shell: bash -e -l {0} |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + name: sanitizer / ${{ matrix.sys.compiler }} ${{ matrix.sys.version }} / ${{ matrix.config.name }} / ${{ matrix.sys.name }} |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + os: [ubuntu-24.04] |
| 21 | + sys: |
| 22 | + - {compiler: clang, version: '21', name: asan, sanitizer: address} |
| 23 | + - {compiler: clang, version: '21', name: lsan, sanitizer: leak} |
| 24 | + - {compiler: clang, version: '21', name: ubsan, sanitizer: undefined} |
| 25 | + config: |
| 26 | + - {name: Debug} |
| 27 | + |
| 28 | + steps: |
| 29 | + |
| 30 | + - name: Install LLVM and Clang |
| 31 | + if: matrix.sys.compiler == 'clang' |
| 32 | + run: | |
| 33 | + wget https://apt.llvm.org/llvm.sh |
| 34 | + chmod +x llvm.sh |
| 35 | + sudo ./llvm.sh ${{matrix.sys.version}} |
| 36 | + sudo apt-get install -y clang-tools-${{matrix.sys.version}} |
| 37 | + sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${{matrix.sys.version}} 200 |
| 38 | + sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${{matrix.sys.version}} 200 |
| 39 | + sudo update-alternatives --install /usr/bin/clang-scan-deps clang-scan-deps /usr/bin/clang-scan-deps-${{matrix.sys.version}} 200 |
| 40 | + sudo update-alternatives --set clang /usr/bin/clang-${{matrix.sys.version}} |
| 41 | + sudo update-alternatives --set clang++ /usr/bin/clang++-${{matrix.sys.version}} |
| 42 | + sudo update-alternatives --set clang-scan-deps /usr/bin/clang-scan-deps-${{matrix.sys.version}} |
| 43 | +
|
| 44 | + - name: Checkout code |
| 45 | + uses: actions/checkout@v6 |
| 46 | + |
| 47 | + - name: Set conda environment |
| 48 | + uses: mamba-org/setup-micromamba@main |
| 49 | + with: |
| 50 | + environment-name: myenv |
| 51 | + environment-file: environment-dev.yml |
| 52 | + init-shell: bash |
| 53 | + cache-downloads: true |
| 54 | + |
| 55 | + - name: Configure using CMake |
| 56 | + run: | |
| 57 | + export CC=clang |
| 58 | + export CXX=clang++ |
| 59 | + cmake -G Ninja \ |
| 60 | + -Bbuild \ |
| 61 | + -DCMAKE_BUILD_TYPE=${{matrix.config.name}} \ |
| 62 | + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ |
| 63 | + -DBUILD_TESTS=ON \ |
| 64 | + -DUSE_SANITIZER=${{ matrix.sys.sanitizer }} |
| 65 | +
|
| 66 | + - name: Build tests |
| 67 | + working-directory: build |
| 68 | + run: cmake --build . --config ${{matrix.config.name}} --target test_xtensor_lib --parallel 8 |
| 69 | + |
| 70 | + - name: Run tests |
| 71 | + working-directory: build |
| 72 | + run: | |
| 73 | + SAN=${{ matrix.sys.sanitizer }} |
| 74 | + case "$SAN" in |
| 75 | + address) |
| 76 | + export ASAN_OPTIONS=log_path=asan_log_:alloc_dealloc_mismatch=0:halt_on_error=0:handle_abort=0 |
| 77 | + export ASAN_SAVE_DUMPS=AsanDump.dmp |
| 78 | + ;; |
| 79 | + leak) |
| 80 | + export LSAN_OPTIONS=log_path=lsan_log_:halt_on_error=0 |
| 81 | + ;; |
| 82 | + undefined) |
| 83 | + export UBSAN_OPTIONS=log_path=ubsan_log_:halt_on_error=0:print_stacktrace=1 |
| 84 | + ;; |
| 85 | + esac |
| 86 | + ctest -R ^xtest$ --output-on-failure |
| 87 | +
|
| 88 | + - name: Upload sanitizer log |
| 89 | + if: always() |
| 90 | + uses: actions/upload-artifact@v6 |
| 91 | + with: |
| 92 | + name: sanitizer-log-${{ matrix.sys.sanitizer }}-${{ matrix.sys.compiler }}-${{ matrix.sys.version }}-${{ matrix.config.name }}-${{ runner.os }} |
| 93 | + path: '**/*san_log_*' |
| 94 | + if-no-files-found: ignore |
| 95 | + |
| 96 | + - name: Upload sanitizer dump |
| 97 | + if: always() |
| 98 | + uses: actions/upload-artifact@v6 |
| 99 | + with: |
| 100 | + name: sanitizer-dump-${{ matrix.sys.sanitizer }}-${{ matrix.sys.compiler }}-${{ matrix.sys.version }}-${{ matrix.config.name }}-${{ runner.os }} |
| 101 | + path: '**/AsanDump.dmp' |
| 102 | + if-no-files-found: ignore |
| 103 | + |
| 104 | + - name: Return errors if sanitizer log content is not empty |
| 105 | + if: always() |
| 106 | + run: | |
| 107 | + if [ -n "$(find build/test -name '*san_log_*' -type f -size +0 2>/dev/null)" ]; then |
| 108 | + echo "Sanitizer detected errors. See the log for details." |
| 109 | + exit 1 |
| 110 | + fi |
0 commit comments