Skip to content

Commit

Permalink
Merge topic 'SIMPLEITK-418_FixTestDriverSize'
Browse files Browse the repository at this point in the history
27989bc Break generated filter tests into different drivers.
31b8b6e STYLE: clean up some cmake style
c488f28 Separately add test from generated json and manually written tests
0d54ffa Clear up some unneeded conditionals
3a4dfd8 Correcting dependencies on generated headers for wrapping
40d1878 Added sitk prefix to ImageCompare file name
36c65fb Splitting of common test code into a library and a second test driver
6d16aeb Remove first pass test conditional
9ea56d4 Add sitk prefix to tests
  • Loading branch information
blowekamp authored and kwrobot committed Sep 30, 2013
2 parents 5d63ed4 + 27989bc commit c4c1f0d
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 71 deletions.
1 change: 1 addition & 0 deletions Code/BasicFilters/json/ExtractImageFilter.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"tag" : "more",
"description" : "croping",
"md5hash" : "01bae0803fe74512dbd9d00fc8da4879",
"no_procedure" : 1,
"settings" : [
{
"parameter" : "Size",
Expand Down
115 changes: 52 additions & 63 deletions Testing/Unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@

# remove me
set ( ITK_NO_IO_FACTORY_REGISTER_MANAGER 1 )
include(${ITK_USE_FILE})

set ( SimpleITKUnitTestSourceBase
SimpleITKTestHarness.cxx
sitkImageCompare.cxx
)
add_library ( SimpleITKUnitTestBase STATIC ${SimpleITKUnitTestSourceBase} )
add_dependencies( SimpleITKUnitTestBase BasicFiltersSourceCode )
# Find tests generated in the binary directory
# To add a new file, just add it to this list. Any GoogleTests inside will be automatically
# added to ctest.
set ( TestSource
SimpleITKTestHarness.cxx
set ( SimpleITKUnitTestSource
sitkImageTests.cxx
CommonTests.cxx
RegistrationTests.cxx
sitkCommonTests.cxx
sitkRegistrationTests.cxx
sitkImageIOTests.cxx
TypeListsTests.cxx
sitkTypeListsTests.cxx
sitkBasicFiltersTests.cxx
LabelStatisticsTest.cxx
sitkLabelStatisticsTest.cxx
sitkOperatorTests.cxx
sitkExceptionsTests.cxx
sitkTransformTests.cxx
sitkImportImageTest.cxx
itkHashImageFilterTest.cxx
itkSliceImageFilterTest.cxx
ImportImageTest.cxx
CXXTests.cxx
)

Expand All @@ -46,48 +50,40 @@ else( )
set( PYTHON_EXECUTABLE ${PythonVirtualenvHome}/bin/python )
endif()


add_executable(SimpleITKUnitTestDriver0 SimpleITKUnitTestDriver.cxx ${SimpleITKUnitTestSource})
target_link_libraries ( SimpleITKUnitTestDriver0 gtest SimpleITKUnitTestBase ${SimpleITK_LIBRARIES} )

#
# Glob for necessary template files up front, before the foreach loop over
# the filters:
#
file ( GLOB CXX_TEMPLATE_FILES "*Template*.cxx.in" )

if ( WRAP_LUA )
file ( GLOB LUA_TEMPLATE_FILES "*Template*.lua.in" )
endif()

if ( WRAP_PYTHON )
file ( GLOB PYTHON_TEMPLATE_FILES "*Template*py.in" )
endif()

if ( WRAP_TCL )
file ( GLOB TCL_TEMPLATE_FILES "*Template*.tcl.in" )
endif()

if ( WRAP_R )
file ( GLOB R_TEMPLATE_FILES "*Template*.R.in" )
endif()

if ( WRAP_RUBY )
file ( GLOB RUBY_TEMPLATE_FILES "*Template*rb.in" )
endif()

if ( WRAP_JAVA )
file ( GLOB JAVA_TEMPLATE_FILES "*Template*.java.in" )
endif()

if ( WRAP_CSHARP )
file( GLOB CSHARP_TEMPLATE_FILES "*Template*.cs.in" )
endif()
file ( GLOB LUA_TEMPLATE_FILES "*Template*.lua.in" )
file ( GLOB PYTHON_TEMPLATE_FILES "*Template*py.in" )
file ( GLOB TCL_TEMPLATE_FILES "*Template*.tcl.in" )
file ( GLOB R_TEMPLATE_FILES "*Template*.R.in" )
file ( GLOB RUBY_TEMPLATE_FILES "*Template*rb.in" )
file ( GLOB JAVA_TEMPLATE_FILES "*Template*.java.in" )
file ( GLOB CSHARP_TEMPLATE_FILES "*Template*.cs.in" )


#
# Generate code for the tests in different languages
#
# Break all these source files into a bunch of separate executables
# base on every n files in the list.
set ( _stride 50 )
set ( _exec_i 1 ) # exec 0 is the manual tests
set ( _i 0 )
foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )

if ( NOT _i LESS _stride )
add_executable(SimpleITKUnitTestDriver${_exec_i} SimpleITKUnitTestDriver.cxx ${GENERATED_TEST_SOURCE})
target_link_libraries ( SimpleITKUnitTestDriver${_exec_i} gtest SimpleITKUnitTestBase ${SimpleITK_LIBRARIES} )
math(EXPR _exec_i "${_exec_i}+1")
set ( _i 0 )
endif ()

# Set up some convenience variables
set (filter_json_file ${SimpleITK_SOURCE_DIR}/Code/BasicFilters/json/${FILTERNAME}.json)
set (template_expansion_script ${SimpleITK_SOURCE_DIR}/Utilities/ExpandTemplate.lua)
Expand All @@ -100,7 +96,7 @@ foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )
COMMAND lua ${template_expansion_script} test ${filter_json_file} ${SimpleITK_SOURCE_DIR}/Testing/Unit/sitk ${template_include_dir} TestTemplate.cxx.in "${OUTPUT_TEST_FILENAME}"
DEPENDS ${filter_json_file} ${CXX_TEMPLATE_FILES}
)
set ( GENERATED_TEST_LIST ${GENERATED_TEST_LIST} "BasicFilters.${FILTERNAME}:BasicFilters.${FILTERNAME}_*" )
add_test( NAME BasicFilters.${FILTERNAME} COMMAND SimpleITKUnitTestDriver${_exec_i} --gtest_filter=BasicFilters.${FILTERNAME}:BasicFilters.${FILTERNAME}_* )
set ( GENERATED_TEST_SOURCE ${GENERATED_TEST_SOURCE} ${OUTPUT_TEST_FILENAME})

if ( WRAP_LUA )
Expand All @@ -111,7 +107,7 @@ foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )
COMMAND lua ${template_expansion_script} test ${filter_json_file} ${SimpleITK_SOURCE_DIR}/Testing/Unit/Lua ${template_include_dir} TestTemplate.lua.in "${OUTPUT_TEST_FILENAME}"
DEPENDS ${filter_json_file} ${LUA_TEMPLATE_FILES}
)
set ( GENERATED_TEST_LIST ${GENERATED_TEST_LIST} "Lua.${FILTERNAME}")
add_test( NAME Lua.${FILTERNAME} COMMAND SimpleITKUnitTestDriver${_exec_i} --gtest_filter=Lua.${FILTERNAME} )
set ( WRAPPED_GENERATED_TEST_SOURCE ${WRAPPED_GENERATED_TEST_SOURCE} ${OUTPUT_TEST_FILENAME})
endif()

Expand All @@ -123,7 +119,7 @@ foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )
COMMAND lua ${template_expansion_script} test ${filter_json_file} ${SimpleITK_SOURCE_DIR}/Testing/Unit/Python ${template_include_dir} TestTemplate.py.in "${OUTPUT_TEST_FILENAME}"
DEPENDS ${filter_json_file} ${PYTHON_TEMPLATE_FILES}
)
set ( GENERATED_TEST_LIST ${GENERATED_TEST_LIST} "Python.${FILTERNAME}")
add_test( NAME Python.${FILTERNAME} COMMAND SimpleITKUnitTestDriver${_exec_i} --gtest_filter=Python.${FILTERNAME} )
set ( WRAPPED_GENERATED_TEST_SOURCE ${WRAPPED_GENERATED_TEST_SOURCE} ${OUTPUT_TEST_FILENAME})
endif()

Expand All @@ -135,7 +131,7 @@ foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )
COMMAND lua ${template_expansion_script} test ${filter_json_file} ${SimpleITK_SOURCE_DIR}/Testing/Unit/Tcl ${template_include_dir} TestTemplate.tcl.in "${OUTPUT_TEST_FILENAME}"
DEPENDS ${filter_json_file} ${TCL_TEMPLATE_FILES}
)
set ( GENERATED_TEST_LIST ${GENERATED_TEST_LIST} "Tcl.${FILTERNAME}")
add_test( NAME Tcl.${FILTERNAME} COMMAND SimpleITKUnitTestDriver${_exec_i} --gtest_filter=Tcl.${FILTERNAME} )
set ( WRAPPED_GENERATED_TEST_SOURCE ${WRAPPED_GENERATED_TEST_SOURCE} ${OUTPUT_TEST_FILENAME})
endif()

Expand All @@ -147,7 +143,7 @@ foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )
COMMAND lua ${template_expansion_script} test ${filter_json_file} ${SimpleITK_SOURCE_DIR}/Testing/Unit/R ${template_include_dir} TestTemplate.R.in "${OUTPUT_TEST_FILENAME}"
DEPENDS ${filter_json_file} ${R_TEMPLATE_FILES}
)
set ( GENERATED_TEST_LIST ${GENERATED_TEST_LIST} "R.${FILTERNAME}")
add_test( NAME R.${FILTERNAME} COMMAND SimpleITKUnitTestDriver${_exec_i} --gtest_filter=R.${FILTERNAME} )
set ( WRAPPED_GENERATED_TEST_SOURCE ${WRAPPED_GENERATED_TEST_SOURCE} ${OUTPUT_TEST_FILENAME})
endif()

Expand All @@ -159,7 +155,7 @@ foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )
COMMAND lua ${template_expansion_script} test ${filter_json_file} ${SimpleITK_SOURCE_DIR}/Testing/Unit/Ruby ${template_include_dir} TestTemplate.rb.in "${OUTPUT_TEST_FILENAME}"
DEPENDS ${filter_json_file} ${RUBY_TEMPLATE_FILES}
)
set ( GENERATED_TEST_LIST ${GENERATED_TEST_LIST} "Ruby.${FILTERNAME}")
add_test( NAME Ruby.${FILTERNAME} COMMAND SimpleITKUnitTestDriver${_exec_i} --gtest_filter=Ruby.${FILTERNAME} )
set ( WRAPPED_GENERATED_TEST_SOURCE ${WRAPPED_GENERATED_TEST_SOURCE} ${OUTPUT_TEST_FILENAME})
endif()

Expand All @@ -173,7 +169,7 @@ foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )
COMMAND ${Java_JAVAC_EXECUTABLE} -classpath ${SimpleITK_BINARY_DIR}/Wrapping/${JAR_FILE} ${SimpleITK_BINARY_DIR}/Testing/Unit/JavaTests/org/itk/simple/testing/${FILTERNAME}Test.java
DEPENDS ${filter_json_file} ${JAVA_TEMPLATE_FILES} ${SWIG_MODULE_SimpleITKJava_TARGET_NAME}
)
set ( GENERATED_TEST_LIST ${GENERATED_TEST_LIST} "Java.${FILTERNAME}")
add_test( NAME Java.${FILTERNAME} COMMAND SimpleITKUnitTestDriver${_exec_i} --gtest_filter=Java.${FILTERNAME} )
set ( WRAPPED_GENERATED_TEST_SOURCE ${WRAPPED_GENERATED_TEST_SOURCE} ${OUTPUT_TEST_FILENAME})
endif()

Expand All @@ -195,12 +191,17 @@ foreach ( FILTERNAME ${GENERATED_FILTER_LIST} )
/out:${CSHARP_BINARY_DIRECTORY}/Test${FILTERNAME}.exe ${OUTPUT_TEST_FILENAME_SAFE}
DEPENDS ${filter_json_file} ${CSHARP_TEMPLATE_FILES}
)
set ( GENERATED_TEST_LIST ${GENERATED_TEST_LIST} "CSharp.${FILTERNAME}")
add_test( NAME CSharp.${FILTERNAME} COMMAND SimpleITKUnitTestDriver${_exec_i} --gtest_filter=CSharp.${FILTERNAME} )
set ( WRAPPED_GENERATED_TEST_SOURCE ${WRAPPED_GENERATED_TEST_SOURCE} ${OUTPUT_TEST_FILENAME})
endif()

math(EXPR _i "${_i}+1")

endforeach()

add_executable(SimpleITKUnitTestDriver${_exec_i} SimpleITKUnitTestDriver.cxx ${GENERATED_TEST_SOURCE})
target_link_libraries ( SimpleITKUnitTestDriver${_exec_i} gtest SimpleITKUnitTestBase ${SimpleITK_LIBRARIES} )

# Build Google Test
find_package(Threads)
if (CMAKE_USE_PTHREADS_INIT) # The pthreads library is available.
Expand Down Expand Up @@ -248,29 +249,19 @@ if( WRAP_CSHARP )
add_dependencies(WrappedGeneratedTests SimpleITKCSharpManaged)
endif()

add_executable(SimpleITKUnitTestDriver
SimpleITKUnitTestDriver.cxx ${TestSource} ImageCompare.cxx
${GENERATED_TEST_SOURCE}
)
target_link_libraries ( SimpleITKUnitTestDriver gtest ${SimpleITK_LIBRARIES} )

add_executable(sitkShowTest
sitkShowTest.cxx
)
add_executable(sitkShowTest sitkShowTest.cxx )
target_link_libraries ( sitkShowTest ${SimpleITK_LIBRARIES} )

add_executable( sitkSystemInformationTest
sitkSystemInformationTest.cxx )
target_link_libraries( sitkSystemInformationTest
${SimpleITK_LIBRARIES} )
add_executable( sitkSystemInformationTest sitkSystemInformationTest.cxx )
target_link_libraries( sitkSystemInformationTest ${SimpleITK_LIBRARIES} )
add_test( NAME sitkSystemInformaionTest COMMAND sitkSystemInformationTest ${CMAKE_BINARY_DIR} )


# Add all the tests by parsing the source code
# This macro searches for GoogleTest macros and adds them as test automatically
macro(ADD_GOOGLE_TESTS target)
# Add the generated tests
set ( AllTestsHits ${GENERATED_TEST_LIST} )
set ( AllTestsHits "" )
set ( LongTestsHits "" )

foreach ( source ${ARGN} )
Expand Down Expand Up @@ -304,13 +295,11 @@ macro(ADD_GOOGLE_TESTS target)
foreach(hit ${AllTestsHits})
# Take the first item in gtest list as the name
string( REGEX MATCH "[^:]+" name ${hit} )
#message ( STATUS "Adding test ${name} as ${target} --gtest_filter=${hit}" )
add_test(NAME ${name} COMMAND ${target} --gtest_filter=${hit})
add_test( NAME ${name} COMMAND ${target} --gtest_filter=${hit} )
endforeach()
endmacro()

# Here we add all the tests
add_google_tests(SimpleITKUnitTestDriver ${TestSource})
add_google_tests(SimpleITKUnitTestDriver0 ${SimpleITKUnitTestSource})


#######################################################
Expand Down
2 changes: 1 addition & 1 deletion Testing/Unit/SimpleITKTestHarness.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ class R : public ExternalProgramRunner { };
class Ruby : public ExternalProgramRunner { };
class CSharp : public ExternalProgramRunner { };

#include "ImageCompare.h"
#include "sitkImageCompare.h"

#endif
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <SimpleITK.h>
#include <memory>

#include "ImageCompare.h"
#include "sitkImageCompare.h"

namespace sitk = itk::simple;

Expand Down
File renamed without changes.
7 changes: 2 additions & 5 deletions Testing/Unit/sitkImageFilterTestTemplate.cxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ end)
end)
}

namespace { bool firstPassSoTestFunctional = true; }
$(foreach tests
TEST(BasicFilters,${name}_${tag})
{ // BEGIN FOR EACH TEST
Expand Down Expand Up @@ -153,9 +152,7 @@ $(if inputA_cast then
ASSERT_TRUE ( inputs[i].GetITKBase() != NULL ) << "Could not read " << inputFileNames[i];
}

if ( firstPassSoTestFunctional ) {
firstPassSoTestFunctional = false;
$(if (not no_procedure) or (no_procedure == 1) then
$(if (not no_procedure) or (no_procedure ==0) then
OUT=[=[

// Do we get the same image back, if we use the functional interface?
Expand All @@ -176,7 +173,7 @@ OUT=[=[
hasher.SetHashFunction ( itk::simple::HashImageFilter::MD5 );
EXPECT_EQ ( hasher.Execute ( fromProcedural ), hasher.Execute ( fromFunctional ) ) << "procedural and functional are not the same!";
]=] end)
}


$(if settings then
OUT=[[
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Wrapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if ( WRAP_LUA OR WRAP_PYTHON OR WRAP_JAVA OR WRAP_CSHARP OR WRAP_TCL OR WRAP_R O
# make a manual list of dependencies for the Swig.i files
list( APPEND SWIG_EXTRA_DEPS "${SimpleITK_BINARY_DIR}/Code/BasicFilters/include/SimpleITKBasicFiltersGeneratedHeaders.i"
"${SimpleITK_BINARY_DIR}/Code/BasicFilters/include/SimpleITKBasicFiltersGeneratedHeaders.h"
${SimpleITKBasicFiltersGeneratedHeaders}
${SimpleITKBasicFiltersGeneratedHeader}
)

# check if uint64_t is the same as unsigned long
Expand Down

0 comments on commit c4c1f0d

Please sign in to comment.