Skip to content
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

Sanitizers #102

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: Linux
on:
workflow_dispatch:
Expand Down Expand Up @@ -47,10 +48,10 @@ jobs:

- name: Install LLVM and Clang
if: matrix.sys.compiler == 'clang'
uses: egor-tensin/setup-clang@v1
uses: KyleMayes/install-llvm-action@v2
with:
version: ${{matrix.sys.version}}
platform: x64
arch: x64

- name: Install the specified standard library for clang
if: matrix.sys.compiler == 'clang'
Expand Down Expand Up @@ -98,7 +99,8 @@ jobs:
-DBUILD_TESTS=ON \
-DBUILD_EXAMPLES=ON \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DUSE_SANITIZER="address;undefined;leak"

- name: Build library
working-directory: build
Expand All @@ -112,13 +114,30 @@ jobs:
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target test_sparrow_lib --parallel 8

- name: fine-tune asan options
# in asan we get an error from std::regex. ignore it.
run: |
echo "ASAN_OPTIONS=log_path=asan_log_:alloc_dealloc_mismatch=0:halt_on_error=0:handle_abort=0:exitcode=0" >> $GITHUB_ENV
echo "LEAK_OPTIONS=log_path=leak_log_" >> $GITHUB_ENV

- name: Run sccache stat for check
shell: bash
run: ${SCCACHE_PATH} --show-stats

- name: Run tests
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report
run: |
export ASAN_OPTIONS=log_path=asan_log_:alloc_dealloc_mismatch=0:halt_on_error=0:handle_abort=0:exitcode=0
export LEAK_OPTIONS=log_path=leak_log_
cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report
# env:
# # log_path is set to the path where ASAN will write the error report (seems ineffective)
# # alloc_dealloc_mismatch is set to 0 to deactivate unwanted ASAN warnings.
# # halt_on_error is set to 0 to avoid crashing the program after printing the first error report.
# # handle_abort is set to 0 to deactivate calls are handled as crashes by ASAN.
# # exitcode is set to 0 to avoid reporting the build as failed if ASAN detects an error.
# ASAN_OPTIONS: log_path=asan_log_:alloc_dealloc_mismatch=0:halt_on_error=0:handle_abort=0:exitcode=0
# LEAK_OPTIONS: log_path=leak_log_

- name: Upload test results
uses: actions/upload-artifact@v4
Expand All @@ -127,6 +146,23 @@ jobs:
name: test_sparrow_lib_report_Linux_${{ matrix.sys.compiler }}_${{ matrix.sys.version }}_${{ matrix.sys.stdlib }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}}
path: '**/test_sparrow_lib_report.xml'


- name: Upload ASAN log
if: always()
uses: actions/upload-artifact@v4
with:
name: asan-log-${{ matrix.sys.compiler }}-${{ matrix.sys.version }}-${{ matrix.config.name }}-${{ matrix.sys.date-polyfill }}
path: '**/asan_log_*'

- name: Upload LEAK log
if: always()
uses: actions/upload-artifact@v4
with:
name: leak-log-${{ matrix.sys.compiler }}-${{ matrix.sys.version }}-${{ matrix.config.name }}-${{ matrix.sys.date-polyfill }}
path: '**/leak_log_*'


- name: Run all examples
working-directory: build
run: cmake --build . --config ${{matrix.config.name}} --target run_examples

5 changes: 4 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ jobs:
$SPARROW_ADDITIONAL_OPTIONS \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL \
${{env.CMAKE_SANITIZER}}
env:
CMAKE_SANITIZER: ${{ (matrix.config.name == 'Debug' && matrix.sys.compiler == 'msvc') && '-DUSE_SANITIZER=address' || '' }}

- name: Build library
working-directory: build
Expand Down
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ target_link_options(${test_target}
PRIVATE
$<$<BOOL:USE_SANITIZER>:${SANITIZER_LINK_OPTIONS}>)
# We do not use non-standard C++
set_target_properties(${test_target} PROPERTIES CMAKE_CXX_EXTENSIONS OFF)
set_target_properties(${test_target}
PROPERTIES
CMAKE_CXX_EXTENSIONS OFF
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_compile_features(${test_target} PRIVATE cxx_std_20)

add_custom_target(run_tests
Expand Down
Loading