Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage improvements. #942

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option(LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP "Websocket++ has been removed from

option(LIBOCPP_ENABLE_V16 "Enable OCPP 1.6 in the ocpp library" ON)
option(LIBOCPP_ENABLE_V201 "Enable OCPP 2.0.1 in the ocpp library" ON)
option(LIBOCPP_ENABLE_COVERAGE_CLEANUP "Cleanup 'old' coverage files before running coverage again" ON)

if((NOT LIBOCPP_ENABLE_V16) AND (NOT LIBOCPP_ENABLE_V201))
message(FATAL_ERROR "At least one of LIBOCPP_ENABLE_V16 and LIBOCPP_ENABLE_V201 needs to be ON")
Expand All @@ -32,8 +33,6 @@ endif()
if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
set(LIBOCPP_BUILD_TESTING ON)
evc_include(CodeCoverage)

append_coverage_compiler_flags()
endif()

# dependencies
Expand Down Expand Up @@ -124,6 +123,8 @@ endif()

if(LIBOCPP_BUILD_TESTING)
include(CTest)
set(LIBOCPP_ROOT_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LIBOCPP_ROOT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(tests)
endif()

Expand Down
28 changes: 28 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(${CMAKE_CURRENT_SOURCE_DIR}/libocpp-unittests.cmake)
include(ProcessorCount)

# For libocpp tests, there is one big executable, which links against the ocpp lib and all other libs.
# When it is useful to link only to the tested cpp files, a separate executable can be created for each file.
Expand All @@ -22,6 +23,7 @@ endif()

set(TEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(GCOVR_DEPENDENCIES)
append_coverage_compiler_flags_to_target(ocpp)


add_libocpp_unittest(NAME libocpp_unit_tests PATH "")
Expand Down Expand Up @@ -80,6 +82,32 @@ add_custom_command(TARGET libocpp_unit_tests POST_BUILD

set(GCOVR_ADDITIONAL_ARGS "--gcov-ignore-parse-errors=negative_hits.warn")

set(GCOVR_DEPENDENCIES libocpp_unit_tests)

# If ev-coverage is installed, remove gcda files and orphaned object / gcno files.
find_program(EV_COVERAGE ev-coverage)

if (NOT EV_COVERAGE)
message("The \"ev-dev-tools\" Python3 package is not installed. You can install it going to
`everest-utils/ev-dev-tools` and type `pip install .`")
else()
if(LIBOCPP_ENABLE_COVERAGE_CLEANUP)
add_custom_target(cleanup_coverage
COMMAND
${EV_COVERAGE}
remove_files
--build-dir=${LIBOCPP_ROOT_BUILD_DIR})
list(APPEND GCOVR_DEPENDENCIES cleanup_coverage)
endif() # LIBOCPP_ENABLE_COVERAGE_CLEANUP
endif() # EV_COVERAGE

# Run gcovr with the number of processors in this system
ProcessorCount(number_of_procs)
if(number_of_procs EQUAL 0)
set(number_of_procs 1)
endif()
set(GCOVR_ADDITIONAL_ARGS "-j;${number_of_procs}")

setup_target_for_coverage_gcovr_html(
NAME ${PROJECT_NAME}_gcovr_coverage
EXECUTABLE ctest
Expand Down