From 7497cb26a5562e0829b80fe7156af4f246dfc805 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 7 Feb 2025 20:59:26 +0100 Subject: [PATCH] [CI] Measure code coverage after unit test --- extras/test/unit/.gitignore | 1 + extras/test/unit/CMakeLists.txt | 6 ++++-- extras/test/unit/coverage.sh | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100755 extras/test/unit/coverage.sh diff --git a/extras/test/unit/.gitignore b/extras/test/unit/.gitignore index 567609b1..b9f0c3b0 100644 --- a/extras/test/unit/.gitignore +++ b/extras/test/unit/.gitignore @@ -1 +1,2 @@ build/ +lcov* diff --git a/extras/test/unit/CMakeLists.txt b/extras/test/unit/CMakeLists.txt index 300b8869..a3943e84 100644 --- a/extras/test/unit/CMakeLists.txt +++ b/extras/test/unit/CMakeLists.txt @@ -18,11 +18,13 @@ add_executable(${PROJECT_NAME} ${TEST_SOURCES}) target_include_directories(${PROJECT_NAME} PUBLIC include) # link RadioLib -target_link_libraries(${PROJECT_NAME} RadioLib fmt) +target_link_libraries(${PROJECT_NAME} RadioLib fmt gcov) # set target properties and options set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20) -target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra) +set(BUILD_FLAGS -Wall -Wextra -fprofile-arcs -ftest-coverage -O0) +target_compile_options(${PROJECT_NAME} PRIVATE ${BUILD_FLAGS}) +target_compile_options(RadioLib PRIVATE ${BUILD_FLAGS}) # set RadioLib debug #target_compile_definitions(RadioLib PUBLIC RADIOLIB_DEBUG_BASIC RADIOLIB_DEBUG_SPI RADIOLIB_DEBUG_PROTOCOL) diff --git a/extras/test/unit/coverage.sh b/extras/test/unit/coverage.sh new file mode 100755 index 00000000..f3606c67 --- /dev/null +++ b/extras/test/unit/coverage.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e +filename="lcov" +rm -rf $filename.* +lcov --capture --directory build --output-file "${filename}.info" + +# filter out boost and C++ standard library +lcov --remove "${filename}.info" "/usr/*/boost/*" "/usr/include/c++/*" --output-file "${filename}.info" + +# generate HTML +genhtml "${filename}.info" --output-directory "${filename}.report" +zip -r "${filename}.report.zip" "${filename}.report"