Skip to content

Commit

Permalink
Add GCC's sanitizers to C++ API workflow (dynamic analysis)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorreijgwart committed Sep 5, 2024
1 parent 94c2f98 commit cd27142
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,71 @@ jobs:
echo "Not all tests passed!"
exit 1
fi
sanitize:
name: Sanitize ${{ matrix.sanitizer.detects }}
needs: test
runs-on: ubuntu-20.04
strategy:
matrix:
sanitizer:
- { name: UBSAN, detects: 'undefined behavior' }
- { name: ASAN, detects: 'addressability and leaks' }
# - { name: TSAN, detects: 'data races and deadlocks' }
# NOTE: TSAN is disabled until the following bug is resolved:
# https://bugs.launchpad.net/ubuntu/+source/gcc-10/+bug/2029910.
# NOTE: MSAN is not used for now since it also requires all deps to be
# instrumented (recompiled with clang and the MSan flags, LLVM's
# stdlib instead of GCCs,...). We therefore use Valgrind to
# check for uninitialized memory usage errors instead.
fail-fast: false
steps:
- name: Fetch the package's repository
uses: actions/checkout@v4

- name: Setup CMake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.18'

- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ secrets.CCACHE_CACHE_VERSION }}|ubuntu-20.04-gcc-${{ matrix.sanitizer.name }}
create-symlink: true

- name: Setup GTest
run: |
sudo apt-get update
sudo apt-get install -yq --no-install-recommends libgtest-dev
- name: Configure CMake
working-directory: ${{github.workspace}}
run: cmake -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=ON -DUSE_${{ matrix.sanitizer.name }}=ON library/cpp

- name: Build tests
working-directory: ${{github.workspace}}
run: |
echo "::add-matcher::./.github/problem-matchers/gcc.json"
cmake --build build --parallel --config Release
echo "::remove-matcher owner=problem-matcher-gcc::"
- name: Check unit tests with ${{ matrix.sanitizer.name }}
working-directory: ${{github.workspace}}
env:
UBSAN_OPTIONS: halt_on_error=1:print_stacktrace=1
ASAN_OPTIONS: halt_on_error=1:detect_leaks=1:detect_stack_use_after_return=1
TSAN_OPTIONS: halt_on_error=1:second_deadlock_stack=1
run: |
all_tests_passed=1
echo "::add-matcher::./.github/problem-matchers/gcc-sanitizers.json"
for f in `find build/test/src/*/test_* -executable`; do
$f --gtest_color=yes || all_tests_passed=0
done
if [ $all_tests_passed -ne 1 ]; then
echo "Not all tests passed!"
exit 1
fi
echo "::remove-matcher owner=problem-matcher-gcc-ubsan::"
echo "::remove-matcher owner=problem-matcher-gcc-asan::"
echo "::remove-matcher owner=problem-matcher-gcc-tsan::"

0 comments on commit cd27142

Please sign in to comment.