From 1b28928e2de58439c63cd26c472436e67fee78c9 Mon Sep 17 00:00:00 2001 From: Kaiser-Yang <624626089@qq.com> Date: Tue, 7 May 2024 13:51:04 +0800 Subject: [PATCH] Add a git action for coverage This action will generate codes coverage for unit tests. --- .github/workflows/codecov.yml | 38 +++++++++++++++++++++++++++++++++++ CMakeLists.txt | 5 +++++ 2 files changed, 43 insertions(+) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..6a3886e --- /dev/null +++ b/.github/workflows/codecov.yml @@ -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/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: build/cover.info + verbose: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 78bc85a..21ab330 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)