Forked from
Eclipse Projects / Eclipse openpass / opSimulation
1599 commits behind the upstream repository.
-
New cmake-options: - "-D WITH_COVERAGE=ON" to activate, - "-D COVERAGE_EXCLUDES=/usr/;..." for filtering Adds dependencies on: - fastcov, gcov, genhtml - Necessary Find*.cmake packages provided and conditionally activated This option adds two consecutive test targets to each test: - <test>_coverage - <test>_html Build: - "ctest" to generate and run tests and generate html coverage report - Then look for <test_bin_root>/html/index.html Signed-off-by:
Rene Paris <rene.paris@in-tech.com> Signed-off-by:
Reinhard Biegel <reinhard.biegel@in-tech.com>
New cmake-options: - "-D WITH_COVERAGE=ON" to activate, - "-D COVERAGE_EXCLUDES=/usr/;..." for filtering Adds dependencies on: - fastcov, gcov, genhtml - Necessary Find*.cmake packages provided and conditionally activated This option adds two consecutive test targets to each test: - <test>_coverage - <test>_html Build: - "ctest" to generate and run tests and generate html coverage report - Then look for <test_bin_root>/html/index.html Signed-off-by:
Rene Paris <rene.paris@in-tech.com> Signed-off-by:
Reinhard Biegel <reinhard.biegel@in-tech.com>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
TestCoverage.cmake 1.88 KiB
################################################################################
# Copyright (c) 2021 in-tech GmbH
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
################################################################################
##
# Set compiler flags for code coverage
#
# @author René Paris, in-tech GmbH
#
function(set_coverage_compiler_flags)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage -O0" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage -O0" PARENT_SCOPE)
endfunction()
##
# Adds a depended test stage for collection of
# coverage information and coverage report generation
#
# ADD_TEST_COVERAGE_FASTCOV(NAME)
# - NAME: Name of the test target, to which the coverage belongs
#
# @author René Paris, in-tech GmbH
#
function(add_test_coverage_fastcov)
set(options, "")
set(oneValueArgs NAME)
set(multiValueArgs "")
cmake_parse_arguments(COVERAGE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(FASTCOV_COMMAND ${FASTCOV_EXECUTABLE}
--gcov ${GCOV_EXECUTABLE}
--search-directory ${CMAKE_CURRENT_BINARY_DIR}
--process-gcno
--lcov
--output ${COVERAGE_NAME}.info
--exclude ${COVERAGE_EXCLUDES}
)
set(GENHTML_COMMAND ${GENHTML_EXECUTABLE}
--demangle-cpp
-o ${CMAKE_CURRENT_BINARY_DIR}/html ${COVERAGE_NAME}.info
)
add_test(NAME ${COVERAGE_NAME}_coverage COMMAND ${FASTCOV_COMMAND})
add_test(NAME ${COVERAGE_NAME}_html COMMAND ${GENHTML_COMMAND})
set_tests_properties(${COVERAGE_NAME}_coverage PROPERTIES DEPENDS ${COVERAGE_NAME})
set_tests_properties(${COVERAGE_NAME}_html PROPERTIES DEPENDS ${COVERAGE_NAME}_coverage)
endfunction()