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

[CI] Add tests coverage in libmamba #2866

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
18 changes: 18 additions & 0 deletions .github/workflows/unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ jobs:
restore-keys: |
libmamba-${{ matrix.os }}
- name: Build libmamba
env:
enable_cov: ${{ ((matrix.os == 'ubuntu-latest') && (matrix.build_type == 'Debug')) || false }}
shell: bash -l {0}
run: |
cmake -B build/ \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D ENABLE_COVERAGE=${{ env.enable_cov }} \
-D BUILD_LIBMAMBA=ON \
-D BUILD_SHARED=ON \
-D BUILD_LIBMAMBA_TESTS=ON \
Expand All @@ -54,6 +57,21 @@ jobs:
run: |
unset CONDARC # Interferes with tests
cd build && ninja test
- name: Coverage
if: ${{ ((matrix.os == 'ubuntu-latest') && (matrix.build_type == 'Debug')) || false }}
shell: bash -l {0}
run: |
cd build && ninja coverage
- name: Upload coverage to Coveralls
if: ${{ ((matrix.os == 'ubuntu-latest') && (matrix.build_type == 'Debug')) || false }}
uses: coverallsapp/github-action@v2
env:
NODE_COVERALLS_DEBUG: 1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ${{github.workspace}}/build/coverage.info
format: lcov
git-branch: gcov
- name: Show build cache statistics
run: sccache --show-stats

Expand Down
13 changes: 10 additions & 3 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,31 @@ endif ()

option(ENABLE_ASAN "Enable Address-Sanitizer (currently only supported on GCC and Clang)" OFF)

if(ENABLE_ASAN)
if (ENABLE_ASAN)
message(WARNING "Address-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=address)
add_link_options(-fno-omit-frame-pointer -fsanitize=address)
endif()

if(ENABLE_TSAN)
if (ENABLE_TSAN)
message(WARNING "Thread-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=thread)
add_link_options(-fno-omit-frame-pointer -fsanitize=thread)
endif()

if(ENABLE_USAN)
if (ENABLE_USAN)
message(WARNING "Undefined-Sanitizer instrumentation will be injected into binaries - do not release these binaries")
add_compile_options(-fno-omit-frame-pointer -fsanitize=undefined)
add_link_options(-fno-omit-frame-pointer -fsanitize=undefined)
endif()

# Code coverage
option(ENABLE_COVERAGE "Enable code testing coverage" OFF)

if (ENABLE_COVERAGE)
add_compile_options(--coverage)
add_link_options(--coverage)
endif()

# Source files
# ============
Expand Down
1 change: 1 addition & 0 deletions libmamba/environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ dependencies:
- cli11 >=2.2
- spdlog
- fmt
- lcov
- sel(win): winreg
13 changes: 13 additions & 0 deletions libmamba/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,16 @@ target_compile_definitions(
target_compile_features(test_libmamba PUBLIC cxx_std_17)

add_custom_target(test COMMAND test_libmamba DEPENDS test_libmamba)

# Generate tests coverage report
if (ENABLE_COVERAGE)
find_program(LCOV lcov REQUIRED)
find_program(GENHTML genhtml REQUIRED)

add_custom_target(coverage
# Gather data
COMMAND ${LCOV} --directory . --capture --output-file coverage.info
# Generate report
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
Loading