Commit ca1d6fb8 authored by Lukas Riedel's avatar Lukas Riedel

Improve CMake testing functions

* 'dorie_add_metaini_test':
    * Make handle metaini input files or regular files
    * Always configure metaini files and place them into the build dir
    * Error out on the case UNIT_TEST and TARGET

* Add CMake docstrings
* Remove '.mini'  files from gitignore list
parent a87d39d1
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
build-cmake/ build-cmake/
# Exclude generated files # Exclude generated files
test/*.mini
python/parfield/wrapper/pf_from_file.py python/parfield/wrapper/pf_from_file.py
python/testtools/wrapper/test_dorie.py python/testtools/wrapper/test_dorie.py
python/testtools/wrapper/test_dorie_pfg.py python/testtools/wrapper/test_dorie_pfg.py
......
...@@ -10,7 +10,14 @@ add_custom_target(system_tests ...@@ -10,7 +10,14 @@ add_custom_target(system_tests
COMMAND ctest --output-on-failure --exclude-regex ^ut.+$ COMMAND ctest --output-on-failure --exclude-regex ^ut.+$
) )
# Add appropriate links for generating code coverage information to targets #
# .. cmake_function:: add_coverage_links
#
# This function adds the appropriate compiler and linker flags for creating
# a coverage report from the resulting object files of the specified targets.
# Signature:
# `add_coverage_links(<target>...)`
#
function(add_coverage_links) function(add_coverage_links)
foreach(target ${ARGV}) foreach(target ${ARGV})
target_compile_options(${target} PRIVATE --coverage) target_compile_options(${target} PRIVATE --coverage)
...@@ -18,7 +25,29 @@ function(add_coverage_links) ...@@ -18,7 +25,29 @@ function(add_coverage_links)
endforeach() endforeach()
endfunction() endfunction()
# Add a unit test. This forwards all arguments to dune_add_test #
# .. cmake_function:: dorie_add_unit_test
#
# .. cmake_param:: NAME
# :single:
# :required:
#
# The name of the resulting test executable and target.
#
# .. cmake_param:: TARGET
# :single:
#
# The target this test applies to. This is only required if no SOURCES
# are specified.
#
# This function serves as wrapper around the function `dune_add_test` which
# registers test for existing targets or adds new test executables from the
# given source files. This function additionally registers the tests as unit
# tests within DORiE and adds flags for coverage reports. Notice that
# `dune_add_test` requires more parameters than this function alone.
#
# Use this function exactly like `dune_add_test`.
#
function(dorie_add_unit_test) function(dorie_add_unit_test)
set(SINGLE NAME TARGET) set(SINGLE NAME TARGET)
cmake_parse_arguments(UNIT_TEST "" "${SINGLE}" "" ${ARGN}) cmake_parse_arguments(UNIT_TEST "" "${SINGLE}" "" ${ARGN})
...@@ -42,16 +71,87 @@ function(dorie_add_unit_test) ...@@ -42,16 +71,87 @@ function(dorie_add_unit_test)
add_dependencies(build_unit_tests ${UNIT_TEST_TARGET}) add_dependencies(build_unit_tests ${UNIT_TEST_TARGET})
endfunction() endfunction()
# Add a system test #
# .. cmake_function:: dorie_add_metaini_test
#
# .. cmake_param:: UNIT_TEST
# :option:
#
# Registers the created tests as unit tests, including coverage flags.
# If not specified, the tests are registered as system tests.
#
# .. cmake_param:: TARGET
# :single:
#
# The existing target to apply these tests to. This is incompatible to
# the option `UNIT_TEST` and the parameter `BASENAME`, because the base
# name of the tests will automatically be set to the target name.
#
# .. cmake_param:: METAINI
# :single:
# :required:
#
# The meta-ini _input_ file for this test.
#
# .. cmake_param:: SCRIPT
# :single:
#
# The Python script to call for this test. The script has to be installed
# into the CMake `virtualenv`. Defaults to `dune_execute.py` for unit
# tests and `test_dorie.py` for system tests.
#
# .. cmake_param:: BASENAME
# :single:
#
# The basename for tests created from source files. This option is ignored
# (by `dune_add_system_test`) if `TARGET` is specified.
#
# .. cmake_param:: CREATED_TARGETS
# :single:
#
# The variable to hold the created CMake targets for post-processing.
#
# This function serves as wrapper around the function `dune_add_system_test`
# which registers test for existing targets or adds new test executables from
# the given source files by expanding meta ini files.
# This function can register the tests as unit or as system tests within
# DORiE. Notice that `dune_add_system_test` requires more parameters
# than this function alone.
#
# Use this function like `dune_add_system_test`, considering the options
# given above.
#
function(dorie_add_metaini_test) function(dorie_add_metaini_test)
set(OPTIONS UNIT_TEST) set(OPTIONS UNIT_TEST)
set(SINGLE METAINI SCRIPT BASENAME CREATED_TARGETS) set(SINGLE TARGET METAINI SCRIPT BASENAME CREATED_TARGETS)
cmake_parse_arguments(SYSTEM_TEST "${OPTIONS}" "${SINGLE}" "" ${ARGN}) cmake_parse_arguments(SYSTEM_TEST "${OPTIONS}" "${SINGLE}" "" ${ARGN})
if(NOT SYSTEM_TEST_METAINI) if(NOT SYSTEM_TEST_METAINI)
message(SEND_ERROR "No meta ini file given!") message(SEND_ERROR "No meta ini file given!")
endif() endif()
configure_file(${SYSTEM_TEST_METAINI}.in ${CMAKE_CURRENT_LIST_DIR}/${SYSTEM_TEST_METAINI})
# configure meta ini file or just copy.
get_filename_component(metaini-name ${SYSTEM_TEST_METAINI} NAME_WE)
get_filename_component(metaini-extension ${SYSTEM_TEST_METAINI} EXT)
if(metaini-extension EQUAL ".mini.in")
configure_file(${SYSTEM_TEST_METAINI} ${metaini-name}.mini)
set(SYSTEM_TEST_METAINI "${metaini-name}.mini")
else()
configure_file(${SYSTEM_TEST_METAINI} ${SYSTEM_TEST_METAINI})
endif()
if(SYSTEM_TEST_TARGET AND SYSTEM_TEST_UNIT_TEST)
message(SEND_ERROR "Specifying TARGET is incompatible to option UNIT_TEST!")
endif()
# Set at least the prefix as basename
if(NOT SYSTEM_TEST_TARGET)
if(SYSTEM_TEST_UNIT_TEST)
string(PREPEND SYSTEM_TEST_BASENAME ut-)
else()
string(PREPEND SYSTEM_TEST_BASENAME st-)
endif()
endif()
# default script for system tests # default script for system tests
if(NOT SYSTEM_TEST_SCRIPT) if(NOT SYSTEM_TEST_SCRIPT)
...@@ -60,21 +160,12 @@ function(dorie_add_metaini_test) ...@@ -60,21 +160,12 @@ function(dorie_add_metaini_test)
endif() endif()
endif() endif()
# Set at least the prefix as basename
if(NOT SYSTEM_TEST_BASENAME)
set(SYSTEM_TEST_BASENAME "")
endif()
if(SYSTEM_TEST_UNIT_TEST)
string(PREPEND SYSTEM_TEST_BASENAME ut-)
else()
string(PREPEND SYSTEM_TEST_BASENAME st-)
endif()
# forward to DUNE function # forward to DUNE function
dune_add_system_test( dune_add_system_test(
${SYSTEM_TEST_UNPARSED_ARGUMENTS} ${SYSTEM_TEST_UNPARSED_ARGUMENTS}
TARGET ${SYSTEM_TEST_TARGET}
BASENAME ${SYSTEM_TEST_BASENAME} BASENAME ${SYSTEM_TEST_BASENAME}
INIFILE ${SYSTEM_TEST_METAINI} INIFILE ${CMAKE_CURRENT_BINARY_DIR}/${SYSTEM_TEST_METAINI}
SCRIPT ${SYSTEM_TEST_SCRIPT} SCRIPT ${SYSTEM_TEST_SCRIPT}
CREATED_TARGETS created_targets CREATED_TARGETS created_targets
) )
......
...@@ -11,17 +11,17 @@ function(dorie_add_system_test_dependency test1 test2) ...@@ -11,17 +11,17 @@ function(dorie_add_system_test_dependency test1 test2)
endfunction() endfunction()
# dorie run: ODE tests # dorie run: ODE tests
dorie_add_metaini_test(TARGET dorie METAINI ode_homogeneous_sand.mini) dorie_add_metaini_test(TARGET dorie METAINI ode_homogeneous_sand.mini.in)
dorie_add_metaini_test(TARGET dorie METAINI ode_homogeneous_silt.mini) dorie_add_metaini_test(TARGET dorie METAINI ode_homogeneous_silt.mini.in)
dorie_add_metaini_test(TARGET dorie METAINI ode_layered.mini) dorie_add_metaini_test(TARGET dorie METAINI ode_layered.mini.in)
# add target for ODE tests # add target for ODE tests
add_custom_target(test_run_ode add_custom_target(test_run_ode
COMMAND ctest --output-on-failure --tests-regex ^dorie_ode.+$) COMMAND ctest --output-on-failure --tests-regex ^dorie_ode.+$)
# dorie run: Reference tests # dorie run: Reference tests
dorie_add_metaini_test(TARGET dorie-rfg METAINI parfield_muphi.mini) dorie_add_metaini_test(TARGET dorie-rfg METAINI parfield_muphi.mini.in)
dorie_add_metaini_test(TARGET dorie METAINI muphi.mini) dorie_add_metaini_test(TARGET dorie METAINI muphi.mini.in)
set_tests_properties(dorie-rfg_ref_muphi_pfg PROPERTIES FIXTURES_SETUP muphi_ref) set_tests_properties(dorie-rfg_ref_muphi_pfg PROPERTIES FIXTURES_SETUP muphi_ref)
set_tests_properties(dorie_ref_muphi PROPERTIES FIXTURES_REQUIRED muphi_ref) set_tests_properties(dorie_ref_muphi PROPERTIES FIXTURES_REQUIRED muphi_ref)
...@@ -29,14 +29,14 @@ add_custom_target(test_run_ref ...@@ -29,14 +29,14 @@ add_custom_target(test_run_ref
COMMAND ctest --output-on-failure --tests-regex ^.+_ref_.+$ COMMAND ctest --output-on-failure --tests-regex ^.+_ref_.+$
) )
# dorie_add_system_test(dorie reference_2d.mini) # dorie_add_system_test(dorie reference_2d.mini.in)
# dorie_add_system_test(dorie reference_3d.mini) # dorie_add_system_test(dorie reference_3d.mini.in)
# dorie_add_system_test(dorie reference_evaporation.mini) # dorie_add_system_test(dorie reference_evaporation.mini.in)
# dorie_add_system_test(dorie reference_interpolators.mini) # dorie_add_system_test(dorie reference_interpolators.mini.in)
# dorie in parallel # dorie in parallel
dorie_add_metaini_test(TARGET dorie METAINI parallel_reference.mini) dorie_add_metaini_test(TARGET dorie METAINI parallel_reference.mini.in)
dorie_add_metaini_test(TARGET dorie METAINI parallel_reference_compare.mini) dorie_add_metaini_test(TARGET dorie METAINI parallel_reference_compare.mini.in)
set_tests_properties(dorie_parallel_reference_0000 PROPERTIES FIXTURES_SETUP dorie_par) set_tests_properties(dorie_parallel_reference_0000 PROPERTIES FIXTURES_SETUP dorie_par)
set_tests_properties(dorie_parallel_reference_0001 PROPERTIES FIXTURES_SETUP dorie_par) set_tests_properties(dorie_parallel_reference_0001 PROPERTIES FIXTURES_SETUP dorie_par)
...@@ -50,17 +50,17 @@ add_custom_target(test_run_parallel ...@@ -50,17 +50,17 @@ add_custom_target(test_run_parallel
) )
# dorie exec tests # dorie exec tests
dorie_add_metaini_test(TARGET dorie-rfg METAINI parfield.mini) dorie_add_metaini_test(TARGET dorie-rfg METAINI parfield.mini.in)
dorie_add_metaini_test(TARGET dorie METAINI run.mini) dorie_add_metaini_test(TARGET dorie METAINI run.mini.in)
set_tests_properties(dorie-rfg_exec_0000 PROPERTIES FIXTURES_SETUP dorie_run) set_tests_properties(dorie-rfg_exec_0000 PROPERTIES FIXTURES_SETUP dorie_run)
set_tests_properties(dorie_exec_run PROPERTIES FIXTURES_REQUIRED dorie_run) set_tests_properties(dorie_exec_run PROPERTIES FIXTURES_REQUIRED dorie_run)
dorie_add_metaini_test(TARGET dorie METAINI plot.mini) dorie_add_metaini_test(TARGET dorie METAINI plot.mini.in)
dorie_add_system_test_dependency(dorie_exec_plot dorie_exec_run) dorie_add_system_test_dependency(dorie_exec_plot dorie_exec_run)
set_tests_properties(dorie_exec_run PROPERTIES FIXTURES_SETUP dorie_plot) set_tests_properties(dorie_exec_run PROPERTIES FIXTURES_SETUP dorie_plot)
set_tests_properties(dorie_exec_plot PROPERTIES FIXTURES_REQUIRED dorie_plot) set_tests_properties(dorie_exec_plot PROPERTIES FIXTURES_REQUIRED dorie_plot)
dorie_add_metaini_test(TARGET dorie METAINI create.mini) dorie_add_metaini_test(TARGET dorie METAINI create.mini.in)
add_custom_target(test_dorie_exec add_custom_target(test_dorie_exec
COMMAND ctest --output-on-failure --tests-regex ^.+_exec.+$ COMMAND ctest --output-on-failure --tests-regex ^.+_exec.+$
...@@ -70,7 +70,7 @@ dorie_add_metaini_test( ...@@ -70,7 +70,7 @@ dorie_add_metaini_test(
SOURCE test-mass-conservation.cc SOURCE test-mass-conservation.cc
BASENAME mass-conservation BASENAME mass-conservation
CREATED_TARGETS mc_target CREATED_TARGETS mc_target
METAINI mass_conservation.mini METAINI mass_conservation.mini.in
SCRIPT dune_execute.py SCRIPT dune_execute.py
) )
...@@ -83,7 +83,7 @@ dorie_add_metaini_test(UNIT_TEST ...@@ -83,7 +83,7 @@ dorie_add_metaini_test(UNIT_TEST
SOURCE test-parameterization.cc SOURCE test-parameterization.cc
BASENAME test-parameterization BASENAME test-parameterization
CREATED_TARGETS par_target CREATED_TARGETS par_target
METAINI param.mini METAINI param.mini.in
SCRIPT SCRIPT
) )
add_custom_target(test_param add_custom_target(test_param
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment