Commit edecce16 authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED uncomment test coverage launch

see https://forge.imag.fr/plugins/mediawiki/wiki/camitk/index.php/Testcoverage
for usage documentation
parent d7653d11
......@@ -34,7 +34,7 @@ camitk_opensource_packaging()
# using https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
# requires lcov to be installed on the machine
if(CMAKE_COMPILER_IS_GNUCXX)
option(CAMITK_COVERAGE "Do you want to check test coverage?" OFF)
option(CAMITK_COVERAGE "Do you want to check test coverage? If ON, run the test with 'make test'" OFF)
if (CAMITK_COVERAGE)
include(${CMAKE_CURRENT_SOURCE_DIR}/sdk/cmake/modules/CodeCoverage.cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
......
# CamiTK code coverage macro are from additional CMake modules published on github by Lars Bilke.
# see https://github.com/bilke/cmake-modules for more scripts
#
# TODO include this to debian/copyright:
# ---
# Files: sdk/cmake/modules/CodeCoverage.cmake
# Copyright: © 2012 - 2015, Lars Bilke
# License: BSD-3-clause
# Comment: see original sources at https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
# ---
#
# Copyright (c) 2012 - 2015, Lars Bilke
# All rights reserved.
#
......@@ -47,23 +58,23 @@
#
# 3. Set compiler flags to turn off optimization and enable coverage:
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
#
# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
# which runs your test executable and produces a lcov code coverage report:
# Example:
# SETUP_TARGET_FOR_COVERAGE(
# my_coverage_target # Name for custom target.
# test_driver # Name of the test driver executable that runs the tests.
# # NOTE! This should always have a ZERO as exit code
# # otherwise the coverage generation will not complete.
# coverage # Name of output directory.
# )
# SETUP_TARGET_FOR_COVERAGE(
# my_coverage_target # Name for custom target.
# test_driver # Name of the test driver executable that runs the tests.
# # NOTE! This should always have a ZERO as exit code
# # otherwise the coverage generation will not complete.
# coverage # Name of output directory.
# )
#
# 4. Build a Debug build:
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# make
# make my_coverage_target
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# make
# make my_coverage_target
#
#
......@@ -74,15 +85,15 @@ FIND_PROGRAM( GENHTML_PATH genhtml )
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
IF(NOT GCOV_PATH)
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
ENDIF() # NOT GCOV_PATH
IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
ENDIF()
IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
ENDIF()
ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX)
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
ENDIF() # CHECK VALID COMPILER
SET(CMAKE_CXX_FLAGS_COVERAGE
......@@ -114,37 +125,26 @@ ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
# Param _targetname The name of new the custom make target
# Param _testrunner The name of the target which runs the tests.
# MUST return ZERO always, even on errors.
# If not, no coverage report will be created!
# MUST return ZERO always, even on errors.
# If not, no coverage report will be created!
# Param _outputname lcov output is generated as _outputname.info
# HTML report is generated in _outputname/index.html
# Optional fourth parameter is passed as arguments to _testrunner
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF() # NOT LCOV_PATH
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF() # NOT GENHTML_PATH
SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info")
SET(coverage_cleaned "${coverage_info}.cleaned")
SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}")
# COMMAND ${test_command}
# COMMAND ${test_command}
#set(list_var "${ARGN}")
# set(list_var "${ARGV3}")
# message("*************** ARGC=${ARGC}")
# set(argi "4")
# message("*************** ARGV4=${ARGV${argi}}")
# foreach(loop_var IN LISTS list_var)
# message("****************** ${loop_var}")
# endforeach()
IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF() # NOT LCOV_PATH
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF() # NOT GENHTML_PATH
SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info")
SET(coverage_cleaned "${coverage_info}.cleaned")
SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}")
# get varargs one by one
set(ARGI "3")
......@@ -152,52 +152,44 @@ FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
while(ARGI LESS ARGC)
# replace ";" by " " in ARGVi
set(TEST_COMMAND_ARGS "")
# foreach(OPT ${ARGV${ARGI}})
# set(TEST_COMMAND_ARGS "${TEST_COMMAND_ARGS} ${OPT}")
# endforeach()
list(LENGTH FULL_TEST_COMMAND COMMAND_COUNT)
if (COMMAND_COUNT GREATER 0)
set(FULL_TEST_COMMAND "${FULL_TEST_COMMAND}${CMAKE_CURRENT_BINARY_DIR}/${test_command};${ARGV${ARGI}}\;") #${TEST_COMMAND_ARGS}")
set(FULL_TEST_COMMAND "${FULL_TEST_COMMAND}${CMAKE_CURRENT_BINARY_DIR}/${test_command};${ARGV${ARGI}}\;")
else()
set(FULL_TEST_COMMAND "${test_command};${ARGV${ARGI}}\;") #${TEST_COMMAND_ARGS}")
set(FULL_TEST_COMMAND "${test_command};${ARGV${ARGI}}\;")
endif()
# next
math(EXPR ARGI "${ARGI}+1")
endwhile()
# message("================== ${test_command} ↑ ${_testrunner}")
# message("****************** ${FULL_TEST_COMMAND}")
# # find_program(TEST_COMMAND_PATH "${test_command}"
# PATHS ${CMAKE_BINARY_DIR})
# message("!!!!!!!!!!!!!!!!!! ${TEST_COMMAND_PATH} ${CMAKE_CURRENT_BINARY_DIR}")
# add this so that the return value is always 0
math(EXPR TEST_COUNT "${ARGC}-3")
set(FULL_TEST_COMMAND "${FULL_TEST_COMMAND}echo;Testing phase finished. ${TEST_COUNT} test done.")
# Setup target
ADD_CUSTOM_TARGET(${_targetname}
# Setup target
ADD_CUSTOM_TARGET(${_targetname}
# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# Run tests
COMMAND ${FULL_TEST_COMMAND}}
# Run tests
COMMAND ${FULL_TEST_COMMAND}}
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info}
COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned}
COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned}
COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned}
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info}
COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned}
COMMAND ${GENHTML_PATH} --legend -o ${_outputname} ${coverage_cleaned}
COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
......@@ -208,29 +200,29 @@ ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)
IF(NOT PYTHON_EXECUTABLE)
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
ENDIF() # NOT PYTHON_EXECUTABLE
IF(NOT PYTHON_EXECUTABLE)
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
ENDIF() # NOT PYTHON_EXECUTABLE
IF(NOT GCOVR_PATH)
MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
ENDIF() # NOT GCOVR_PATH
IF(NOT GCOVR_PATH)
MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
ENDIF() # NOT GCOVR_PATH
ADD_CUSTOM_TARGET(${_targetname}
ADD_CUSTOM_TARGET(${_targetname}
# Run tests
${_testrunner} ${ARGV3}
# Run tests
${_testrunner} ${ARGV3}
# Running gcovr
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running gcovr to produce Cobertura code coverage report."
)
# Running gcovr
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running gcovr to produce Cobertura code coverage report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Cobertura code coverage report saved in ${_outputname}.xml."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Cobertura code coverage report saved in ${_outputname}.xml."
)
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA
......@@ -949,6 +949,13 @@ macro(camitk_extension)
TEST_SUFFIX "-LEVEL${TESTLEVEL}-"
PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
)
if(CAMITK_COVERAGE)
setup_target_for_coverage(${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}-coverage-${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}-${DATA_FILE}-LEVEL${TESTLEVEL}
${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}
${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}-coverage-${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}-${DATA_FILE}-LEVEL${TESTLEVEL}
"-i;${CAMITK_BUILD_TESTDATA_DIR}/ctestdata/${DATA_FILE};-c;${CAMITK_BUILD_PRIVATE_LIB_DIR}/${TYPE_EXTENSION}s/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.so;-l;${TESTLEVEL}"
)
endif()
endif()
camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL ${TESTLEVEL} DESCRIPTION ${TEST_DESCRIPTION})
MATH(EXPR TESTLEVEL "${TESTLEVEL}-1")# Decrease the test level to proceed less arduous tests
......@@ -996,13 +1003,15 @@ macro(camitk_extension)
TEST_SUFFIX "-LEVEL1-"
PROJECT_NAME ${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}
)
# if(CAMITK_COVERAGE)
# setup_target_for_coverage(${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}-coverage-${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}-${ACTION_TESTDATA_FILE}
# ${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}
# ${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}-coverage-${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}-${ACTION_TESTDATA_FILE}
# "-i;${CAMITK_BUILD_TESTDATA_DIR}/ctestdata/${ACTION_TESTDATA_FILE};-a;lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.so" )
if(CAMITK_COVERAGE)
setup_target_for_coverage(${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}-coverage-${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}-${ACTION_TESTDATA_FILE}
${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}
${${EXTENSION_NAME_CMAKE}_TEST_APPLICATION}-coverage-${${TYPE_EXTENSION_CMAKE}_TARGET_NAME}-${ACTION_TESTDATA_FILE}
"-i;${CAMITK_BUILD_TESTDATA_DIR}/ctestdata/${ACTION_TESTDATA_FILE};-a;lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.so"
)
endif()
camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL 1 DESCRIPTION "Open a file, load the action and apply it on the component.")
endif()
camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL 1 DESCRIPTION "Open a file, load the action and apply it on the component.")
endif()
endforeach()
endif()
......
......@@ -121,11 +121,11 @@ macro(camitk_add_test)
# add properties if needed
if(CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION)
set_tests_properties(${CAMITK_TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION ${CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION})
set_tests_properties(${CAMITK_TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION ${CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION})
else()
if(CAMITK_ADD_TEST_FAIL_REGULAR_EXPRESSION)
set_tests_properties(${CAMITK_TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION ${CAMITK_ADD_TEST_FAIL_REGULAR_EXPRESSION})
endif()
if(CAMITK_ADD_TEST_FAIL_REGULAR_EXPRESSION)
set_tests_properties(${CAMITK_TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION ${CAMITK_ADD_TEST_FAIL_REGULAR_EXPRESSION})
endif()
endif()
endif()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment