From cf3476fe57ed99a1475ae9bb901e1f634a85a1ae Mon Sep 17 00:00:00 2001 From: Kasper Marstal <kaspermarstal@gmail.com> Date: Thu, 13 Aug 2015 14:55:49 +0200 Subject: [PATCH] ENH: ELASTIX-1 Add unit test XML report and test harness for handling configuring test data at test compile time --- Testing/CMakeLists.txt | 82 ++++++++++++++++----------- Testing/Unit/CMakeLists.txt | 22 +++---- Testing/Unit/elxExampleUnitTest.cxx | 4 +- Testing/Unit/elxTestHarness.h | 6 -- Testing/Unit/elxTestHarness.h.in | 7 +++ Testing/Unit/elxTestHarnessPaths.h.in | 7 --- 6 files changed, 68 insertions(+), 60 deletions(-) delete mode 100644 Testing/Unit/elxTestHarness.h create mode 100644 Testing/Unit/elxTestHarness.h.in delete mode 100644 Testing/Unit/elxTestHarnessPaths.h.in diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 4b259cbb..ea6d3697 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -1,4 +1,35 @@ -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- +# Download test data + +# ExternalData module requires CMake version 2.8.11 +if( CMAKE_VERSION VERSION_LESS 2.8.11 ) + message( FATAL_ERROR "Building tests require CMake 2.8.11 or newer." ) +endif() + +include( ExternalData ) + +list( APPEND ExternalData_URL_TEMPLATES + "http://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)" + "https://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)" +) + +# Scan the Data directory for content links on the form "[filename].[ext].md5". +# The content links contains md5 hashes that are checked for consistensy +# against files downloaded from servers in ExternalData_URL_TEMPLATES. These +# files are placed in a corresponding location in the build directory. +file( GLOB_RECURSE ElastixDataContentLinks "*.md5" ) +foreach(ElastixDataContentLink ${ElastixDataContentLinks}) + string( REGEX REPLACE "\\.md5$" "" ElastixDataContentLink ${ElastixDataContentLink} ) + ExternalData_Expand_Arguments( ElastixData + ElastixDataFilenames + DATA{${ElastixDataContentLink}} + ) +endforeach() + +# Test data is downloaded when this target is built +ExternalData_Add_Target( ElastixData ) + +# --------------------------------------------------------------------- # Setup GoogleTest find_package( Git ) @@ -18,7 +49,7 @@ if( NOT EXISTS ${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git ) endif() if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" ) - include( ${CMAKE_SOURCE_DIR}/CMake/elxGoogleTestWinConfig.cmake ) + include( elxWinConfigGoogleTest.cmake ) endif() add_subdirectory( GoogleTest ) @@ -31,41 +62,24 @@ set( TEST_LIBRARIES gtest_main ) -#--------------------------------------------------------------------- -# Download unit test and benchmark data - -# ExternalData module was introduced in CMake version 2.8.11 -cmake_minimum_required( VERSION 2.8.11 ) - -include( ExternalData ) - -list( APPEND ExternalData_URL_TEMPLATES - "http://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)" - "https://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)" -) - -# Scan the Data directory for content links on the form "[filename].[ext].md5". -# The content links contains md5 hashes that are checked for consistensy -# against corresponding files downloaded from servers in -# ExternalData_URL_TEMPLATES. These files are placed in a corresponding -# location in the build directory. -file( GLOB_RECURSE ElastixDataContentLinks "*.md5" ) -foreach(ElastixDataContentLink ${ElastixDataContentLinks}) - string( REGEX REPLACE "\\.md5$" "" ElastixDataContentLink ${ElastixDataContentLink} ) - ExternalData_Expand_Arguments( ElastixData - ElastixDataFilenames - DATA{${ElastixDataContentLink}} - ) -endforeach() - -# Test data is downloaded when this target is built -ExternalData_Add_Target( ElastixData ) +# --------------------------------------------------------------------- +# Build test suite -#--------------------------------------------------------------------- -# Build tests +# Unit tests add_subdirectory( Unit ) -# Build benchmarks +# Benchmarks +option( ELASTIX_BUILD_BENCHMARKING "Enable building benchmarks." OFF ) + if( ${ELASTIX_BUILD_BENCHMARKING} ) add_subdirectory( Benchmark ) endif() + +# --------------------------------------------------------------------- +# Configure dashboard +mark_as_advanced( ELASTIX_BUILD_DASHBOARD ) +option( ELASTIX_BUILD_DASHBOARD "Enable elastix dashboard." OFF ) + +if( ${ELASTIX_BUILD_DASHBOARD} ) + add_subdirectory( Dashboard ) +endif() diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index 82ce81f6..0e92b5a3 100644 --- a/Testing/Unit/CMakeLists.txt +++ b/Testing/Unit/CMakeLists.txt @@ -1,32 +1,32 @@ #--------------------------------------------------------------------- # To add a test to the build system, append it to the list below. -# Any GoogleTests in these files are automatically added to CTest. +# Any GoogleTests in these files are automatically added to CTest and +# the Kibana dashboard. set( ElastixUnitTestFilenames elxExampleUnitTest.cxx ) #--------------------------------------------------------------------- - -# Set test harness data directories -set( ELASTIX_TEST_DATA_INPUT_DIR ${CMAKE_CURRENT_DIR}/Data/Input ) -set( ELASTIX_TEST_DATA_BASELINE_DIR ${CMAKE_CURRENT_DIR}/Data/Baseline ) +# Set data directories +set( ELASTIX_UNITTEST_INPUT_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/Data/Input ) +set( ELASTIX_UNITTEST_BASELINE_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/Data/Baseline ) configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/elxTestHarnessPaths.h.in - ${CMAKE_CURRENT_BINARY_DIR}/elxTestHarnessPaths.h + ${CMAKE_CURRENT_SOURCE_DIR}/elxTestHarness.h.in + ${CMAKE_CURRENT_BINARY_DIR}/elxTestHarness.h ESCAPE_QUOTES ) -# Build tests executables +# Build tests foreach( ElastixUnitTestFilename ${ElastixUnitTestFilenames} ) + # Build tests executables string( REPLACE ".cxx" "" ElastixUnitTest ${ElastixUnitTestFilename} ) add_executable( "${ElastixUnitTest}" ${ElastixUnitTestFilename} ) target_link_libraries( "${ElastixUnitTest}" ${ELASTIX_LIBRARIES} ${ITK_LIBRARIES} ${TEST_LIBRARIES} ) - ExternalData_Add_Test( ElastixUnitTestData + ExternalData_Add_Test( ElastixData NAME ${ElastixUnitTest} - COMMAND "${ElastixUnitTest}" -gtest_output + COMMAND ${ElastixUnitTest} "--gtest_output=xml:${CMAKE_BINARY_DIR}/Testing/Unit/${ElastixUnitTest}.xml" ) endforeach() - diff --git a/Testing/Unit/elxExampleUnitTest.cxx b/Testing/Unit/elxExampleUnitTest.cxx index 68326895..725fa981 100644 --- a/Testing/Unit/elxExampleUnitTest.cxx +++ b/Testing/Unit/elxExampleUnitTest.cxx @@ -26,7 +26,7 @@ TEST( GoogleTest, Example1 ) TEST( GoogleTest, Example2 ) { // Record random number between 10 and 19 - int MetricValue = rand() % 20 + 10; + int MetricValue = rand() % 10 + 10; RecordProperty("MetricValue", MetricValue); ASSERT_TRUE( true ); } @@ -34,7 +34,7 @@ TEST( GoogleTest, Example2 ) TEST( GoogleTest, Example3 ) { // Record random number between 20 and 29 - int MetricValue = rand() % 30 + 20; + int MetricValue = rand() % 10 + 20; RecordProperty("MetricValue", MetricValue); ASSERT_TRUE( true ); } \ No newline at end of file diff --git a/Testing/Unit/elxTestHarness.h b/Testing/Unit/elxTestHarness.h deleted file mode 100644 index 2817180f..00000000 --- a/Testing/Unit/elxTestHarness.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __ElastixTestHarness_h -#define __ElastixTestHarness_h - -#include "elxTestHarnessPaths" - -#endif // __ElastixTestHarness_h \ No newline at end of file diff --git a/Testing/Unit/elxTestHarness.h.in b/Testing/Unit/elxTestHarness.h.in new file mode 100644 index 00000000..8bdb97a7 --- /dev/null +++ b/Testing/Unit/elxTestHarness.h.in @@ -0,0 +1,7 @@ +#ifndef __ElastixTestHarness_h +#define __ElastixTestHarness_h + +#define ELASTIX_UNITTEST_INPUT_DATA_DIR "@ELASTIX_UNITTEST_INPUT_DATA_DIR@" +#define ELASTIX_INITTEST_BASELINE_DATA_DIR "@ELASTIX_UNITTEST_BASELINE_DATA_DIR@" + +#endif // __ElastixTestHarness_h \ No newline at end of file diff --git a/Testing/Unit/elxTestHarnessPaths.h.in b/Testing/Unit/elxTestHarnessPaths.h.in deleted file mode 100644 index 06b4750a..00000000 --- a/Testing/Unit/elxTestHarnessPaths.h.in +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __ElastixTestHarness_h -#define __ElastixTestHarness_h - -#define ELASTIX_TEST_DATA_INPUT_DIR "@ELASTIX_TEST_DATA_INPUT_DIR@" -#define ELASTIX_TEST_DATA_BASELINE_DIR "@ELASTIX_TEST_DATA_BASELINE_DIR@" - -#endif // __ElastixTestHarness_h \ No newline at end of file -- GitLab