Skip to content

Commit

Permalink
Added ExternalData-support for test data files.
Browse files Browse the repository at this point in the history
  • Loading branch information
bilke authored and endJunction committed Aug 13, 2014
1 parent 83beb8b commit 4e47097
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
build*/
*.sw[op]
tags
.ExternalData_*
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,18 @@ IF( OGS_BUILD_CLI )
ADD_SUBDIRECTORY( OGS )
ENDIF() # OGS_BUILD_CLI
IF( OGS_BUILD_TESTS AND NOT IS_SUBPROJECT )
ADD_SUBDIRECTORY( Tests )
ADD_SUBDIRECTORY( SimpleTests/MatrixTests )
ADD_SUBDIRECTORY( SimpleTests/MeshTests )
IF(CMAKE_VERSION VERSION_LESS 2.8.11)
MESSAGE(FATAL_ERROR "CMAKE 2.8.11 or higher is required to build the tests!")
ENDIF()
ADD_SUBDIRECTORY( Tests EXCLUDE_FROM_ALL )
ADD_SUBDIRECTORY( SimpleTests/MatrixTests EXCLUDE_FROM_ALL )
ADD_SUBDIRECTORY( SimpleTests/MeshTests EXCLUDE_FROM_ALL )
IF(NOT MSVC AND BLAS_FOUND AND LAPACK_FOUND)
ADD_SUBDIRECTORY( SimpleTests/SolverTests )
ADD_SUBDIRECTORY( SimpleTests/SolverTests EXCLUDE_FROM_ALL )
ENDIF()
# Create a target 'data', which downloads all referenced data sets into the build tree
# This has to be defined after all tests are defined
ExternalData_Add_Target(data)
ENDIF() # OGS_BUILD_TESTS
IF(OGS_BUILD_UTILS AND NOT IS_SUBPROJECT)
ADD_SUBDIRECTORY( Utils/SimpleMeshCreation )
Expand Down
4 changes: 3 additions & 1 deletion scripts/cmake/test/AddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ FUNCTION (AddTest executable case_path case_name wrapper)

## -----------

ADD_TEST(NAME "${executable}-${case_path}-${wrapper}"
ExternalData_Add_Test(data
NAME "${executable}-${case_path}-${wrapper}"
COMMAND ${CMAKE_COMMAND}
-Dexecutable=$<TARGET_FILE:${executable}>
-Dcase_path=${case_path}
Expand All @@ -31,6 +32,7 @@ FUNCTION (AddTest executable case_path case_name wrapper)
-DWRAPPER_COMMAND=${WRAPPER_COMMAND}
-DCMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}
-P ${PROJECT_SOURCE_DIR}/scripts/cmake/test/AddTestWrapper.cmake
DATA{${case_path}/${case_name}.cnd, ${case_path}/${case_name}.gml, ${case_path}/${case_name}.vtu}
)

IF(NOT tester)
Expand Down
32 changes: 32 additions & 0 deletions scripts/cmake/test/Data.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
INCLUDE(ExternalData)

SET(ExternalData_OBJECT_STORES "${ExternalData_OBJECT_STORES_DEFAULT}" CACHE STRING
"Semicolon-separated list of local directories holding test data files in the layout %(algo)/%(hash).")
MARK_AS_ADVANCED(ExternalData_OBJECT_STORES)
IF(NOT ExternalData_OBJECT_STORES)
SET(ExternalData_OBJECT_STORES "${CMAKE_SOURCE_DIR}/../ogs6-data")
FILE(MAKE_DIRECTORY "${ExternalData_OBJECT_STORES}")
ENDIF()

SET(ExternalData_SOURCE_ROOT ${CMAKE_SOURCE_DIR}/Tests/Data)
SET(ExternalData_BINARY_ROOT ${CMAKE_BINARY_DIR}/Tests/Data)
SET(ExternalData_LINK_CONTENT MD5)

SET(ExternalData_URL_TEMPLATES "http://www.opengeosys.org/images/dev/%(algo)/%(hash)")

ADD_CUSTOM_TARGET(
move-data
COMMAND ${CMAKE_COMMAND}
-DExternalData_SOURCE_ROOT=${ExternalData_SOURCE_ROOT}
-DExternalData_LINK_CONTENT=${ExternalData_LINK_CONTENT}
-DExternalData_OBJECT_STORES=${ExternalData_OBJECT_STORES}
-P ${PROJECT_SOURCE_DIR}/scripts/cmake/test/MoveDataToStore.cmake
VERBATIM
)

ExternalData_Add_Test(
data # data target specified above
NAME External-Data-Test
COMMAND ls -ll ${ExternalData_SOURCE_ROOT}/Elliptic/2d-quads-x1000-y1000/
DATA{${ExternalData_SOURCE_ROOT}/Elliptic/2d-quads-x1000-y1000/,REGEX:.*}
)
7 changes: 7 additions & 0 deletions scripts/cmake/test/MoveDataToStore.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Get all files matching .ExternalData_<algo>_<hash>
FILE(GLOB_RECURSE FILES "" ${ExternalData_SOURCE_ROOT}/.ExternalData_${ExternalData_LINK_CONTENT}_*)
FOREACH(HASH_FILE ${FILES})
STRING(REGEX MATCH [^_]+$ HASH ${HASH_FILE})
MESSAGE("Copying ${HASH_FILE} to ${ExternalData_OBJECT_STORES}/${HASH}")
FILE(RENAME ${HASH_FILE} ${ExternalData_OBJECT_STORES}/${ExternalData_LINK_CONTENT}/${HASH})
ENDFOREACH()

0 comments on commit 4e47097

Please sign in to comment.