ecbuild_add_test

Add a test as a script or an executable with a given list of source files.

ecbuild_add_test( [ TARGET <name> ]
                  [ SOURCES <source1> [<source2> ...] ]
                  [ OBJECTS <obj1> [<obj2> ...] ]
                  [ COMMAND <executable> ]
                  [ TYPE EXE|SCRIPT|PYTHON ]
                  [ LABELS <label1> [<label2> ...] ]
                  [ ARGS <argument1> [<argument2> ...] ]
                  [ RESOURCES <file1> [<file2> ...] ]
                  [ TEST_DATA <file1> [<file2> ...] ]
                  [ MPI <number-of-mpi-tasks> ]
                  [ OMP <number-of-threads-per-mpi-task> ]
                  [ ENABLED ON|OFF ]
                  [ LIBS <library1> [<library2> ...] ]
                  [ INCLUDES <path1> [<path2> ...] ]
                  [ DEFINITIONS <definition1> [<definition2> ...] ]
                  [ PERSISTENT <file1> [<file2> ...] ]
                  [ GENERATED <file1> [<file2> ...] ]
                  [ DEPENDS <target1> [<target2> ...] ]
                  [ TEST_DEPENDS <target1> [<target2> ...] ]
                  [ CONDITION <condition> ]
                  [ PROPERTIES <prop1> <val1> [<prop2> <val2> ...] ]
                  [ ENVIRONMENT <variable1> [<variable2> ...] ]
                  [ WORKING_DIRECTORY <path> ]
                  [ CFLAGS <flag1> [<flag2> ...] ]
                  [ CXXFLAGS <flag1> [<flag2> ...] ]
                  [ FFLAGS <flag1> [<flag2> ...] ]
                  [ LINKER_LANGUAGE <lang> ] )

Options

TARGET : either TARGET or COMMAND must be provided, unless TYPE is PYTHON
target name to be built
SOURCES : required if TARGET is provided
list of source files to be compiled
OBJECTS : optional
list of object libraries to add to this target
COMMAND : either TARGET or COMMAND must be provided, unless TYPE is PYTHON
command or script to execute (no executable is built)
TYPE : optional

test type, one of:

EXE:run built executable, default if TARGET is provided
SCRIPT:run command or script, default if COMMAND is provided
PYTHON:run a Python script (requires the Python interpreter to be found)
LABELS : optional

list of labels to assign to the test

The project name in lower case is always added as a label. Additional labels are assigned depending on the type of test:

executable:for type EXE
script:for type SCRIPT
python:for type PYTHON
mpi:if MPI is set
openmp:if OMP is set

This allows selecting tests to run via ctest -L <regex> or tests to exclude via ctest -LE <regex>.

ARGS : optional
list of arguments to pass to TARGET or COMMAND when running the test
RESOURCES : optional
list of files to copy from the test source directory to the test directory
TEST_DATA : optional
list of test data files to download
MPI : optional

Run with MPI using the given number of MPI tasks.

If greater than 1, and MPIEXEC is not available, the test is disabled.

OMP : optional

number of OpenMP threads per MPI task to use.

If set, the environment variable OMP_NUM_THREADS will set. Also, in case of launchers like aprun, the OMP_NUMTHREADS_FLAG will be used.

ENABLED : optional
if set to OFF, the test is built but not enabled as a test case
LIBS : optional
list of libraries to link against (CMake targets or external libraries)
INCLUDES : optional
list of paths to add to include directories
DEFINITIONS : optional
list of definitions to add to preprocessor defines
PERSISTENT : optional
list of persistent layer object files
GENERATED : optional
list of files to mark as generated (sets GENERATED source file property)
DEPENDS : optional
list of targets to be built before this target
TEST_DEPENDS : optional
list of tests to be run before this one
CONDITION : optional
conditional expression which must evaluate to true for this target to be built (must be valid in a CMake if statement)
PROPERTIES : optional
custom properties to set on the target
ENVIRONMENT : optional
list of environment variables to set in the test environment
WORKING_DIRECTORY : optional
directory to switch to before running the test
CFLAGS : optional

list of C compiler flags to use for all C source files

See usage note below.

CXXFLAGS : optional

list of C++ compiler flags to use for all C++ source files

See usage note below.

FFLAGS : optional

list of Fortran compiler flags to use for all Fortran source files

See usage note below.

LINKER_LANGUAGE : optional
sets the LINKER_LANGUAGE property on the target

Usage

The CFLAGS, CXXFLAGS and FFLAGS options apply the given compiler flags to all C, C++ and Fortran sources passed to this command, respectively. If any two ecbuild_add_executable, ecbuild_add_library or ecbuild_add_test commands are passed the same source file and each sets a different value for the compiler flags to be applied to that file (including when one command adds flags and another adds none), then the two commands will be in conflict and the result may not be as expected.

For this reason it is recommended not to use the *FLAGS options when multiple targets share the same source files, unless the exact same flags are applied to those sources by each relevant command.

Care should also be taken to ensure that these commands are not passed source files which are not required to build the target, if those sources are also passed to other commands which set different compiler flags.