Commit daf6e15f authored by Emmanuel Promayon's avatar Emmanuel Promayon

UPDATED now a camitk_extension option + unify names for integration macros

parent 5d61d84a
......@@ -4,6 +4,7 @@ camitk_extension(ACTION_EXTENSION
DESCRIPTION "Use marching cube algorithm to create a surfacic mesh from a volumic image"
ENABLE_AUTO_TEST
TEST_FILES sinus_skin.vtk brain.mha sinus.mhd
ENABLE_INTEGRATION_TEST
)
# Recursively update the shiboken path variable containing the CamiTK SDK tree structure
......
......@@ -28,7 +28,7 @@ include(camitk/manifest/CamiTKWriteManifestData)
# -- CamiTK test macros (see also http://www.org/cmake/help/v2.8.8/cmake.html#section_PropertiesonTests)
include(camitk/test/CamiTKInitTest)
include(camitk/test/CamiTKAddTest)
include(camitk/test/CamiTKAddTestActionStateMachine)
include(camitk/test/CamiTKAddIntegrationTest)
include(camitk/test/CamiTKAdditionalActionTest)
# -- packaging macros
......
......@@ -106,7 +106,7 @@ macro(camitk_extension)
get_directory_name(${CMAKE_CURRENT_SOURCE_DIR} EXTENSION_NAME)
set(options ACTION_EXTENSION COMPONENT_EXTENSION DISABLED NEEDS_XERCESC NEEDS_ITK NEEDS_LIBXML2 NEEDS_XSD NEEDS_OPENCV NEEDS_IGSTK INSTALL_ALL_HEADERS NEEDS_GDCM ENABLE_AUTO_TEST)
set(options ACTION_EXTENSION COMPONENT_EXTENSION DISABLED NEEDS_XERCESC NEEDS_ITK NEEDS_LIBXML2 NEEDS_XSD NEEDS_OPENCV NEEDS_IGSTK INSTALL_ALL_HEADERS NEEDS_GDCM ENABLE_AUTO_TEST ENABLE_INTEGRATION_TEST)
set(oneValueArgs TARGET_NAME CEP_NAME DESCRIPTION AUTO_TEST_LEVEL)
set(multiValueArgs NEEDS_TOOL NEEDS_CEP_LIBRARIES NEEDS_COMPONENT_EXTENSION NEEDS_ACTION_EXTENSION INCLUDE_DIRECTORIES EXTERNAL_LIBRARIES HEADERS_TO_INSTALL DEFINES CXX_FLAGS EXTERNAL_SOURCES EXTRA_TRANSLATE_LANGUAGE TEST_FILES)
cmake_parse_arguments(${EXTENSION_NAME_CMAKE} "${options}" "${oneValueArgs}"
......@@ -937,6 +937,17 @@ macro(camitk_extension)
endif()
endif() # NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_AUTO_TEST)
#########################################################################
# #
# CTEST - Integration test #
# #
#########################################################################
if (NOT PACKAGING_NSIS AND BUILD_TESTING AND ${EXTENSION_NAME_CMAKE}_ENABLE_INTEGRATION_TEST)
# add a specific test to run the action, save the output and compare it to expected
camitk_add_integration_test()
endif()
endif() # endif(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE})
endmacro()
......
#!
#! @ingroup group_sdk_cmake_camitk_test
#!
#! camitk_add_test_actionstatemachine is a macro to add a new test to the CTest infrastructure
#! camitk_add_integration_test is a macro to add a new test to the CTest infrastructure
#! It encapsulates CMake add_test and use the action state machine to run a set of actions.
#! The set of actions are described in a CamiTK SCXML document. This macro is used to
#! add integration tests.
#!
#! Details on the runned test can be found in ${CMAKE_BINARY_DIR}/Testing/Temporary/target#
#! where target is the executable name (see camitk_init_test() macro), and # is the test order number.
#! Details on the runned test can be found in directory
#! ${CMAKE_BINARY_DIR}/Testing/Temporary/${TYPE_EXTENSION}-${EXTENSION_NAME}-integration-test
#!
#! It is typically usued inside the camitk_extension(..) macro and expects the following variable
#! to be set beforehand:
#! - TYPE_EXTENSION action or component)
#! - EXTENSION_NAME name of the current action or component
#!
#! It does add a test if and only if:
#! - ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata exists
#! - ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata contains an file called "asm-input.scxml"
#! - ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata contains at least one file name "output-*.*"
#!
#! Usage:
#! \code
#! camitk_add_test_actionstatemachine(NAME "testName"
#! CAMITK_SCXML "file.xml"
#! EXPECTED_OUTPUT_FILES file1 file2 file3...
#! )
#! camitk_add_integration_test()
#! \endcode
#!
#! It creates a target name
#!
#! \param NAME Name of the test, use "ctest -V -R testName" to run the test individually
#! \param CAMITK_SCXML The input xml file
#! \param EXPECTED_OUTPUT_FILES List of files that have to be compared with the asm output
#!
macro(camitk_add_test_actionstatemachine)
set(options "")
set(oneValueArgs NAME CAMITK_SCXML)
set(multiValueArgs EXPECTED_OUTPUT_FILES)
cmake_parse_arguments(CAMITK_ADD_TEST_ASM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
macro(camitk_add_integration_test)
# determine cmake macro path
#-- set the name of the current test and other parameters
if (NOT EXISTS ${SDK_TOP_LEVEL_SOURCE_DIR})
# this macro is called outside the sdk
set(CAMITK_CMAKE_MACRO_PATH ${CAMITK_CMAKE_DIR}/modules/macros/camitk/test)
if(NOT IS_DIRECTORY ${CAMITK_CMAKE_MACRO_PATH})
#-- check integration data availability
set(CAMITK_INTEGRATION_TESTDATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata)
# inside communityedition but not in sdk (modeling or imaging)
set(CAMITK_CMAKE_MACRO_PATH ${CMAKE_SOURCE_DIR}/sdk/cmake/modules/macros/camitk/test)
endif()
else()
# directly use the macro source dir
set(CAMITK_CMAKE_MACRO_PATH ${SDK_TOP_LEVEL_SOURCE_DIR}/cmake/modules/macros/camitk/test)
endif()
message(FATAL_ERROR "Can not add test ${CAMITK_INTEGRATION_TEST_NAME}: \"integration-testdata\" subdirectory not found." )
endif()
set(CAMITK_INTEGRATION_SCXML asm-input.scxml)
if (NOT EXISTS ${CAMITK_INTEGRATION_TESTDATA_DIR})
message(FATAL_ERROR "Can not add test ${CAMITK_INTEGRATION_TEST_NAME}: CamiTK SCXML document not found." )
endif()
# look for all the files that called "output-*"
file(GLOB CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES RELATIVE ${CAMITK_INTEGRATION_TESTDATA_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata/output-*.*)
list(LENGTH CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES NUMBER_OF_EXPECTED_OUTPUT_FILES)
if (NUMBER_OF_EXPECTED_OUTPUT_FILES EQUAL 0)
message(FATAL_ERROR "Can not add test ${CAMITK_INTEGRATION_TEST_NAME}: no expected output file found." )
endif()
#-- clean/create test output directory
set(CAMITK_TEST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Testing/Temporary/${CAMITK_ADD_TEST_ASM_NAME}")
set(CAMITK_TEST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Testing/Temporary/${CAMITK_INTEGRATION_TEST_NAME}")
file(REMOVE_RECURSE ${CAMITK_TEST_OUTPUT_DIR})
file(MAKE_DIRECTORY ${CAMITK_TEST_OUTPUT_DIR})
#-- replace the input file names
# Read the file in a variable
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata/${CAMITK_ADD_TEST_ASM_CAMITK_SCXML} ASM_INPUT_FILE_AS_STRING)
file(READ ${CAMITK_INTEGRATION_TESTDATA_DIR}/${CAMITK_INTEGRATION_SCXML} ASM_INPUT_FILE_AS_STRING)
# get all the lines that have a non-empty "File Name" parameter
string(REGEX MATCHALL "<camitk:parameter name=\"File Name\" value=\".*\" type=\"QString\"/>" FILENAME_LINES "${ASM_INPUT_FILE_AS_STRING}")
# intialize ASM_INPUT_FILE_AS_STRING_OK
......@@ -62,7 +69,7 @@ macro(camitk_add_test_actionstatemachine)
string(REGEX REPLACE ".*value=\"(.*)\" .*" "\\1" INPUT_FILE_NAME "${CURRENT_LINE}")
# copy the corresponding file to the temp directory
# message("===== Input File = ${INPUT_FILE_NAME}")
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata/${INPUT_FILE_NAME}
file(COPY ${CAMITK_INTEGRATION_TESTDATA_DIR}/${INPUT_FILE_NAME}
DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
endforeach()
......@@ -70,16 +77,16 @@ macro(camitk_add_test_actionstatemachine)
# Beware/Note: you need to add the quote around the ASM_INPUT_FILE_AS_STRING_OK value otherwise ";" will be
# interprated as list/argument separator and will be transformed to " " (for XML files that means that each
# substitution will get damaged: &lt; -> &lt ... not good...)
file(WRITE ${CAMITK_TEST_OUTPUT_DIR}/${CAMITK_ADD_TEST_ASM_CAMITK_SCXML} "${ASM_INPUT_FILE_AS_STRING_OK}")
file(WRITE ${CAMITK_TEST_OUTPUT_DIR}/${CAMITK_INTEGRATION_SCXML} "${ASM_INPUT_FILE_AS_STRING_OK}")
# And copy the expected output files
foreach(EXPECTED_OUTPUT_FILE ${CAMITK_ADD_TEST_ASM_EXPECTED_OUTPUT_FILES})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata/${EXPECTED_OUTPUT_FILE}
foreach(EXPECTED_OUTPUT_FILE ${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES})
file(COPY ${CAMITK_INTEGRATION_TESTDATA_DIR}/${EXPECTED_OUTPUT_FILE}
DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
endforeach()
#-- run actionstatemachine
set(CAMITK_TEST_EXECUTABLE_ARG "-f ${CAMITK_TEST_OUTPUT_DIR}/${CAMITK_ADD_TEST_ASM_CAMITK_SCXML} -o ${CAMITK_TEST_OUTPUT_DIR} -a")
set(CAMITK_TEST_EXECUTABLE_ARG "-f ${CAMITK_TEST_OUTPUT_DIR}/${CAMITK_INTEGRATION_SCXML} -o ${CAMITK_TEST_OUTPUT_DIR} -a")
# determine path to camitk-actionstatemachine executable
if(NOT CAMITK_COMMUNITY_EDITION_BUILD)
......@@ -117,9 +124,9 @@ macro(camitk_add_test_actionstatemachine)
COMMAND ${CMAKE_COMMAND}
-DCAMITK_TEST_COMMAND=${CAMITK_ASM_EXE}
-DCAMITK_TEST_COMMAND_ARG=${CAMITK_TEST_EXECUTABLE_ARG}
-DCAMITK_TEST_EXPECTED_FILES=${CAMITK_ADD_TEST_ASM_EXPECTED_OUTPUT_FILES}
-DCAMITK_TEST_EXPECTED_FILES=${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES}
-DCAMITK_TEST_OUTPUT_DIR=${CAMITK_TEST_OUTPUT_DIR}
-DCAMITK_TEST_NAME=${CAMITK_ADD_TEST_ASM_NAME}
-DCAMITK_TEST_NAME=${CAMITK_INTEGRATION_TEST_NAME}
-P ${CAMITK_CMAKE_MACRO_PATH}/CamiTKTestActionStateMachine.cmake
)
......
#!
#! @ingroup group_sdk_cmake_camitk_test
#!
#! This CMake file run the action state machine and compare the output files to the expected files
#! The intended use is to execute this script from the camitk_add_test_actionstatemachine
#! This CMake script run the action state machine and compare the output files to the expected files
#! The intended use is to run this script from the camitk_add_test_actionstatemachine
#!
#! Usage:
#! \code
......@@ -108,7 +108,7 @@ file(WRITE ${CAMITK_TEST_EXPECTED_FILE_RESULT_FILE} ${CAMITK_TEST_EXPECTED_FILE_
#-- check result
if( CAMITK_TEST_EXPECTED_FILE_RESULT )
message("[FAIL]")
message(FATAL_ERROR "${CAMITK_TEST_NAME}: (one or more) output file do(es) not match the corresponding expected file\nSee ${CAMITK_TEST_EXPECTED_FILE_OUTPUT_FILE} for more information" )
message(FATAL_ERROR "${CAMITK_TEST_NAME}: (one or more) output file do(es) not match the corresponding expected file.\n${CAMITK_TEST_EXPECTED_FILE_OUTPUT}" )
else()
message("[OK]")
endif()
Markdown is supported
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