Skip to content

Commit

Permalink
Code coverage testing (#65)
Browse files Browse the repository at this point in the history
* Add code coverage to testing

* Publish code coverage report

* Enabling all unit tests

* Enabling back all ci builds
  • Loading branch information
BAILOOL authored Feb 19, 2024
1 parent fecb429 commit 0f893aa
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
52 changes: 51 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,54 @@ jobs:
mkdir MC-Calib/build && cd MC-Calib/build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4
./tests/boost_tests_run
./tests/boost_tests_run
code-coverage-testing:
runs-on: ubuntu-latest
needs:
- clang-format-lint
- cppcheck
- clang-tidy
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Checkout MC-Calib-data
uses: actions/checkout@v4
with:
repository: BAILOOL/MC-Calib-data
path: ${{ github.workspace }}/data
lfs: 'true'

- name: Unzip MC-Calib-data
run: tar xf ${{ github.workspace }}/data/Blender_Images.tar.gz -C ${{ github.workspace }}/data

- name: Run tests
uses: addnab/docker-run-action@v3
with:
image: bailool/mc-calib-dev:latest
options: -v ${{ github.workspace }}:${{ github.workspace }}
run: |
mkdir ${{ github.workspace }}/build && cd ${{ github.workspace }}/build
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=true ..
make -j4
./tests/boost_tests_run && make coverage
- name: Upload code coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: ${{ github.workspace }}/build/coverage

- name: Setup LCOV for report to PR
uses: hrishikesh-kadam/setup-lcov@v1

- name: Report code coverage to PR
uses: zgosalvez/github-actions-report-lcov@v3
with:
coverage-files: build/coverage.info
minimum-coverage: 77
artifact-name: code-coverage-report-with-github-actions
github-token: ${{ secrets.GITHUB_TOKEN }}
update-comment: true
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
ENDIF(SSSE3_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

if(ENABLE_COVERAGE)
# set compiler flags
set(CMAKE_CXX_FLAGS "-O0 -coverage")
# find required tools
find_program(LCOV lcov REQUIRED)
find_program(GENHTML genhtml REQUIRED)

# add coverage target
add_custom_target(coverage
# gather data
COMMAND ${LCOV} --directory . --capture --output-file coverage.info --exclude '/usr/*'
# generate report
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

add_compile_options(-Wall -Wextra -Wpedantic -Werror)

if(USE_SANITIZERS)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ RUN apt update && apt install -y flex bison && \
#------------------------------ #
# For development #
#------------------------------ #
RUN apt update && apt install -y cppcheck clang-tidy valgrind && \
RUN apt update && apt install -y cppcheck clang-tidy valgrind lcov && \
rm -rf /var/lib/apt/lists/*
12 changes: 11 additions & 1 deletion docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,17 @@ Then, run the valgrind test:
==6274== still reachable: 0 bytes in 0 blocks
==6274== suppressed: 420,593 bytes in 3,714 blocks
9. Create pull request.
9. Code coverage testing

.. code-block:: bash
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=true ..
make -j10
./tests/boost_tests_run && make coverage
10. Create pull request.


Naming convention:
Expand Down

0 comments on commit 0f893aa

Please sign in to comment.