mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 01:49:02 +00:00
Move VTK-m CMake testing wrappers to the testing folder
The VTK-m testing infrastructure isn't public facing so it doesn't need to be installed or clutter the main VTKmWrappers file. At the same time I have refactored the code to make it clearer to understand, and remove unused options.
This commit is contained in:
parent
0b7dd7c38e
commit
ea50e82aac
@ -160,7 +160,7 @@ endfunction()
|
||||
#
|
||||
# MODIFY_CUDA_FLAGS: If enabled will add the required -arch=<ver> flags
|
||||
# that VTK-m was compiled with. This functionality is also provided by the
|
||||
# the standalone `vtkm_get_cuda_flags` function. Default is OFF.
|
||||
# the standalone `vtkm_get_cuda_flags` function.
|
||||
#
|
||||
# DEVICE_SOURCES: The collection of source files that are used by `target` that
|
||||
# need to be marked as going to a special compiler for certain device adapters
|
||||
@ -334,210 +334,3 @@ function(vtkm_library)
|
||||
)
|
||||
|
||||
endfunction(vtkm_library)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Declare unit tests, which should be in the same directory as a kit
|
||||
# (package, module, whatever you call it). Usage:
|
||||
#
|
||||
# vtkm_unit_tests(
|
||||
# NAME
|
||||
# SOURCES <source_list>
|
||||
# BACKEND <type>
|
||||
# LIBRARIES <dependent_library_list>
|
||||
# DEFINES <target_compile_definitions>
|
||||
# TEST_ARGS <argument_list>
|
||||
# MPI
|
||||
# ALL_BACKENDS
|
||||
# <options>
|
||||
# )
|
||||
#
|
||||
# [BACKEND]: mark all source files as being compiled with the proper defines
|
||||
# to make this backend the default backend
|
||||
# If the backend is specified as CUDA it will also imply all
|
||||
# sources should be treated as CUDA sources
|
||||
# The backend name will also be added to the executable name
|
||||
# so you can test multiple backends easily
|
||||
#
|
||||
# [LIBRARIES] : extra libraries that this set of tests need to link too
|
||||
#
|
||||
# [DEFINES] : extra defines that need to be set for all unit test sources
|
||||
#
|
||||
# [TEST_ARGS] : arguments that should be passed on the command line to the
|
||||
# test executable
|
||||
#
|
||||
# [MPI] : when specified, the tests should be run in parallel if
|
||||
# MPI is enabled.
|
||||
# [ALL_BACKENDS] : when specified, the tests would test against all enabled
|
||||
# backends. BACKEND argument would be ignored.
|
||||
#
|
||||
function(vtkm_unit_tests)
|
||||
if (NOT VTKm_ENABLE_TESTING)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(options)
|
||||
set(global_options ${options} MPI ALL_BACKENDS)
|
||||
set(oneValueArgs BACKEND NAME)
|
||||
set(multiValueArgs SOURCES LIBRARIES DEFINES TEST_ARGS)
|
||||
cmake_parse_arguments(VTKm_UT
|
||||
"${global_options}" "${oneValueArgs}" "${multiValueArgs}"
|
||||
${ARGN}
|
||||
)
|
||||
vtkm_parse_test_options(VTKm_UT_SOURCES "${options}" ${VTKm_UT_SOURCES})
|
||||
|
||||
set(test_prog)
|
||||
set(backend ${VTKm_UT_BACKEND})
|
||||
|
||||
set(enable_all_backends ${VTKm_UT_ALL_BACKENDS})
|
||||
set(all_backends Serial)
|
||||
if (VTKm_ENABLE_CUDA)
|
||||
list(APPEND all_backends Cuda)
|
||||
endif()
|
||||
if (VTKm_ENABLE_TBB)
|
||||
list(APPEND all_backends TBB)
|
||||
endif()
|
||||
if (VTKm_ENABLE_OPENMP)
|
||||
list(APPEND all_backends OpenMP)
|
||||
endif()
|
||||
|
||||
if(VTKm_UT_NAME)
|
||||
set(test_prog "${VTKm_UT_NAME}")
|
||||
else()
|
||||
vtkm_get_kit_name(kit)
|
||||
set(test_prog "UnitTests_${kit}")
|
||||
endif()
|
||||
|
||||
if(backend)
|
||||
set(test_prog "${test_prog}_${backend}")
|
||||
set(all_backends ${backend})
|
||||
elseif(NOT enable_all_backends)
|
||||
set (all_backends "NO_BACKEND")
|
||||
endif()
|
||||
|
||||
if(VTKm_UT_MPI)
|
||||
# for MPI tests, suffix test name and add MPI_Init/MPI_Finalize calls.
|
||||
set(test_prog "${test_prog}_mpi")
|
||||
set(extraArgs EXTRA_INCLUDE "vtkm/cont/testing/Testing.h"
|
||||
FUNCTION "vtkm::cont::testing::Environment env")
|
||||
else()
|
||||
set(extraArgs)
|
||||
endif()
|
||||
|
||||
#the creation of the test source list needs to occur before the labeling as
|
||||
#cuda. This is so that we get the correctly named entry points generated
|
||||
create_test_sourcelist(test_sources ${test_prog}.cxx ${VTKm_UT_SOURCES} ${extraArgs})
|
||||
#if all backends are enabled, we can use cuda compiler to handle all possible backends.
|
||||
if(TARGET vtkm::cuda AND (backend STREQUAL "Cuda" OR enable_all_backends))
|
||||
set_source_files_properties(${VTKm_UT_SOURCES} PROPERTIES LANGUAGE "CUDA")
|
||||
endif()
|
||||
|
||||
add_executable(${test_prog} ${test_prog}.cxx ${VTKm_UT_SOURCES})
|
||||
set_property(TARGET ${test_prog} PROPERTY CUDA_SEPARABLE_COMPILATION ON)
|
||||
|
||||
set_property(TARGET ${test_prog} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
|
||||
set_property(TARGET ${test_prog} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
|
||||
set_property(TARGET ${test_prog} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH})
|
||||
|
||||
if(NOT VTKm_USE_DEFAULT_SYMBOL_VISIBILITY)
|
||||
set_property(TARGET ${test_prog} PROPERTY CUDA_VISIBILITY_PRESET "hidden")
|
||||
set_property(TARGET ${test_prog} PROPERTY CXX_VISIBILITY_PRESET "hidden")
|
||||
endif()
|
||||
|
||||
|
||||
#Starting in CMake 3.13, cmake will properly drop duplicate libraries
|
||||
#from the link line so this workaround can be dropped
|
||||
if (CMAKE_VERSION VERSION_LESS 3.13 AND "vtkm_rendering" IN_LIST VTKm_UT_LIBRARIES)
|
||||
list(REMOVE_ITEM VTKm_UT_LIBRARIES "vtkm_cont")
|
||||
target_link_libraries(${test_prog} PRIVATE ${VTKm_UT_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(${test_prog} PRIVATE vtkm_cont ${VTKm_UT_LIBRARIES})
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${test_prog} PRIVATE ${VTKm_UT_DEFINES})
|
||||
|
||||
foreach(current_backend ${all_backends})
|
||||
set (device_command_line_argument --device=${current_backend})
|
||||
if (current_backend STREQUAL "NO_BACKEND")
|
||||
set (current_backend "")
|
||||
set(device_command_line_argument "")
|
||||
endif()
|
||||
string(TOUPPER "${current_backend}" upper_backend)
|
||||
foreach (test ${VTKm_UT_SOURCES})
|
||||
get_filename_component(tname ${test} NAME_WE)
|
||||
if(VTKm_UT_MPI AND VTKm_ENABLE_MPI)
|
||||
add_test(NAME ${tname}${upper_backend}
|
||||
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS}
|
||||
$<TARGET_FILE:${test_prog}> ${tname} ${device_command_line_argument} ${VTKm_UT_TEST_ARGS}
|
||||
${MPIEXEC_POSTFLAGS}
|
||||
)
|
||||
else()
|
||||
add_test(NAME ${tname}${upper_backend}
|
||||
COMMAND ${test_prog} ${tname} ${device_command_line_argument} ${VTKm_UT_TEST_ARGS}
|
||||
)
|
||||
endif()
|
||||
|
||||
#determine the timeout for all the tests based on the backend. CUDA tests
|
||||
#generally require more time because of kernel generation.
|
||||
if (current_backend STREQUAL "Cuda")
|
||||
set(timeout 1500)
|
||||
else()
|
||||
set(timeout 180)
|
||||
endif()
|
||||
if(current_backend STREQUAL "OpenMP")
|
||||
#We need to have all OpenMP tests run serially as they
|
||||
#will uses all the system cores, and we will cause a N*N thread
|
||||
#explosion which causes the tests to run slower than when run
|
||||
#serially
|
||||
set(run_serial True)
|
||||
else()
|
||||
set(run_serial False)
|
||||
endif()
|
||||
|
||||
set_tests_properties("${tname}${upper_backend}" PROPERTIES
|
||||
TIMEOUT ${timeout}
|
||||
RUN_SERIAL ${run_serial}
|
||||
)
|
||||
|
||||
set_tests_properties("${tname}${upper_backend}" PROPERTIES
|
||||
FAIL_REGULAR_EXPRESSION "runtime error"
|
||||
)
|
||||
|
||||
endforeach (test)
|
||||
endforeach(current_backend)
|
||||
|
||||
endfunction(vtkm_unit_tests)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# vtkm_parse_test_options(varname options)
|
||||
# INTERNAL: Parse options specified for individual tests.
|
||||
#
|
||||
# Parses the arguments to separate out options specified after the test name
|
||||
# separated by a comma e.g.
|
||||
#
|
||||
# TestName,Option1,Option2
|
||||
#
|
||||
# For every option in options, this will set _TestName_Option1,
|
||||
# _TestName_Option2, etc in the parent scope.
|
||||
#
|
||||
function(vtkm_parse_test_options varname options)
|
||||
set(names)
|
||||
foreach(arg IN LISTS ARGN)
|
||||
set(test_name ${arg})
|
||||
set(test_options)
|
||||
if(test_name AND "x${test_name}" MATCHES "^x([^,]*),(.*)$")
|
||||
set(test_name "${CMAKE_MATCH_1}")
|
||||
string(REPLACE "," ";" test_options "${CMAKE_MATCH_2}")
|
||||
endif()
|
||||
foreach(opt IN LISTS test_options)
|
||||
list(FIND options "${opt}" index)
|
||||
if(index EQUAL -1)
|
||||
message(WARNING "Unknown option '${opt}' specified for test '${test_name}'")
|
||||
else()
|
||||
set(_${test_name}_${opt} TRUE PARENT_SCOPE)
|
||||
endif()
|
||||
endforeach()
|
||||
list(APPEND names ${test_name})
|
||||
endforeach()
|
||||
set(${varname} ${names} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
210
CMake/testing/VTKmTestWrappers.cmake
Normal file
210
CMake/testing/VTKmTestWrappers.cmake
Normal file
@ -0,0 +1,210 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
|
||||
include(VTKmWrappers)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Declare unit tests, which should be in the same directory as a kit
|
||||
# (package, module, whatever you call it). Usage:
|
||||
#
|
||||
# vtkm_unit_tests(
|
||||
# NAME
|
||||
# SOURCES <source_list>
|
||||
# LIBRARIES <dependent_library_list>
|
||||
# DEFINES <target_compile_definitions>
|
||||
# TEST_ARGS <argument_list>
|
||||
# MPI
|
||||
# ALL_BACKENDS
|
||||
# <options>
|
||||
# )
|
||||
#
|
||||
# [LIBRARIES] : extra libraries that this set of tests need to link too
|
||||
#
|
||||
# [DEFINES] : extra defines that need to be set for all unit test sources
|
||||
#
|
||||
# [TEST_ARGS] : arguments that should be passed on the command line to the
|
||||
# test executable
|
||||
#
|
||||
# [MPI] : when specified, the tests should be run in parallel if
|
||||
# MPI is enabled.
|
||||
# [ALL_BACKENDS] : when specified, the tests would test against all enabled
|
||||
# backends. Otherwise we expect the tests to manage the
|
||||
# backends at runtime.
|
||||
#
|
||||
function(vtkm_unit_tests)
|
||||
if (NOT VTKm_ENABLE_TESTING)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(options)
|
||||
set(global_options ${options} MPI ALL_BACKENDS)
|
||||
set(oneValueArgs BACKEND NAME)
|
||||
set(multiValueArgs SOURCES LIBRARIES DEFINES TEST_ARGS)
|
||||
cmake_parse_arguments(VTKm_UT
|
||||
"${global_options}" "${oneValueArgs}" "${multiValueArgs}"
|
||||
${ARGN}
|
||||
)
|
||||
vtkm_parse_test_options(VTKm_UT_SOURCES "${options}" ${VTKm_UT_SOURCES})
|
||||
|
||||
set(test_prog)
|
||||
|
||||
|
||||
set(per_device_command_line_arguments "")
|
||||
set(per_device_suffix "")
|
||||
set(per_device_timeout 180)
|
||||
set(per_device_serial FALSE)
|
||||
|
||||
set(enable_all_backends ${VTKm_UT_ALL_BACKENDS})
|
||||
if(enable_all_backends)
|
||||
set(per_device_command_line_arguments --device=serial)
|
||||
set(per_device_suffix "SERIAL")
|
||||
|
||||
if (VTKm_ENABLE_CUDA)
|
||||
list(APPEND per_device_command_line_arguments --device=cuda)
|
||||
list(APPEND per_device_suffix "CUDA")
|
||||
#CUDA tests generally require more time because of kernel generation.
|
||||
list(APPEND per_device_timeout 1500)
|
||||
list(APPEND per_device_serial FALSE)
|
||||
endif()
|
||||
if (VTKm_ENABLE_TBB)
|
||||
list(APPEND per_device_command_line_arguments --device=tbb)
|
||||
list(APPEND per_device_suffix "TBB")
|
||||
list(APPEND per_device_timeout 180)
|
||||
list(APPEND per_device_serial FALSE)
|
||||
endif()
|
||||
if (VTKm_ENABLE_OPENMP)
|
||||
list(APPEND per_device_command_line_arguments --device=openmp)
|
||||
list(APPEND per_device_suffix "OPENMP")
|
||||
list(APPEND per_device_timeout 180)
|
||||
#We need to have all OpenMP tests run serially as they
|
||||
#will uses all the system cores, and we will cause a N*N thread
|
||||
#explosion which causes the tests to run slower than when run
|
||||
#serially
|
||||
list(APPEND per_device_serial TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(VTKm_UT_NAME)
|
||||
set(test_prog "${VTKm_UT_NAME}")
|
||||
else()
|
||||
vtkm_get_kit_name(kit)
|
||||
set(test_prog "UnitTests_${kit}")
|
||||
endif()
|
||||
|
||||
if(VTKm_UT_MPI)
|
||||
# for MPI tests, suffix test name and add MPI_Init/MPI_Finalize calls.
|
||||
set(test_prog "${test_prog}_mpi")
|
||||
set(extraArgs EXTRA_INCLUDE "vtkm/cont/testing/Testing.h"
|
||||
FUNCTION "vtkm::cont::testing::Environment env")
|
||||
else()
|
||||
set(extraArgs)
|
||||
endif()
|
||||
|
||||
#the creation of the test source list needs to occur before the labeling as
|
||||
#cuda. This is so that we get the correctly named entry points generated
|
||||
create_test_sourcelist(test_sources ${test_prog}.cxx ${VTKm_UT_SOURCES} ${extraArgs})
|
||||
|
||||
add_executable(${test_prog} ${test_prog}.cxx ${VTKm_UT_SOURCES})
|
||||
target_compile_definitions(${test_prog} PRIVATE ${VTKm_UT_DEFINES})
|
||||
|
||||
#if all backends are enabled, we can use cuda compiler to handle all possible backends.
|
||||
set(device_sources )
|
||||
if(TARGET vtkm::cuda AND enable_all_backends)
|
||||
set(device_sources ${VTKm_UT_SOURCES})
|
||||
endif()
|
||||
vtkm_add_target_information(${test_prog} DEVICE_SOURCES ${device_sources})
|
||||
|
||||
if(NOT VTKm_USE_DEFAULT_SYMBOL_VISIBILITY)
|
||||
set_property(TARGET ${test_prog} PROPERTY CUDA_VISIBILITY_PRESET "hidden")
|
||||
set_property(TARGET ${test_prog} PROPERTY CXX_VISIBILITY_PRESET "hidden")
|
||||
endif()
|
||||
set_property(TARGET ${test_prog} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
|
||||
set_property(TARGET ${test_prog} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
|
||||
set_property(TARGET ${test_prog} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH})
|
||||
|
||||
#Starting in CMake 3.13, cmake will properly drop duplicate libraries
|
||||
#from the link line so this workaround can be dropped
|
||||
if (CMAKE_VERSION VERSION_LESS 3.13 AND "vtkm_rendering" IN_LIST VTKm_UT_LIBRARIES)
|
||||
list(REMOVE_ITEM VTKm_UT_LIBRARIES "vtkm_cont")
|
||||
target_link_libraries(${test_prog} PRIVATE ${VTKm_UT_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(${test_prog} PRIVATE vtkm_cont ${VTKm_UT_LIBRARIES})
|
||||
endif()
|
||||
|
||||
foreach(index RANGE per_device_command_line_arguments)
|
||||
if(per_device_command_line_arguments STREQUAL "")
|
||||
set(device_command_line_argument ${per_device_command_line_arguments})
|
||||
set(upper_backend ${per_device_suffix})
|
||||
set(timeout ${per_device_timeout})
|
||||
set(run_serial ${per_device_serial})
|
||||
else()
|
||||
list(GET per_device_command_line_arguments ${index} device_command_line_argument)
|
||||
list(GET per_device_suffix ${index} upper_backend)
|
||||
list(GET per_device_timeout ${index} timeout)
|
||||
list(GET per_device_serial ${index} run_serial)
|
||||
endif()
|
||||
|
||||
foreach (test ${VTKm_UT_SOURCES})
|
||||
get_filename_component(tname ${test} NAME_WE)
|
||||
if(VTKm_UT_MPI AND VTKm_ENABLE_MPI)
|
||||
add_test(NAME ${tname}${upper_backend}
|
||||
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS}
|
||||
$<TARGET_FILE:${test_prog}> ${tname} ${device_command_line_argument} ${VTKm_UT_TEST_ARGS}
|
||||
${MPIEXEC_POSTFLAGS}
|
||||
)
|
||||
else()
|
||||
add_test(NAME ${tname}${upper_backend}
|
||||
COMMAND ${test_prog} ${tname} ${device_command_line_argument} ${VTKm_UT_TEST_ARGS}
|
||||
)
|
||||
endif()
|
||||
|
||||
set_tests_properties("${tname}${upper_backend}" PROPERTIES
|
||||
TIMEOUT ${timeout}
|
||||
RUN_SERIAL ${run_serial}
|
||||
FAIL_REGULAR_EXPRESSION "runtime error"
|
||||
)
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
endfunction(vtkm_unit_tests)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# vtkm_parse_test_options(varname options)
|
||||
# INTERNAL: Parse options specified for individual tests.
|
||||
#
|
||||
# Parses the arguments to separate out options specified after the test name
|
||||
# separated by a comma e.g.
|
||||
#
|
||||
# TestName,Option1,Option2
|
||||
#
|
||||
# For every option in options, this will set _TestName_Option1,
|
||||
# _TestName_Option2, etc in the parent scope.
|
||||
#
|
||||
function(vtkm_parse_test_options varname options)
|
||||
set(names)
|
||||
foreach(arg IN LISTS ARGN)
|
||||
set(test_name ${arg})
|
||||
set(test_options)
|
||||
if(test_name AND "x${test_name}" MATCHES "^x([^,]*),(.*)$")
|
||||
set(test_name "${CMAKE_MATCH_1}")
|
||||
string(REPLACE "," ";" test_options "${CMAKE_MATCH_2}")
|
||||
endif()
|
||||
foreach(opt IN LISTS test_options)
|
||||
list(FIND options "${opt}" index)
|
||||
if(index EQUAL -1)
|
||||
message(WARNING "Unknown option '${opt}' specified for test '${test_name}'")
|
||||
else()
|
||||
set(_${test_name}_${opt} TRUE PARENT_SCOPE)
|
||||
endif()
|
||||
endforeach()
|
||||
list(APPEND names ${test_name})
|
||||
endforeach()
|
||||
set(${varname} ${names} PARENT_SCOPE)
|
||||
endfunction()
|
@ -143,6 +143,9 @@ include(VTKmCompilerFlags)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# We include the wrappers unconditionally as VTK-m expects the function to
|
||||
# always exist (and early terminate when testing is disabled).
|
||||
include(testing/VTKmTestWrappers)
|
||||
if (VTKm_ENABLE_TESTING)
|
||||
enable_testing()
|
||||
# Only include CTest if it has not been included by a superproject. The
|
||||
@ -155,6 +158,7 @@ if (VTKm_ENABLE_TESTING)
|
||||
mark_as_advanced(BUILD_TESTING)
|
||||
endif()
|
||||
|
||||
|
||||
configure_file(${VTKm_SOURCE_DIR}/CTestCustom.cmake.in
|
||||
${VTKm_BINARY_DIR}/CTestCustom.cmake @ONLY)
|
||||
|
||||
@ -187,7 +191,7 @@ add_subdirectory(vtkm)
|
||||
#-----------------------------------------------------------------------------
|
||||
# Build documentation
|
||||
if (VTKm_ENABLE_DOCUMENTATION)
|
||||
include(CMake/VTKmBuildDocumentation.cmake)
|
||||
include(VTKmBuildDocumentation)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
@ -45,4 +45,4 @@ set(unit_tests
|
||||
UnitTestVecVariable.cxx
|
||||
)
|
||||
|
||||
VTKM_unit_tests(SOURCES ${unit_tests})
|
||||
vtkm_unit_tests(SOURCES ${unit_tests})
|
||||
|
Loading…
Reference in New Issue
Block a user