Skip to content

Commit 59b2f2d

Browse files
authored
Merge pull request #23 from ethz-asl/feature/coverage
Added code coverage in CI
2 parents 362ada3 + a63e551 commit 59b2f2d

File tree

5 files changed

+158
-14
lines changed

5 files changed

+158
-14
lines changed

.github/workflows/coverage_report.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Generate coverage report
2+
on:
3+
pull_request:
4+
branches:
5+
- "master"
6+
push:
7+
branches:
8+
- "master"
9+
10+
jobs:
11+
build:
12+
runs-on: [self-hosted, linux]
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
rosdistro: ['noetic']
17+
gcc: ['10']
18+
cxx: ['17']
19+
container: ros:${{ matrix.rosdistro }}-ros-base-focal
20+
steps:
21+
- uses: actions/checkout@v3
22+
name: Checkout lpp
23+
with:
24+
repository: ethz-asl/lpp
25+
token: ${{ secrets.PAT }}
26+
path: catkin_ws/src/lpp
27+
28+
- name: Install newest git version
29+
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
30+
31+
- name: Install GCC version ${{ matrix.gcc }}
32+
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 }}
33+
34+
- name: Install catkin tools
35+
run: sudo apt install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential python3-catkin-tools
36+
37+
- name: Install system dependencies
38+
run: sudo apt install -y libgoogle-glog-dev
39+
40+
- name: Install gcovr
41+
run: sudo apt install -y gcovr
42+
43+
- name: Build lpp
44+
run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE="Debug" -DENABLE_COVERAGE=1 && make
45+
working-directory: catkin_ws/src/lpp
46+
shell: bash
47+
48+
- name: Run unittests
49+
run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && ./test_default && ./test_glog && ./test_lpp && ./test_lpp_custom && ./test_nolog && ./test_roslog
50+
working-directory: catkin_ws/src/lpp/build/devel/lib/lpp
51+
shell: bash
52+
53+
- name: Print coverage
54+
run: gcovr
55+
working-directory: catkin_ws/src/lpp
56+
57+
58+

.github/workflows/cpp_ubuntu20_04.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
rosdistro: ['noetic']
17-
gcc: ['8', '9', '10']
17+
gcc: ['8', '9', '10', '11']
1818
cxx: ['11', '14', '17']
1919
container: ros:${{ matrix.rosdistro }}-ros-base-focal
2020
name: ROS ${{ matrix.rosdistro }} - GCC ${{ matrix.gcc }} - C++${{ matrix.cxx }}
@@ -30,7 +30,7 @@ jobs:
3030
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
3131

3232
- name: Install GCC version ${{ matrix.gcc }}
33-
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 }}
33+
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 }}
3434

3535
- name: Install catkin tools
3636
run: sudo apt install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential python3-catkin-tools
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Coverage report
2+
on:
3+
push:
4+
branches:
5+
- "master"
6+
7+
jobs:
8+
deploy:
9+
name: Deploy coverage report
10+
environment:
11+
name: github-pages
12+
url: ${{ steps.deployment.outputs.url }}
13+
runs-on: [self-hosted, linux]
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
rosdistro: ['noetic']
18+
gcc: ['10']
19+
cxx: ['17']
20+
container: ros:${{ matrix.rosdistro }}-ros-base-focal
21+
permissions:
22+
pages: write # to deploy to Pages
23+
id-token: write # to verify the deployment originates from an appropriate source
24+
steps:
25+
- uses: actions/checkout@v3
26+
name: Checkout lpp
27+
with:
28+
repository: ethz-asl/lpp
29+
token: ${{ secrets.PAT }}
30+
path: catkin_ws/src/lpp
31+
32+
- name: Install newest git version
33+
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
34+
35+
- name: Install GCC version ${{ matrix.gcc }}
36+
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 }}
37+
38+
- name: Install catkin tools
39+
run: sudo apt install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential python3-catkin-tools
40+
41+
- name: Install system dependencies
42+
run: sudo apt install -y libgoogle-glog-dev
43+
44+
- name: Install gcovr
45+
run: sudo apt install -y gcovr
46+
47+
- name: Build lpp
48+
run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE="Debug" -DENABLE_COVERAGE=1 && make
49+
working-directory: catkin_ws/src/lpp
50+
shell: bash
51+
52+
- name: Run unittests
53+
run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && ./test_default && ./test_glog && ./test_lpp && ./test_lpp_custom && ./test_nolog && ./test_roslog
54+
working-directory: catkin_ws/src/lpp/build/devel/lib/lpp
55+
shell: bash
56+
57+
- name: Generate coverage report
58+
run: make coverage
59+
working-directory: catkin_ws/src/lpp/build
60+
61+
- name: Upload artifact
62+
uses: actions/upload-pages-artifact@v3
63+
with:
64+
path: ./catkin_ws/src/lpp/build/coverage
65+
66+
- name: Deploy to Github pages
67+
uses: actions/deploy-pages@v4
68+
id: deployment
69+
70+
71+

CMakeLists.txt

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
66
set(LPP_BUILD_TESTS 1)
77
endif ()
88

9+
if (ENABLE_COVERAGE)
10+
set(LPP_TEST_CXX_FLAGS ${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage)
11+
message(STATUS "Coverage enabled")
12+
else ()
13+
set(LPP_TEST_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fcompare-debug-second)
14+
endif ()
15+
916
# Set standard of top level project or C++17
1017
if (NOT DEFINED CMAKE_CXX_STANDARD)
1118
set(CMAKE_CXX_STANDARD 17)
@@ -85,9 +92,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
8592
test/glog/test_glog_vlog.cc)
8693

8794
target_include_directories(${GLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/glog)
88-
target_link_libraries(${GLOG_TESTS} glog gtest ${catkin_LIBRARIES})
95+
target_link_libraries(${GLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
8996
target_compile_definitions(${GLOG_TESTS} PRIVATE MODE_GLOG)
90-
target_compile_options(${GLOG_TESTS} PRIVATE "-fcompare-debug-second")
97+
target_compile_options(${GLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})
9198

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

103110
target_include_directories(${LPP_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/lpp)
104-
target_link_libraries(${LPP_TESTS} glog gtest ${catkin_LIBRARIES})
111+
target_link_libraries(${LPP_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
105112
target_compile_definitions(${LPP_TESTS} PRIVATE MODE_LPP)
106-
target_compile_options(${LPP_TESTS} PRIVATE "-fcompare-debug-second")
113+
target_compile_options(${LPP_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})
107114

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

120127
target_include_directories(${LPP_TESTS_CUSTOM} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/lpp)
121-
target_link_libraries(${LPP_TESTS_CUSTOM} glog gtest ${catkin_LIBRARIES})
128+
target_link_libraries(${LPP_TESTS_CUSTOM} glog gtest ${catkin_LIBRARIES} gcov)
122129
target_compile_definitions(${LPP_TESTS_CUSTOM} PRIVATE MODE_LPP)
123-
target_compile_options(${LPP_TESTS_CUSTOM} PRIVATE "-fcompare-debug-second")
130+
target_compile_options(${LPP_TESTS_CUSTOM} PRIVATE ${LPP_TEST_CXX_FLAGS})
124131

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

136143
target_include_directories(${ROSLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/roslog)
137-
target_link_libraries(${ROSLOG_TESTS} glog gtest ${catkin_LIBRARIES})
144+
target_link_libraries(${ROSLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
138145
target_compile_definitions(${ROSLOG_TESTS} PRIVATE MODE_ROSLOG)
139-
target_compile_options(${ROSLOG_TESTS} PRIVATE "-fcompare-debug-second")
146+
target_compile_options(${ROSLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})
140147

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

155162
target_include_directories(${DEFAULT_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/default)
156-
target_link_libraries(${DEFAULT_TESTS} glog gtest ${catkin_LIBRARIES})
163+
target_link_libraries(${DEFAULT_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
157164
target_compile_definitions(${DEFAULT_TESTS} PRIVATE MODE_DEFAULT)
158-
target_compile_options(${DEFAULT_TESTS} PRIVATE "-fcompare-debug-second")
165+
target_compile_options(${DEFAULT_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})
159166

160167
##### Nolog Tests #####
161168
set(NOLOG_TESTS "test_nolog")
@@ -171,7 +178,13 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
171178
)
172179

173180
target_include_directories(${NOLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/nolog)
174-
target_link_libraries(${NOLOG_TESTS} glog gtest ${catkin_LIBRARIES})
181+
target_link_libraries(${NOLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov)
175182
target_compile_definitions(${NOLOG_TESTS} PRIVATE MODE_NOLOG)
176-
target_compile_options(${NOLOG_TESTS} PRIVATE "-fcompare-debug-second")
183+
target_compile_options(${NOLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS})
184+
185+
add_custom_target(coverage
186+
COMMAND mkdir coverage && cd coverage && gcovr -r ${CMAKE_SOURCE_DIR} --html --html-details -o coverage.html
187+
COMMENT "Generating coverage report"
188+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
189+
)
177190
endif ()

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Log++ Logging framework
2+
[![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)
23

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

46
![](docs/Log++.svg)
57
***

0 commit comments

Comments
 (0)