/usr/share/deal.ii/macros/macro_deal_ii_add_test.cmake is in libdeal.ii-dev 8.4.2-2+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | ## ---------------------------------------------------------------------
##
## Copyright (C) 2013 - 2015 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE at
## the top level of the deal.II distribution.
##
## ---------------------------------------------------------------------
#
# A Macro to set up tests for the testsuite
#
#
# The testsuite distinguishes two different kinds of tests:
#
# - A combination of a source file "${test_name}.cc" (containing a main
# function) with a file "${comparison_file}" defines an executable that
# is compiled and linked against deal.II. Its output is compared with the
# comparison file. Additional libraries (like a library from a user
# project with code to test) the target should be linked against can be
# specified by
#
# TEST_LIBRARIES
# TEST_LIBRARIES_DEBUG
# TEST_LIBRARIES_RELEASE
#
# - A combination of a parameter file "${test_name}.prm" with a file
# "${comparison_file}" describes the configuration of an already compiled
# executable that should just be run with its output being compared with
# the file "${comparison_file}". The executable is defined by
#
# TEST_TARGET or
# TEST_TARGET_DEBUG and TEST_TARGET_RELEASE
#
# For every deal.II build type (given by the variable DEAL_II_BUILD_TYPES)
# that is a (case insensitive) substring of CMAKE_BUILD_TYPE a test is
# defined.
#
# This macro gets the following options from the comparison file name (have
# a look at the testsuite documentation for details):
# - usage of mpirun and number of simultaneous processes
# - valid build configurations
# - expected test stage
#
# The following variables must be set:
#
# NUMDIFF_EXECUTABLE, DIFF_EXECUTABLE
# - pointing to valid diff executables. If NUMDIFF_EXECUTABLE is not
# "numdiff" it will be ignored and DIFF_EXECUTABLE is used instead.
#
# TEST_TIME_LIMIT
# - specifying the maximal wall clock time in seconds a test is allowed
# to run
#
# Usage:
# DEAL_II_ADD_TEST(category test_name comparison_file)
#
MACRO(DEAL_II_ADD_TEST _category _test_name _comparison_file)
IF(NOT DEAL_II_PROJECT_CONFIG_INCLUDED)
MESSAGE(FATAL_ERROR
"\nDEAL_II_ADD_TEST can only be called in external (test sub-) projects after "
"the inclusion of deal.IIConfig.cmake. It is not intended for "
"internal use.\n\n"
)
ENDIF()
GET_FILENAME_COMPONENT(_file ${_comparison_file} NAME)
#
# Determine valid build configurations for this test:
#
SET(_configuration)
IF(_file MATCHES "\\.debug\\.")
SET(_configuration DEBUG)
ELSEIF(_file MATCHES "\\.release\\.")
SET(_configuration RELEASE)
ENDIF()
#
# A "binary" in the output file indicates binary output. In this case we
# have to switch to plain diff instead of (possibly) numdiff, which can
# only work on plain text files.
#
IF(_file MATCHES "\\.binary\\.")
SET(_test_diff ${DIFF_EXECUTABLE})
ELSE()
SET(_test_diff ${NUMDIFF_EXECUTABLE})
ENDIF()
#
# Determine whether the test should be run with mpirun:
#
STRING(REGEX MATCH "mpirun=([0-9]*)" _n_cpu ${_file})
IF("${_n_cpu}" STREQUAL "")
SET(_n_cpu 0) # 0 indicates that no mpirun should be used
ELSE()
STRING(REGEX REPLACE "^mpirun=([0-9]*)$" "\\1" _n_cpu ${_n_cpu})
ENDIF()
#
# Determine the expected build stage of this test:
#
STRING(REGEX MATCH "expect=([a-z]*)" _expect ${_file})
IF("${_expect}" STREQUAL "")
SET(_expect "PASSED")
ELSE()
STRING(REGEX REPLACE "^expect=([a-z]*)$" "\\1" _expect ${_expect})
STRING(TOUPPER ${_expect} _expect)
ENDIF()
#
# Determine for which build types a test should be defined. Every deal.II
# build type (given by the list DEAL_II_BUILD_TYPES) that is a (case
# insensitive) substring of CMAKE_BUILD_TYPE:
#
SET(_build_types "")
FOREACH(_build ${DEAL_II_BUILD_TYPES})
STRING(TOLOWER ${_build} _build_lowercase)
STRING(TOLOWER ${CMAKE_BUILD_TYPE} _cmake_build_type)
IF("${_cmake_build_type}" MATCHES "${_build_lowercase}")
LIST(APPEND _build_types ${_build})
ENDIF()
ENDFOREACH()
FOREACH(_build ${_build_types})
#
# Obey "debug" and "release" keywords in the output file:
#
ITEM_MATCHES(_match "${_build}" ${_configuration})
IF(_match OR "${_configuration}" STREQUAL "")
STRING(TOLOWER ${_build} _build_lowercase)
#
# Select a suitable target:
#
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.cc")
SET(_target ${_test_name}.${_build_lowercase}) # target name
SET(_run_command "$<TARGET_FILE:${_target}>") # the command to issue
ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm")
IF(NOT "${TEST_TARGET_${_build}}" STREQUAL "")
SET(_target ${TEST_TARGET_${_build}})
ELSEIF(NOT "${TEST_TARGET}" STREQUAL "")
SET(_target ${TEST_TARGET})
ELSE()
MESSAGE(FATAL_ERROR
"\nFor ${_comparison_file}: \"${_test_name}.prm\" provided, but "
"neither \"\${TEST_TARGET}\", nor \"\${TEST_TARGET_${_build}}"
"\" is defined.\n\n"
)
ENDIF()
SET(_run_command "$<TARGET_FILE:${_target}> ${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm")
ELSE()
MESSAGE(FATAL_ERROR
"\nFor ${_comparison_file}: Neither \"${_test_name}.cc\", "
"nor \"${_test_name}.prm\" could be found!\n\n"
)
ENDIF()
#
# Set up a bunch of variables describing this particular test:
#
# If _n_cpu is equal to "0", a normal, sequential test will be run,
# otherwise run the test with mpirun:
IF("${_n_cpu}" STREQUAL "0")
SET(_diff_target ${_test_name}.${_build_lowercase}.diff) # diff target name
SET(_test_full ${_category}/${_test_name}.${_build_lowercase}) # full test name
SET(_test_directory ${CMAKE_CURRENT_BINARY_DIR}/${_test_name}.${_build_lowercase}) # directory to run the test in
ELSE()
SET(_diff_target ${_test_name}.mpirun${_n_cpu}.${_build_lowercase}.diff) # diff target name
SET(_test_full ${_category}/${_test_name}.mpirun=${_n_cpu}.${_build_lowercase}) # full test name
SET(_test_directory ${CMAKE_CURRENT_BINARY_DIR}/${_test_name}.${_build_lowercase}/mpirun=${_n_cpu}) # directory to run the test in
SET(_run_command "${DEAL_II_MPIEXEC} ${DEAL_II_MPIEXEC_NUMPROC_FLAG} ${_n_cpu} ${DEAL_II_MPIEXEC_PREFLAGS} ${_run_command} ${DEAL_II_MPIEXEC_POSTFLAGS}")
ENDIF()
FILE(MAKE_DIRECTORY ${_test_directory})
#
# Add an executable (for the first type of tests) and set up compile
# definitions and the full link interface. Only add the target once.
#
IF(NOT TARGET ${_target})
#
# Add a "guard file" rule: The purpose of interrupt_guard.cc is to
# force a complete rerun of this test (BUILD, RUN and DIFF stage)
# if interrupt_guard.cc is removed by run_test.cmake due to an
# interruption.
#
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}/interrupt_guard.cc
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${_target}/interrupt_guard.cc
)
ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL
${_test_name}.cc
${CMAKE_CURRENT_BINARY_DIR}/${_target}/interrupt_guard.cc
)
DEAL_II_SETUP_TARGET(${_target} ${_build})
TARGET_LINK_LIBRARIES(${_target}
${TEST_LIBRARIES} ${TEST_LIBRARIES_${_build}}
)
SET_PROPERTY(TARGET ${_target} APPEND PROPERTY
COMPILE_DEFINITIONS SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
)
SET_PROPERTY(TARGET ${_target} PROPERTY
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_target}"
)
ENDIF()
#
# Add a top level target to run and compare the test:
#
ADD_CUSTOM_COMMAND(OUTPUT ${_test_directory}/output
COMMAND sh ${DEAL_II_PATH}/${DEAL_II_SHARE_RELDIR}/scripts/run_test.sh
run "${_test_full}" "${_run_command}" "${_test_diff}"
"${DIFF_EXECUTABLE}" "${_comparison_file}"
COMMAND ${PERL_EXECUTABLE}
-pi ${DEAL_II_PATH}/${DEAL_II_SHARE_RELDIR}/scripts/normalize.pl
${_test_directory}/output
WORKING_DIRECTORY
${_test_directory}
DEPENDS
${_target}
${DEAL_II_PATH}/${DEAL_II_SHARE_RELDIR}/scripts/normalize.pl
VERBATIM
)
FILE(GLOB _comparison_files ${_comparison_file} ${_comparison_file}.*)
ADD_CUSTOM_COMMAND(OUTPUT ${_test_directory}/diff
COMMAND sh ${DEAL_II_PATH}/${DEAL_II_SHARE_RELDIR}/scripts/run_test.sh
diff "${_test_full}" "${_run_command}" "${_test_diff}"
"${DIFF_EXECUTABLE}" "${_comparison_file}"
WORKING_DIRECTORY
${_test_directory}
DEPENDS
${_test_directory}/output
${_comparison_files}
VERBATIM
)
ADD_CUSTOM_TARGET(${_diff_target}
COMMAND echo "${_test_full}: BUILD successful."
COMMAND echo "${_test_full}: RUN successful."
COMMAND echo "${_test_full}: DIFF successful."
COMMAND echo "${_test_full}: PASSED."
DEPENDS ${_test_directory}/diff
)
#
# And finally define the test:
#
ADD_TEST(NAME ${_test_full}
COMMAND ${CMAKE_COMMAND}
-DTRGT=${_diff_target}
-DTEST=${_test_full}
-DEXPECT=${_expect}
-DBINARY_DIR=${CMAKE_BINARY_DIR}
-DGUARD_FILE=${CMAKE_CURRENT_BINARY_DIR}/${_test_name}.${_build_lowercase}/interrupt_guard.cc
-P ${DEAL_II_PATH}/${DEAL_II_SHARE_RELDIR}/scripts/run_test.cmake
WORKING_DIRECTORY ${_test_directory}
)
SET_TESTS_PROPERTIES(${_test_full} PROPERTIES
LABEL "${_category}"
TIMEOUT ${TEST_TIME_LIMIT}
)
#
# Limit concurrency of mpi tests. We can only set concurrency
# for the entire test, which includes the compiling and linking
# stages that are purely sequential. There is no good way to model
# this without unnecessarily restricting concurrency. Consequently,
# we just choose to model an "average" concurrency as one half of
# the number of MPI jobs.
#
IF(_n_cpu GREATER 2)
MATH(EXPR _slots "${_n_cpu} / 2")
SET_TESTS_PROPERTIES(${_test_full} PROPERTIES PROCESSORS ${_slots})
ENDIF()
IF(NOT "${_n_cpu}" STREQUAL "0")
#
# We have to be careful not to run different mpirun settings for the
# same executable in parallel because this triggers a race condition
# when compiling the not yet existent executable that is shared
# between the different tests.
#
# Luckily CMake has a mechanism to force a test to be run after
# another has finished (and both are scheduled):
#
IF(DEFINED TEST_DEPENDENCIES_${_target})
SET_TESTS_PROPERTIES(${_test_full} PROPERTIES
DEPENDS ${TEST_DEPENDENCIES_${_target}}
)
ENDIF()
SET(TEST_DEPENDENCIES_${_target} ${_test_full})
ENDIF()
ENDIF()
ENDFOREACH()
ENDMACRO()
|