From 63a3bce03f359fd6cb0632fc25d6775a57a51f9c Mon Sep 17 00:00:00 2001 From: "Maaike Zijderveld, iolar" Date: Thu, 16 Jan 2025 16:59:00 +0100 Subject: [PATCH 1/3] append coverage compiler flags only to specific target (instead of globally). Run script to remove gcda files and orphaned object / gcno files (useful after switching branches) Signed-off-by: Maaike Zijderveld, iolar --- CMakeLists.txt | 4 ++-- lib/CMakeLists.txt | 2 ++ tests/CMakeLists.txt | 46 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 583aaed20..d76fe6ad6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,8 +32,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 @@ -126,6 +124,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() diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 12f111075..b745848d1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -202,3 +202,5 @@ endif() # with gcc 10.x and C++11/14, so we need to publish the # C++17 standard target_compile_features(ocpp PUBLIC cxx_std_17) +append_coverage_compiler_flags_to_target(ocpp) + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ae2c21eac..b73128039 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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. @@ -80,6 +81,51 @@ add_custom_command(TARGET libocpp_unit_tests POST_BUILD set(GCOVR_ADDITIONAL_ARGS "--gcov-ignore-parse-errors=negative_hits.warn") +target_include_directories(libocpp_unit_tests PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/lib/ocpp/common +) +target_link_libraries(libocpp_unit_tests PRIVATE + ocpp + GTest::gmock_main + GTest::gtest_main +) + +set(GCOVR_DEPENDENCIES libocpp_unit_tests) + +add_subdirectory(lib/ocpp/common) + +if(LIBOCPP_ENABLE_V16) + add_subdirectory(lib/ocpp/v16) +endif() + +if(LIBOCPP_ENABLE_V201) + add_subdirectory(lib/ocpp/v201) +endif() + +# 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() + add_custom_target(cleanup_coverage + COMMAND + ${EV_COVERAGE} + remove_files + --source-dirs=${LIBOCPP_ROOT_SRC_DIR} + --build-dir=${LIBOCPP_ROOT_BUILD_DIR}) + list(APPEND GCOVR_DEPENDENCIES cleanup_coverage) +endif() + +# 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 From 726c0ed3db39443339e2494680a6950a486ea311 Mon Sep 17 00:00:00 2001 From: "Maaike Zijderveld, iolar" Date: Mon, 20 Jan 2025 13:26:58 +0100 Subject: [PATCH 2/3] Move adding coverage compiler flags to tests CMakeLists. Signed-off-by: Maaike Zijderveld, iolar --- lib/CMakeLists.txt | 2 -- tests/CMakeLists.txt | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b745848d1..12f111075 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -202,5 +202,3 @@ endif() # with gcc 10.x and C++11/14, so we need to publish the # C++17 standard target_compile_features(ocpp PUBLIC cxx_std_17) -append_coverage_compiler_flags_to_target(ocpp) - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b73128039..a86cf1719 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,6 +24,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 "") From d8c0d99e516b1fd1b10e5e9dff3d396ffe61a0b5 Mon Sep 17 00:00:00 2001 From: "Maaike Zijderveld, iolar" Date: Wed, 29 Jan 2025 14:58:50 +0100 Subject: [PATCH 3/3] Add option to disable coverage cleanup. Cleanup after rebase. Signed-off-by: Maaike Zijderveld, iolar --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 37 +++++++++---------------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d76fe6ad6..417a084bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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_V2 "Enable OCPP 2.0.1 and OCPP2.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_V2)) message(FATAL_ERROR "At least one of LIBOCPP_ENABLE_V16 and LIBOCPP_ENABLE_V2 needs to be ON") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a86cf1719..31693eab0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -82,28 +82,8 @@ add_custom_command(TARGET libocpp_unit_tests POST_BUILD set(GCOVR_ADDITIONAL_ARGS "--gcov-ignore-parse-errors=negative_hits.warn") -target_include_directories(libocpp_unit_tests PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/lib/ocpp/common -) -target_link_libraries(libocpp_unit_tests PRIVATE - ocpp - GTest::gmock_main - GTest::gtest_main -) - set(GCOVR_DEPENDENCIES libocpp_unit_tests) -add_subdirectory(lib/ocpp/common) - -if(LIBOCPP_ENABLE_V16) - add_subdirectory(lib/ocpp/v16) -endif() - -if(LIBOCPP_ENABLE_V201) - add_subdirectory(lib/ocpp/v201) -endif() - # If ev-coverage is installed, remove gcda files and orphaned object / gcno files. find_program(EV_COVERAGE ev-coverage) @@ -111,14 +91,15 @@ 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() - add_custom_target(cleanup_coverage - COMMAND - ${EV_COVERAGE} - remove_files - --source-dirs=${LIBOCPP_ROOT_SRC_DIR} - --build-dir=${LIBOCPP_ROOT_BUILD_DIR}) - list(APPEND GCOVR_DEPENDENCIES cleanup_coverage) -endif() + 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)