Skip to content

Commit

Permalink
Add a git action for coverage
Browse files Browse the repository at this point in the history
This action will generate codes coverage for unit tests.
  • Loading branch information
Kaiser-Yang committed May 7, 2024
1 parent 4275204 commit 1b28928
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: generate unit tests coverage
on: [pull_request]
jobs:
run:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: build
shell: bash
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -Dmca_GENERATE_COVERAGE=on
cmake --build build
- name: Install LCOV
shell: bash
run: |
sudo apt-get --assume-yes install lcov > /dev/null
- name: run test
shell: bash
run: ./build/test/mca_unit_test

- name: lcov collection
shell: bash
run: |
cd build
lcov -c -d ./ -o cover.info
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: build/cover.info
verbose: true
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ endif()

option(mca_BUILD_SHARE_LIB "Build shared libraries rather than static libraries" on)
option(mca_BUILD_TEST "Whether or not to build unit test" on)
option(mca_GENERATE_COVERAGE "Whether or not to generate codes coverage report" off)

if (mca_GENERATE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

aux_source_directory(src mca_SOURCE)

Expand Down

0 comments on commit 1b28928

Please sign in to comment.