Skip to content

Commit

Permalink
Merge pull request #23 from ethz-asl/feature/coverage
Browse files Browse the repository at this point in the history
Added code coverage in CI
  • Loading branch information
4c3y committed Jan 11, 2024
2 parents 362ada3 + a63e551 commit 59b2f2d
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 14 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/coverage_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Generate coverage report
on:
pull_request:
branches:
- "master"
push:
branches:
- "master"

jobs:
build:
runs-on: [self-hosted, linux]
strategy:
fail-fast: false
matrix:
rosdistro: ['noetic']
gcc: ['10']
cxx: ['17']
container: ros:${{ matrix.rosdistro }}-ros-base-focal
steps:
- uses: actions/checkout@v3
name: Checkout lpp
with:
repository: ethz-asl/lpp
token: ${{ secrets.PAT }}
path: catkin_ws/src/lpp

- name: Install newest git version
run: sudo apt update && sudo apt-get install -y software-properties-common && sudo add-apt-repository -y ppa:git-core/ppa && sudo apt-get update && sudo apt-get install -y git

- name: Install GCC version ${{ matrix.gcc }}
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa -y && sudo apt update && sudo apt install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.gcc }} 100 --slave /usr/bin/g++ g++ /usr/bin/g++-${{ matrix.gcc }}

- name: Install catkin tools
run: sudo apt install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential python3-catkin-tools

- name: Install system dependencies
run: sudo apt install -y libgoogle-glog-dev

- name: Install gcovr
run: sudo apt install -y gcovr

- name: Build lpp
run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE="Debug" -DENABLE_COVERAGE=1 && make
working-directory: catkin_ws/src/lpp
shell: bash

- name: Run unittests
run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && ./test_default && ./test_glog && ./test_lpp && ./test_lpp_custom && ./test_nolog && ./test_roslog
working-directory: catkin_ws/src/lpp/build/devel/lib/lpp
shell: bash

- name: Print coverage
run: gcovr
working-directory: catkin_ws/src/lpp



4 changes: 2 additions & 2 deletions .github/workflows/cpp_ubuntu20_04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
rosdistro: ['noetic']
gcc: ['8', '9', '10']
gcc: ['8', '9', '10', '11']
cxx: ['11', '14', '17']
container: ros:${{ matrix.rosdistro }}-ros-base-focal
name: ROS ${{ matrix.rosdistro }} - GCC ${{ matrix.gcc }} - C++${{ matrix.cxx }}
Expand All @@ -30,7 +30,7 @@ jobs:
run: sudo apt update && sudo apt-get install -y software-properties-common && sudo add-apt-repository -y ppa:git-core/ppa && sudo apt-get update && sudo apt-get install -y git

- name: Install GCC version ${{ matrix.gcc }}
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa -y && sudo apt update && sudo apt install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.gcc }} 100 --slave /usr/bin/g++ g++ /usr/bin/g++-${{ matrix.gcc }}
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && sudo apt update && sudo apt install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.gcc }} 100 --slave /usr/bin/g++ g++ /usr/bin/g++-${{ matrix.gcc }}

- name: Install catkin tools
run: sudo apt install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential python3-catkin-tools
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/deploy_coverage_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Coverage report
on:
push:
branches:
- "master"

jobs:
deploy:
name: Deploy coverage report
environment:
name: github-pages
url: ${{ steps.deployment.outputs.url }}
runs-on: [self-hosted, linux]
strategy:
fail-fast: false
matrix:
rosdistro: ['noetic']
gcc: ['10']
cxx: ['17']
container: ros:${{ matrix.rosdistro }}-ros-base-focal
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
steps:
- uses: actions/checkout@v3
name: Checkout lpp
with:
repository: ethz-asl/lpp
token: ${{ secrets.PAT }}
path: catkin_ws/src/lpp

- name: Install newest git version
run: sudo apt update && sudo apt-get install -y software-properties-common && sudo add-apt-repository -y ppa:git-core/ppa && sudo apt-get update && sudo apt-get install -y git

- name: Install GCC version ${{ matrix.gcc }}
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa -y && sudo apt update && sudo apt install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.gcc }} 100 --slave /usr/bin/g++ g++ /usr/bin/g++-${{ matrix.gcc }}

- name: Install catkin tools
run: sudo apt install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential python3-catkin-tools

- name: Install system dependencies
run: sudo apt install -y libgoogle-glog-dev

- name: Install gcovr
run: sudo apt install -y gcovr

- name: Build lpp
run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE="Debug" -DENABLE_COVERAGE=1 && make
working-directory: catkin_ws/src/lpp
shell: bash

- name: Run unittests
run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && ./test_default && ./test_glog && ./test_lpp && ./test_lpp_custom && ./test_nolog && ./test_roslog
working-directory: catkin_ws/src/lpp/build/devel/lib/lpp
shell: bash

- name: Generate coverage report
run: make coverage
working-directory: catkin_ws/src/lpp/build

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./catkin_ws/src/lpp/build/coverage

- name: Deploy to Github pages
uses: actions/deploy-pages@v4
id: deployment



37 changes: 25 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(LPP_BUILD_TESTS 1)
endif ()

if (ENABLE_COVERAGE)
set(LPP_TEST_CXX_FLAGS ${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage)
message(STATUS "Coverage enabled")
else ()
set(LPP_TEST_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fcompare-debug-second)
endif ()

# Set standard of top level project or C++17
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -85,9 +92,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
test/glog/test_glog_vlog.cc)

target_include_directories(${GLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/glog)
target_link_libraries(${GLOG_TESTS} glog gtest ${catkin_LIBRARIES})
target_link_libraries(${GLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
target_compile_definitions(${GLOG_TESTS} PRIVATE MODE_GLOG)
target_compile_options(${GLOG_TESTS} PRIVATE "-fcompare-debug-second")
target_compile_options(${GLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})

##### Log++ Tests #####
set(LPP_TESTS "test_lpp")
Expand All @@ -101,9 +108,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
test/lpp/test_lpp_vlog.cc)

target_include_directories(${LPP_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/lpp)
target_link_libraries(${LPP_TESTS} glog gtest ${catkin_LIBRARIES})
target_link_libraries(${LPP_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
target_compile_definitions(${LPP_TESTS} PRIVATE MODE_LPP)
target_compile_options(${LPP_TESTS} PRIVATE "-fcompare-debug-second")
target_compile_options(${LPP_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})

##### Log++ Custom Output Tests #####
set(LPP_TESTS_CUSTOM "test_lpp_custom")
Expand All @@ -118,9 +125,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
test/lpp/custom/test_lpp_custom_vlog.cc)

target_include_directories(${LPP_TESTS_CUSTOM} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/lpp)
target_link_libraries(${LPP_TESTS_CUSTOM} glog gtest ${catkin_LIBRARIES})
target_link_libraries(${LPP_TESTS_CUSTOM} glog gtest ${catkin_LIBRARIES} gcov)
target_compile_definitions(${LPP_TESTS_CUSTOM} PRIVATE MODE_LPP)
target_compile_options(${LPP_TESTS_CUSTOM} PRIVATE "-fcompare-debug-second")
target_compile_options(${LPP_TESTS_CUSTOM} PRIVATE ${LPP_TEST_CXX_FLAGS})

##### Roslog Tests #####
set(ROSLOG_TESTS "test_roslog")
Expand All @@ -134,9 +141,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
test/roslog/test_roslog_vlog.cc)

target_include_directories(${ROSLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/roslog)
target_link_libraries(${ROSLOG_TESTS} glog gtest ${catkin_LIBRARIES})
target_link_libraries(${ROSLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
target_compile_definitions(${ROSLOG_TESTS} PRIVATE MODE_ROSLOG)
target_compile_options(${ROSLOG_TESTS} PRIVATE "-fcompare-debug-second")
target_compile_options(${ROSLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})

##### Default Tests #####
set(DEFAULT_TESTS "test_default")
Expand All @@ -153,9 +160,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
test/default/test_severity_conversions.cc)

target_include_directories(${DEFAULT_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/default)
target_link_libraries(${DEFAULT_TESTS} glog gtest ${catkin_LIBRARIES})
target_link_libraries(${DEFAULT_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
target_compile_definitions(${DEFAULT_TESTS} PRIVATE MODE_DEFAULT)
target_compile_options(${DEFAULT_TESTS} PRIVATE "-fcompare-debug-second")
target_compile_options(${DEFAULT_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})

##### Nolog Tests #####
set(NOLOG_TESTS "test_nolog")
Expand All @@ -171,7 +178,13 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
)

target_include_directories(${NOLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/nolog)
target_link_libraries(${NOLOG_TESTS} glog gtest ${catkin_LIBRARIES})
target_link_libraries(${NOLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
target_compile_definitions(${NOLOG_TESTS} PRIVATE MODE_NOLOG)
target_compile_options(${NOLOG_TESTS} PRIVATE "-fcompare-debug-second")
target_compile_options(${NOLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})

add_custom_target(coverage
COMMAND mkdir coverage && cd coverage && gcovr -r ${CMAKE_SOURCE_DIR} --html --html-details -o coverage.html
COMMENT "Generating coverage report"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif ()
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Log++ Logging framework
[![lpp](https://github.com/ethz-asl/lpp/actions/workflows/cpp_ubuntu20_04.yml/badge.svg)](https://github.com/ethz-asl/lpp/actions/workflows/cpp_ubuntu20_04.yml)

[Latest Code Coverage Report](https://ethz-asl.github.io/lpp/coverage.html) (master branch)

![](docs/Log++.svg)
***
Expand Down

0 comments on commit 59b2f2d

Please sign in to comment.