Skip to content
Snippets Groups Projects
Commit bd8667b2 authored by Dominic Kempf's avatar Dominic Kempf
Browse files

Merge branch 'feature/new-dune-add-test-features' into 'master'

Implement some new features for dune_add_test

* `COMMANDS` was requested by @tkoch on the mailing list
* `COMPILE_ONLY` is useful for my latest YaspGrid tests, that check the code with and without deprecated interface features.
* `TIMEOUT` sets the timeout for ctest and is need in parallel testing

See merge request !1
parents d939f910 8d44187c
Branches
Tags
No related merge requests found
......@@ -92,7 +92,35 @@
# given here. Any number exceeding the user-specified processor maximum
# :ref:`DUNE_MAX_TEST_CORES` will be ignored. Tests with a
# processor number :code:`n` higher than one will have the suffix
# :code:`-mpi-n` appended to their name.
# :code:`-mpi-n` appended to their name. You need to specify the
# TIMEOUT option when specifying the MPI_RANKS option.
#
# .. cmake_param:: COMMAND
# :multi:
# :argname: cmd
#
# You may specify the COMMAND option to give the exact command line to be
# executed when running the test. This defaults to the name of the executable
# added by dune_add_test for this test. Note, that if you specify both CMD_ARGS
# and COMMAND, the given CMD_ARGS will be put behind your COMMAND. If you use
# this in combination with the MPI_RANKS parameter, the call to mpi will still be
# wrapped around the given commands.
#
# .. cmake_param:: COMPILE_ONLY
# :option:
#
# Set if the given test should only be compiled during :code:`make build_tests`,
# but not run during :code:`make test`. This is useful if you compile the same
# executable twice, but with different compile flags, where you want to assue that
# it compiles with both sets of flags, but you already know they will produce the
# same result.
#
# .. cmake_param:: TIMEOUT
# :single:
#
# If set, the test will time out after the given number of seconds. This supersedes
# any timeout setting in ctest (see `cmake --help-property TIMEOUT`). If you
# specify the MPI_RANKS option, you need to specify a TIMEOUT.
#
# This function defines the Dune way of adding a test to the testing suite.
# You may either add the executable yourself through :ref:`add_executable`
......@@ -132,9 +160,9 @@ endif()
function(dune_add_test)
include(CMakeParseArguments)
set(OPTIONS EXPECT_COMPILE_FAIL EXPECT_FAIL SKIP_ON_77)
set(SINGLEARGS NAME TARGET)
set(MULTIARGS SOURCES COMPILE_DEFINITIONS COMPILE_FLAGS LINK_LIBRARIES CMD_ARGS MPI_RANKS)
set(OPTIONS EXPECT_COMPILE_FAIL EXPECT_FAIL SKIP_ON_77 COMPILE_ONLY)
set(SINGLEARGS NAME TARGET TIMEOUT)
set(MULTIARGS SOURCES COMPILE_DEFINITIONS COMPILE_FLAGS LINK_LIBRARIES CMD_ARGS MPI_RANKS COMMAND)
cmake_parse_arguments(ADDTEST "${OPTIONS}" "${SINGLEARGS}" "${MULTIARGS}" ${ARGN})
# Check whether the parser produced any errors
......@@ -165,9 +193,18 @@ function(dune_add_test)
get_filename_component(ADDTEST_NAME ${ADDTEST_SOURCES} NAME_WE)
endif()
endif()
if(NOT ADDTEST_COMMAND)
set(ADDTEST_COMMAND ${ADDTEST_NAME})
endif()
if(ADDTEST_MPI_RANKS AND (NOT ADDTEST_TIMEOUT))
message(FATAL_ERROR "dune_add_test: You need to specify the TIMEOUT parameter if using the MPI_RANKS parameter.")
endif()
if(NOT ADDTEST_MPI_RANKS)
set(ADDTEST_MPI_RANKS 1)
endif()
if(NOT ADDTEST_TIMEOUT)
set(ADDTEST_TIMEOUT 300)
endif()
foreach(num ${ADDTEST_MPI_RANKS})
if(NOT "${num}" MATCHES "[1-9][0-9]*")
message(FATAL_ERROR "${num} was given to the MPI_RANKS arugment of dune_add_test, but it does not seem like a correct processor number")
......@@ -203,22 +240,19 @@ function(dune_add_test)
add_dependencies(build_tests ${ADDTEST_TARGET})
endif()
# By default, the target itself is sufficient as a testing command.
set(TESTCOMMAND ${ADDTEST_TARGET})
# Process the EXPECT_COMPILE_FAIL option
if(ADDTEST_EXPECT_COMPILE_FAIL)
set(TESTCOMMAND ${CMAKE_COMMAND} --build . --target ${TESTCOMMAND} --config $<CONFIGURATION>)
set(ADDTEST_COMMAND ${CMAKE_COMMAND} --build . --target ${ADDTEST_TARGET} --config $<CONFIGURATION>)
endif()
# Add one test for each specified processor number
foreach(procnum ${ADDTEST_MPI_RANKS})
if(NOT "${procnum}" GREATER "${DUNE_MAX_TEST_CORES}")
if((NOT "${procnum}" GREATER "${DUNE_MAX_TEST_CORES}") AND (NOT ADDTEST_COMPILE_ONLY))
if(NOT ${procnum} STREQUAL "1")
set(ACTUAL_TESTCOMMAND ${MPIEXEC} ${MPIEXEC_PREFLAGS} ${MPIEXEC_NUMPROC_FLAG} ${procnum} ${TESTCOMMAND} ${MPIEXEC_POSTFLAGS})
set(ACTUAL_TESTCOMMAND ${MPIEXEC} ${MPIEXEC_PREFLAGS} ${MPIEXEC_NUMPROC_FLAG} ${procnum} ${ADDTEST_COMMAND} ${MPIEXEC_POSTFLAGS})
set(ACTUAL_NAME "${ADDTEST_NAME}-mpi-${procnum}")
else()
set(ACTUAL_TESTCOMMAND ${TESTCOMMAND})
set(ACTUAL_TESTCOMMAND ${ADDTEST_COMMAND})
set(ACTUAL_NAME ${ADDTEST_NAME})
endif()
......@@ -229,6 +263,8 @@ function(dune_add_test)
# Define the number of processors (ctest will coordinate this with the -j option)
set_tests_properties(${ACTUAL_NAME} PROPERTIES PROCESSORS ${procnum})
# Apply the timeout (which was defaulted to 5 minutes if not specified)
set_tests_properties(${ACTUAL_NAME} PROPERTIES TIMEOUT ${ADDTEST_TIMEOUT})
# Process the EXPECT_FAIL option
if(ADDTEST_EXPECT_COMPILE_FAIL OR ADDTEST_EXPECT_FAIL)
set_tests_properties(${ACTUAL_NAME} PROPERTIES WILL_FAIL true)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment