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

TARGETeither TARGET or COMMAND must be provided, unless TYPE is PYTHON

target name to be built

SOURCESrequired if TARGET is provided

list of source files to be compiled

OBJECTSoptional

list of object libraries to add to this target

COMMANDeither TARGET or COMMAND must be provided, unless TYPE is PYTHON

command or script to execute (no executable is built)

TYPEoptional

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)

LABELSoptional

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>.

ARGSoptional

list of arguments to pass to TARGET or COMMAND when running the test

RESOURCESoptional

list of files to copy from the test source directory to the test directory

TEST_DATAoptional

list of test data files to download

MPIoptional

Run with MPI using the given number of MPI tasks.

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

OMPoptional

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.

ENABLEDoptional

if set to OFF, the test is built but not enabled as a test case

LIBSoptional

list of libraries to link against (CMake targets or external libraries)

INCLUDESoptional

list of paths to add to include directories

DEFINITIONSoptional

list of definitions to add to preprocessor defines

PERSISTENToptional

list of persistent layer object files

GENERATEDoptional

list of files to mark as generated (sets GENERATED source file property)

DEPENDSoptional

list of targets to be built before this target

TEST_DEPENDSoptional

list of tests to be run before this one

CONDITIONoptional

conditional expression which must evaluate to true for this target to be built (must be valid in a CMake if statement)

PROPERTIESoptional

custom properties to set on the target

ENVIRONMENToptional

list of environment variables to set in the test environment

WORKING_DIRECTORYoptional

directory to switch to before running the test

CFLAGSoptional

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

See usage note below.

CXXFLAGSoptional

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

See usage note below.

FFLAGSoptional

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

See usage note below.

LINKER_LANGUAGEoptional

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.