Skip to content

Commit 1a69ef7

Browse files
committed
Fix code coverage
1 parent d1d15c7 commit 1a69ef7

File tree

3 files changed

+813
-54
lines changed

3 files changed

+813
-54
lines changed

Diff for: .github/workflows/fdp_cpp_api.yaml

+7-9
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ jobs:
4242
- name: Install Dependencies
4343
run: |
4444
sudo apt update
45-
sudo apt install -y lcov libjsoncpp-dev curl libcurl4-openssl-dev libyaml-cpp-dev
45+
sudo apt install -y lcov libjsoncpp-dev curl libcurl4-openssl-dev libyaml-cpp-dev gcovr
4646
- name: Configure Library
4747
run: |
48-
cmake -Bbuild -DFDPAPI_BUILD_TESTS=ON -DFDPAPI_CODE_COVERAGE=ON
48+
cmake -Bbuild -DFDPAPI_BUILD_TESTS=ON -DFDPAPI_CODE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
4949
- name: Fetch cache
5050
uses: actions/[email protected]
5151
with:
@@ -60,21 +60,19 @@ jobs:
6060
wget -nv https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
6161
unzip -q build-wrapper-linux-x86.zip
6262
echo "${PWD}/build-wrapper-linux-x86" >> $GITHUB_PATH
63-
- name: Compile FDP-Cpp-API
64-
run: build-wrapper-linux-x86-64 --out-dir bw-outputs cmake --build build
65-
env:
66-
CIBuild: 1
67-
BUILD_TESTS: True
68-
- name: Run Unit Tests
63+
- name: Build and Run Unit Tests
6964
run: |
70-
cmake --build build --target test
65+
build-wrapper-linux-x86-64 --out-dir bw-outputs cmake --build build --target coverage
7166
if [ $? -eq 0 ]; then
7267
echo "Unit tests completed successfully"
7368
exit 0
7469
else
7570
echo "Unit tests failed"
7671
exit 1
7772
fi
73+
env:
74+
CIBuild: 1
75+
BUILD_TESTS: True
7876
- name: SonarCloud Scan
7977
run: |
8078
sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -X

Diff for: CMakeLists.txt

+15-45
Original file line numberDiff line numberDiff line change
@@ -76,49 +76,19 @@ ENDIF()
7676

7777
# Compile Code Coverage if Specified with Tests
7878
IF( FDPAPI_CODE_COVERAGE AND FDPAPI_BUILD_TESTS )
79-
MESSAGE( STATUS "[Coverage]")
80-
SET( COVERAGE_COMPILER_FLAGS "--coverage -fprofile-arcs -ftest-coverage" )
81-
SET( CMAKE_CXX_FLAGS "-std=gnu++17 -O0 -Wall -Wextra -Werror ${COVERAGE_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}" )
82-
SET( CMAKE_C_FLAGS "-O0 -Wall -Wextra ${COVERAGE_COMPILER_FLAGS} ${CMAKE_C_FLAGS}" )
83-
MESSAGE( "\t CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}" )
84-
MESSAGE( "\t CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}" )
85-
86-
87-
find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl)
88-
find_program( GCOV_PATH gcov )
89-
90-
set(LCOV_EXCLUDES "build/*" "/usr*")
91-
92-
add_custom_target(coverage
93-
94-
# Cleanup lcov
95-
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -directory . -b ${PROJECT_SOURCE_DIR} --zerocounters
96-
97-
# Create baseline to make sure untouched files show up in the report
98-
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -c -i -d . -b ${PROJECT_SOURCE_DIR} -o ${FDPAPI}.base
99-
100-
# Run executables
101-
COMMAND ${CMAKE_BINARY_DIR}/test/${FDPAPI}-tests ${COV_TEST_FLAGS}
102-
103-
# Capturing lcov counters and generating report
104-
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} --directory . -b ${PROJECT_SOURCE_DIR} --capture --output-file ${FDPAPI}.capture
105-
106-
# add baseline counters
107-
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -a ${FDPAPI}.base -a ${FDPAPI}.capture --output-file ${FDPAPI}.total
108-
109-
# filter collected data to final coverage report and merge outputs
110-
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} --remove ${FDPAPI}.total ${LCOV_EXCLUDES} --output-file ${FDPAPI}.info
111-
112-
# Set output files as GENERATED (will be removed on 'make clean')
113-
BYPRODUCTS
114-
${FDPAPI}.base
115-
${FDPAPI}.capture
116-
${FDPAPI}.total
117-
${FDPAPI}.info
118-
${FDPAPI} # report directory
119-
120-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
121-
VERBATIM # Protect arguments to commands
122-
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
123-
)
79+
if(CMAKE_COMPILER_IS_GNUCXX)
80+
LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules")
81+
include(CodeCoverage)
82+
APPEND_COVERAGE_COMPILER_FLAGS()
83+
84+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 --coverage")
85+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
86+
87+
#set(COVERAGE_EXCLUDES 'build/*' 'usr/*')
88+
#set(Coverage_BASE_DIRECTORY ${CMAKE_SOURCE_DIR})
89+
setup_target_for_coverage_gcovr_sonar(NAME coverage
90+
EXECUTABLE bin/${FDPAPI}-tests
91+
DEPENDENCIES ${FDPAPI}-tests
92+
BASE_DIRECTORY ${CMAKE_SOURCE_DIR})
93+
endif()
12494
ENDIF()

0 commit comments

Comments
 (0)