Debian Codegraph @

cmake/tribits/core/test_support/TribitsAddAdvancedTest.cmake

raw
1 # @HEADER
2 # *****************************************************************************
3 # TriBITS: Tribal Build, Integrate, and Test System
4 #
5 # Copyright 2013-2016 NTESS and the TriBITS contributors.
6 # SPDX-License-Identifier: BSD-3-Clause
7 # *****************************************************************************
8 # @HEADER
9
10 include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE)
11 include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake")
12
13 set(tribitsAddAdvancedTestModuleDir "${CMAKE_CURRENT_LIST_DIR}")
14
15 include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddAdvancedTestHelpers.cmake")
16
17 include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsPrintList.cmake")
18 include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendStringVar.cmake")
19 include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake")
20
21
22 # @FUNCTION: tribits_add_advanced_test()
23 #
24 # Function that creates an advanced test defined by stringing together one or
25 # more executable and/or command invocations that is run as a ``cmake -P``
26 # script with very flexible pass/fail criteria.
27 #
28 # Usage::
29 #
30 # tribits_add_advanced_test(
31 # <testNameBase>
32 # TEST_0 (EXEC <execTarget0> | CMND <cmndExec0>) ...
33 # [TEST_1 (EXEC <execTarget1> | CMND <cmndExec1>) ...]
34 # ...
35 # [TEST_N (EXEC <execTargetN> | CMND <cmndExecN>) ...]
36 # [OVERALL_WORKING_DIRECTORY (<overallWorkingDir> | TEST_NAME)]
37 # [SKIP_CLEAN_OVERALL_WORKING_DIRECTORY]
38 # [FAIL_FAST]
39 # [RUN_SERIAL]
40 # [KEYWORDS <keyword1> <keyword2> ...]
41 # [COMM [serial] [mpi]]
42 # [OVERALL_NUM_MPI_PROCS <overallNumProcs>]
43 # [OVERALL_NUM_TOTAL_CORES_USED <overallNumTotalCoresUsed>]
44 # [CATEGORIES <category0> <category1> ...]
45 # [HOST <host0> <host1> ...]
46 # [XHOST <host0> <host1> ...]
47 # [HOSTTYPE <hosttype0> <hosttype1> ...]
48 # [XHOSTTYPE <hosttype0> <hosttype1> ...]
49 # [EXCLUDE_IF_NOT_TRUE <varname0> <varname1> ...]
50 # [DISABLED <messageWhyDisabled>]
51 # [FINAL_PASS_REGULAR_EXPRESSION "<regex>" |
52 # FINAL_FAIL_REGULAR_EXPRESSION "<regex>"]
53 # [ENVIRONMENT <var1>=<value1> <var2>=<value2> ...]
54 # [TIMEOUT <maxSeconds>]
55 # [LIST_SEPARATOR <sep>]
56 # [ADDED_TEST_NAME_OUT <testName>]
57 # )
58 #
59 # This function allows one to add a single CTest test that is actually a
60 # sequence of one or more separate commands strung together in some way to
61 # define the final pass/fail. One will want to use this function to add a test
62 # instead of `tribits_add_test()`_ when one needs to run more than one
63 # command, or one needs more sophisticated checking of the test result other
64 # than just grepping STDOUT (e.g. by running separate post-processing programs
65 # to examine output files).
66 #
67 # For more details on these arguments, see `TEST_<idx> EXEC/CMND Test Blocks
68 # and Arguments (tribits_add_advanced_test())`_.
69 #
70 # The most common type of an atomic test block ``TEST_<idx>`` runs a command
71 # as either a package-built executable or just any command. An atomic test
72 # command block ``TEST_<idx>`` (i.e. ``TEST_0``, ``TEST_1``, ...) takes the
73 # form::
74 #
75 # TEST_<idx>
76 # (EXEC <exeRootName> [NOEXEPREFIX] [NOEXESUFFIX] [ADD_DIR_TO_NAME]
77 # [DIRECTORY <dir>]
78 # | CMND <cmndExec>)
79 # [ARGS "<arg0>" "<arg1>" ... "<argn>"]
80 # [MESSAGE "<message>"]
81 # [WORKING_DIRECTORY <workingDir>]
82 # [SKIP_CLEAN_WORKING_DIRECTORY]
83 # [NUM_MPI_PROCS <numProcs>]
84 # [NUM_TOTAL_CORES_USED <numTotalCoresUsed>]
85 # [OUTPUT_FILE <outputFile>]
86 # [NO_ECHO_OUTPUT]]
87 # [PASS_ANY
88 # | PASS_REGULAR_EXPRESSION "<regex0>" "<regex1>" ...
89 # | PASS_REGULAR_EXPRESSION_ALL "<regex0>" "<regex1>" ...
90 # | STANDARD_PASS_OUTPUT ]
91 # [FAIL_REGULAR_EXPRESSION "<regex0>" "<regex1>" ...]
92 # [ALWAYS_FAIL_ON_NONZERO_RETURN | ALWAYS_FAIL_ON_ZERO_RETURN]
93 # [WILL_FAIL]
94 #
95 # For more information on these arguments, see `TEST_<idx> EXEC/CMND Test
96 # Blocks and Arguments (tribits_add_advanced_test())`_.
97 #
98 # The other type of ``TEST_<idx>`` block supported is for copying files and
99 # takes the form::
100 #
101 # TEST_<idx>
102 # COPY_FILES_TO_TEST_DIR <file0> <file1> ... <filen>
103 # [SOURCE_DIR <srcDir>]
104 # [DEST_DIR <destDir>]
105 #
106 # This makes it easy to copy files from the source tree (or other location) to
107 # inside of the test directory (usually created with ``OVERALL_WORKING_DIR
108 # TEST_NAME``) so that tests can run in their own private working directory
109 # (and so these files get deleted and recopied each time the test runs). This
110 # approach has several advantages:
111 #
112 # * One can modify the input files and then just run the test with ``ctest``
113 # in an iterative manner (and not have to configure again when using
114 # ``configure_file( ... COPYONLY)`` or build again when using
115 # ``tribits_copy_files_to_binary_dir()`` in order to copy files).
116 #
117 # * When using ``OVERALL_WORKING_DIR TEST_NAME``, the test directory gets blow
118 # away every time before it runs and therefore any old files are deleted
119 # before the test gets run again (which avoids the problem of having a test
120 # pass looking for the old files that will not be there when someone
121 # configures and builds from scratch).
122 #
123 # For more information on these arguments, see `TEST_<idx>
124 # COPY_FILES_TO_TEST_DIR Test Blocks and Arguments
125 # (tribits_add_advanced_test())`_.
126 #
127 # By default, each and every atomic ``TEST_<idx>`` block needs to pass (as
128 # defined in `Test case Pass/Fail (tribits_add_advanced_test())`_) in order
129 # for the overall test to pass.
130 #
131 # Finally, the test is only added if tests are enabled for the package
132 # (i.e. `${PACKAGE_NAME}_ENABLE_TESTS`_ ``= ON``) and if other criteria are
133 # met (see `Overall Arguments (tribits_add_advanced_test())`_). (NOTE: A more
134 # efficient way to optionally enable tests is to put them in a ``test/``
135 # subdir and then include that subdir with `tribits_add_test_directories()`_.)
136 #
137 # *Sections:*
138 #
139 # * `Overall Arguments (tribits_add_advanced_test())`_
140 # * `TEST_<idx> EXEC/CMND Test Blocks and Arguments (tribits_add_advanced_test())`_
141 # * `TEST_<idx> COPY_FILES_TO_TEST_DIR Test Blocks and Arguments (tribits_add_advanced_test())`_
142 # * `Test case Pass/Fail (tribits_add_advanced_test())`_
143 # * `Overall Pass/Fail (tribits_add_advanced_test())`_
144 # * `Argument Parsing and Ordering (tribits_add_advanced_test())`_
145 # * `Implementation Details (tribits_add_advanced_test())`_
146 # * `Setting Additional Test Properties (tribits_add_advanced_test())`_
147 # * `Running multiple tests at the same time (tribits_add_advanced_test())`_
148 # * `Disabling Tests Externally (tribits_add_advanced_test())`_
149 # * `Debugging and Examining Test Generation (tribits_add_advanced_test())`_
150 # * `Using tribits_add_advanced_test() in non-TriBITS CMake projects`_
151 #
152 # .. _Overall Arguments (tribits_add_advanced_test()):
153 #
154 # **Overall Arguments (tribits_add_advanced_test())**
155 #
156 # Below, some of the overall arguments are described. The rest of the overall
157 # arguments that control overall pass/fail are described in `Overall Pass/Fail
158 # (tribits_add_advanced_test())`_. (NOTE: All of these arguments must be
159 # listed outside of the ``TEST_<idx>`` blocks, see `Argument Parsing and
160 # Ordering (tribits_add_advanced_test())`_).
161 #
162 # ``<testNameBase>``
163 #
164 # The base name of the test (which will have ``${PACKAGE_NAME}_``
165 # prepended to the name, see <testName> below) that will be used to name
166 # the output CMake script file as well as the CTest test name passed into
167 # ``add_test()``. This must be the first argument to this function. The
168 # name is allowed to contain '/' chars but these will be replaced with
169 # '__' in the overall working directory name and the ctest -P script
170 # (`Debugging and Examining Test Generation
171 # (tribits_add_advanced_test())`_).
172 #
173 # ``OVERALL_WORKING_DIRECTORY <overallWorkingDir>``
174 #
175 # If specified, then the working directory ``<overallWorkingDir>``
176 # (relative or absolute path) will be created and all of the test commands
177 # by default will be run from within this directory. If the value
178 # ``<overallWorkingDir>=TEST_NAME`` is given, then the working directory
179 # will be given the name ``<testName>`` where any '/' chars are replaced
180 # with '__'. By default, if the directory ``<overallWorkingDir>`` exists
181 # before the test runs, it will be deleted and created again. If one
182 # wants to preserve the contents of this directory between test runs then
183 # set ``SKIP_CLEAN_OVERALL_WORKING_DIRECTORY``. Using a separate test
184 # directory is a good option to use if the commands create intermediate
185 # files and one wants to make sure they get deleted before the test cases
186 # are run again. It is also important to create a separate test directory
187 # if multiple tests are defined in the same ``CMakeLists.txt`` file that
188 # read/write files with the same name.
189 #
190 # ``SKIP_CLEAN_OVERALL_WORKING_DIRECTORY``
191 #
192 # If specified, then ``<overallWorkingDir>`` will **not** be deleted if it
193 # already exists.
194 #
195 # ``FAIL_FAST``
196 #
197 # If specified, then the remaining test commands will be aborted when any
198 # test command fails. Otherwise, all of the test cases will be run.
199 #
200 # ``RUN_SERIAL``
201 #
202 # If specified, then no other tests will be allowed to run while this test
203 # is running. See the ``RUN_SERIAL`` argument in the function
204 # `tribits_add_test()`_ for more details.
205 #
206 # ``COMM [serial] [mpi]``
207 #
208 # If specified, selects if the test will be added in serial and/or MPI
209 # mode. See the ``COMM`` argument in the function `tribits_add_test()`_
210 # for more details.
211 #
212 # ``OVERALL_NUM_MPI_PROCS <overallNumProcs>``
213 #
214 # If specified, gives the default number of MPI processes that each
215 # executable command runs on. If ``<overallNumProcs>`` is greater than
216 # ``${MPI_EXEC_MAX_NUMPROCS}`` then the test will be excluded. If not
217 # specified, then the default number of processes for an MPI build will be
218 # ``${MPI_EXEC_DEFAULT_NUMPROCS}``. For serial builds, this argument is
219 # ignored. For MPI builds with all ``TEST_<idx> CMND`` blocks,
220 # ``<overallNumProcs>`` is used to set the property ``PROCESSORS``. (see
221 # `Running multiple tests at the same time
222 # (tribits_add_advanced_test())`_). **WARNING!** If just running a serial
223 # script or other command, then the property ``PROCESSORS`` will still get
224 # set to ``${OVERALL_NUM_MPI_PROCS}`` so in order to avoid CTest
225 # unnecessarily reserving ``${OVERALL_NUM_MPI_PROCS}`` processes for a
226 # serial non-MPI test, then one must leave off ``OVERALL_NUM_MPI_PROCS``
227 # or explicitly pass in ``MPI_EXEC_DEFAULT_NUMPROCS 1``!
228 #
229 # ``OVERALL_NUM_TOTAL_CORES_USED <overallNumTotalCoresUsed>``
230 #
231 # Used for ``NUM_TOTAL_CORES_USED`` if missing in a ``TEST_<idx>`` block.
232 #
233 # ``CATEGORIES <category0> <category1> ...``
234 #
235 # Gives the `Test Test Categories`_ for which this test will be added.
236 # See `tribits_add_test()`_ for more details.
237 #
238 # ``HOST <host0> <host1> ...``
239 #
240 # The list of hosts for which to enable the test (see
241 # `tribits_add_test()`_).
242 #
243 # ``XHOST <host0> <host1> ...``
244 #
245 # The list of hosts for which **not** to enable the test (see
246 # `tribits_add_test()`_).
247 #
248 # ``HOSTTYPE <hosttype0> <hosttype1> ...``
249 #
250 # The list of host types for which to enable the test (see
251 # `tribits_add_test()`_).
252 #
253 # ``XHOSTTYPE <hosttype0> <hosttype1> ...``
254 #
255 # The list of host types for which **not** to enable the test (see
256 # `tribits_add_test()`_).
257 #
258 # ``EXCLUDE_IF_NOT_TRUE <varname0> <varname1> ...``
259 #
260 # If specified, gives the names of CMake variables that must evaluate to
261 # true, or the test will not be added (see `tribits_add_test()`_).
262 #
263 # ``DISABLED <messageWhyDisabled>``
264 #
265 # If ``<messageWhyDisabled>`` is non-empty and does not evaluate to FALSE
266 # by CMake, then the test will be added by ctest but the ``DISABLED`` test
267 # property will be set (see `tribits_add_test()`_).
268 #
269 # ``ENVIRONMENT "<var1>=<value1>" "<var2>=<value2>" ...``.
270 #
271 # If passed in, the listed environment variables will be set by CTest
272 # before calling the test. This is set using the built-in CTest test
273 # property ``ENVIRONMENT``. Note, if the env var values contain
274 # semi-colons ``';'``, then replace the semi-colons ``';'`` with another
275 # separator ``'<sep>'`` and pass in ``LIST_SEPARATOR <sep>`` so ``<sep>``
276 # will be replaced with ``';'`` at point of usage. If the env var values
277 # contain any spaces, also quote the entire variable/value pair as
278 # ``"<vari>=<valuei>"``. For example, the env var and value
279 # ``my_env_var="arg1 b;arg2;I have spaces"`` would need to be passed as
280 # ``"my_env_var=arg1 b<sep>arg2<sep>I have spaces"``.
281 #
282 # ``TIMEOUT <maxSeconds>``
283 #
284 # If passed in, gives maximum number of seconds the test will be allowed
285 # to run before being timed-out and killed (see `Setting timeouts for
286 # tests (tribits_add_test())`_). This is for the full CTest test, not
287 # individual ``TEST_<idx>`` commands!
288 #
289 # ``LIST_SEPARATOR <sep>``
290 #
291 # String used as placeholder for the semi-colon char ``';'`` in order to
292 # allow pass-through. For example, if arguments to the ``ARGS`` or
293 # ``ENVIRONMENT`` need to use semi-colons, then replace ``';'`` with
294 # ``'<semicolon>'`` (for example) such as with
295 # ``"somearg=arg1<semicolon>arg2"``, then at the point of usage,
296 # ``'<semicolon>'`` will be replaced with ``';'`` and it will be passed to
297 # the final command as ``"somearg=arg1;arg2"`` (with as many preceding
298 # escape backslashes ``'\'`` in front of ``';'`` as is needed for the
299 # given usage context).
300 #
301 # ``ADDED_TEST_NAME_OUT <testName>``
302 #
303 # If specified, then on output the variable ``<testName>`` will be set
304 # with the name of the test passed to ``add_test()``. Having this name
305 # allows the calling ``CMakeLists.txt`` file access and set additional
306 # test properties (see `Setting additional test properties
307 # (tribits_add_advanced_test())`_).
308 #
309 # .. _TEST_<idx> EXEC/CMND Test Blocks and Arguments (tribits_add_advanced_test()):
310 #
311 #
312 # **TEST_<idx> EXEC/CMND Test Blocks and Arguments (tribits_add_advanced_test())**
313 #
314 # Each test general command block ``TEST_<idx>`` runs either a package-built
315 # test executable or some general command executable and is defined as either
316 # ``EXEC <exeRootName>`` or an arbitrary command ``CMND <cmndExec>`` with the
317 # arguments:
318 #
319 # ``EXEC <exeRootName> [NOEXEPREFIX] [NOEXESUFFIX] [ADD_DIR_TO_NAME]
320 # [DIRECTORY <dir>]``
321 #
322 # If ``EXEC`` is specified, then ``<exeRootName>`` gives the root name of
323 # an executable target that will be run as the command. The full
324 # executable name and path is determined in exactly the same way it is in
325 # the `tribits_add_test()`_ function (see `Determining the Executable or
326 # Command to Run (tribits_add_test())`_). If this is an MPI build, then
327 # the executable will be run with MPI using ``NUM_MPI_PROCS <numProcs>``
328 # (or ``OVERALL_NUM_MPI_PROCS <overallNumProcs>`` if ``NUM_MPI_PROCS`` is
329 # not set for this test case). If the maximum number of MPI processes
330 # allowed is less than this number of MPI processes, then the test will
331 # *not* be run. Note that ``EXEC <exeRootName>`` when ``NOEXEPREFIX`` and
332 # ``NOEXESUFFIX`` are specified is basically equivalent to ``CMND
333 # <cmndExec>`` except that in an MPI build, ``<exeRootName>`` is always
334 # run using MPI. In this case, one can pass in ``<exeRootName>`` to any
335 # command one would like and it will get run with MPI in MPI mode just
336 # link any other MPI-enabled built executable.
337 #
338 # ``CMND <cmndExec>``
339 #
340 # If ``CMND`` is specified, then ``<cmndExec>`` gives the executable for a
341 # command to be run. In this case, MPI will never be used to run the
342 # executable even when configured in MPI mode
343 # (i.e. ``TPL_ENABLE_MPI=ON``). If one wants to run an arbitrary command
344 # using MPI, use ``EXEC <fullPathToCmndExec> NOEXEPREFIX NOEXESUFFIX``
345 # instead. **WARNING:** If you want to run such tests using valgrind, you
346 # have to use the raw executable as the ``<cmndExec>`` argument and *not*
347 # the script. For example, if you have a python script
348 # ``my_python_test.py`` with ``/usr/bin/env python3`` at the top, you can't
349 # just use::
350 #
351 # CMND <path>/my_python_test.py ARGS "<arg0>" "<arg1>" ...
352 #
353 # The same goes for Perl or any other scripting language.
354 #
355 # Instead, you have to use::
356 #
357 # CMND ${Python3_EXECUTABLE} ARGS <path>/my_python_test.py <arg0> <arg1> ...
358 #
359 # ``ARGS "<arg0>" "<arg1>" ... "<argN>"``
360 #
361 # The list of command-line arguments to pass to the ``CMND`` command or
362 # ``EXEC`` executable. Put each argument ``<argi>`` in quotes ``"<argi>"``
363 # if it contains any spaces. Also, of any of the individual arguments need
364 # to contain semi-colons ``';'`` such as ``--my-arg=a;b a;c;d``, then pass
365 # that quoted as ``"--my-arg=a<sep>b a<sep>c<sep>d"`` where ``<sep>``
366 # matches the ``<sep>`` argument to the input ``LIST_SEPARATOR <sep>``.
367 #
368 # By default, the output (stdout/stderr) for each test command is captured and
369 # is then echoed to stdout for the overall test. This is done in order to be
370 # able to grep the result to determine pass/fail.
371 #
372 # Other miscellaneous arguments for each ``TEST_<idx>`` block include:
373 #
374 # ``DIRECTORY <dir>``
375 #
376 # If specified, then the executable is assumed to be in the directory
377 # given by relative ``<dir>``. See `tribits_add_test()`_.
378 #
379 # ``MESSAGE "<message>"``
380 #
381 # If specified, then the string in ``"<message>"`` will be printed before
382 # this test command is run. This allows adding some documentation about
383 # each individual test invocation to make the test output more
384 # understandable.
385 #
386 # ``WORKING_DIRECTORY <workingDir>``
387 #
388 # If specified, then the working directory ``<workingDir>`` (relative or
389 # absolute) will be created and the test will be run from within this
390 # directory. If the directory ``<workingDir>`` exists before the test
391 # runs, it will be deleted and created again. If one wants to preserve
392 # the contents of this directory between test blocks, then one needs to
393 # set ``SKIP_CLEAN_WORKING_DIRECTORY``. Using a different
394 # ``WORKING_DIRECTORY`` for individual test commands allows creating
395 # independent working directories for each test case. This would be
396 # useful if a single ``OVERALL_WORKING_DIRECTORY`` was not sufficient for
397 # some reason.
398 #
399 # ``SKIP_CLEAN_WORKING_DIRECTORY``
400 #
401 # If specified, then ``<workingDir>`` will **not** be deleted if it
402 # already exists.
403 #
404 # ``NUM_MPI_PROCS <numProcs>``
405 #
406 # If specified, then ``<numProcs>`` is the number of processors used for
407 # MPI executables. If not specified, this will default to
408 # ``<overallNumProcs>`` from ``OVERALL_NUM_MPI_PROCS <overallNumProcs>``.
409 # If that is not specified, then the value is taken from
410 # ``${MPI_EXEC_DEFAULT_NUMPROCS}``. For serial builds
411 # (i.e. ``TPL_ENABLE_MPI=OFF``), passing in a value ``<numMpiProcs>`` >
412 # ``1`` will cause the entire test to not be added.
413 #
414 # ``NUM_TOTAL_CORES_USED <numTotalCoresUsed>``
415 #
416 # If specified, gives the total number of processes used by this
417 # command/executable. If this is missing, but ``NUM_MPI_PROCS
418 # <numProcs>`` is specified, then ``<numProcs>`` is used instead. If
419 # ``NUM_TOTAL_CORES_USED`` is missing BUT ``OVERALL_NUM_TOTAL_CORES_USED
420 # <overallNumTotalCoresUsed>`` is, then ``<overallNumTotalCoresUsed>`` is
421 # used for ``<numTotalCoresUsed>``. This argument is used for test
422 # scripts/executables that use more cores than MPI processes
423 # (i.e. ``<numProcs>``) and its only purpose is to inform CTest and
424 # TriBITS of the maximum number of cores that are used by the underlying
425 # test executable/script. When ``<numTotalCoresUsed>`` is greater than
426 # ``${MPI_EXEC_MAX_NUMPROCS}``, then the test will not be added.
427 # Otherwise, the CTest property ``PROCESSORS`` is set to the max over all
428 # ``<numTotalCoresUsed>`` so that CTest knows how to best schedule the
429 # test w.r.t. other tests on a given number of available processes.
430 #
431 # ``OUTPUT_FILE <outputFile>``
432 #
433 # If specified, then stdout and stderr for the test case will be sent to
434 # ``<outputFile>``. By default, the contents of this file will **also**
435 # be printed to STDOUT unless ``NO_ECHO_OUTPUT`` is passed as well.
436 #
437 # NOTE: Contrary to CMake documentation for execute_process(), STDOUT and
438 # STDERR may not get output in the correct order interleaved correctly,
439 # even in serial without MPI. Therefore, you can't write any tests that
440 # depend on the order of STDOUT and STDERR output in relation to each
441 # other. Also note that all of STDOUT and STDERR will be first read into
442 # the CTest executable process main memory before the file
443 # ``<outputFile>`` is written. Therefore, don't run executables or
444 # commands that generate massive amounts of console output or it may
445 # exhaust main memory. Instead, have the command or executable write
446 # directly to a file instead of going through STDOUT.
447 #
448 # ``NO_ECHO_OUTPUT``
449 #
450 # If specified, then the output for the test command will not be echoed to
451 # the output for the entire test command.
452 #
453 # By default, an individual test case ``TEST_<IDX>`` is assumed to pass if the
454 # executable or commands returns a non-zero value to the shell. However, a
455 # test case can also be defined to pass or fail based on the arguments/options
456 # (see `Test case Pass/Fail (tribits_add_advanced_test())`_):
457 #
458 # ``PASS_ANY``
459 #
460 # If specified, the test command will be assumed to pass regardless of
461 # the return value or any other output. This would be used when a command
462 # that is to follow will determine pass or fail based on output from this
463 # command in some way.
464 #
465 # ``PASS_REGULAR_EXPRESSION "<regex0>" "<regex1>" ...``
466 #
467 # If specified, the test command will be assumed to pass if it matches
468 # **any** of the given regular expressions. Otherwise, it is assumed to
469 # fail. TIPS: Replace ';' with '[;]' or CMake will interpret this as an
470 # array element boundary. To match '.', use '[.]'.
471 #
472 # ``PASS_REGULAR_EXPRESSION_ALL "<regex0>" "<regex1>" ...``
473 #
474 # If specified, the test command will be assumed to pass if the output
475 # matches **all** of the provided regular expressions. Note that this is not
476 # a capability of raw ctest and represents an extension provided by
477 # TriBITS. NOTE: It is critical that you replace ';' with '[;]' or CMake
478 # will interpret this as an array element boundary.
479 #
480 # ``STANDARD_PASS_OUTPUT``
481 #
482 # If specified, the test command will be assumed to pass if the string
483 # expression "Final Result: PASSED" is found in the output for the test.
484 # This as the result of directly passing in ``PASS_REGULAR_EXPRESSION
485 # "End Result: TEST PASSED"``.
486 #
487 # ``FAIL_REGULAR_EXPRESSION "<regex0>" "<regex1>" ...``
488 #
489 # If specified, the test command will be assumed to fail if it matches
490 # **any** of the given regular expressions. This will be applied and take
491 # precedence over other above pass criteria. For example, if even if
492 # ``PASS_REGULAR_EXPRESSION`` or ``PASS_REGULAR_EXPRESSION_ALL`` match,
493 # then the test will be marked as failed if any of the fail regexes match
494 # the output.
495 #
496 # ``ALWAYS_FAIL_ON_NONZERO_RETURN``
497 #
498 # If specified, then the test case will be marked as failed if the test
499 # command returns nonzero, independent of the other pass/fail criteria.
500 # This option is used in cases where one wants to grep for strings in the
501 # output but still wants to require a zero return code. This make for a
502 # stronger test by requiring that both the strings are found and that the
503 # command returns 0.
504 #
505 # ``ALWAYS_FAIL_ON_ZERO_RETURN``
506 #
507 # If specified, then the test case will be marked as failed if the test
508 # command returns zero '0', independent of the other pass/fail criteria.
509 # This option is used in cases where one wants to grep for strings in the
510 # output but still wants to require a nonzero return code. This make for
511 # a stronger test by requiring that both the strings are found and that
512 # the command returns != 0.
513 #
514 # ``WILL_FAIL``
515 #
516 # If specified, invert the result from the other pass/fail criteria. For
517 # example, if the regexes in ``PASS_REGULAR_EXPRESSION`` or
518 # ``PASS_REGULAR_EXPRESSION_ALL`` indicate that a test should pass, then
519 # setting ``WILL_FAIL`` will invert that and report the test as failing.
520 # But typically this is used to report a test that returns a nonzero code
521 # as passing.
522 #
523 # All of the arguments for a test block ``TEST_<idx>`` must appear directly
524 # below their ``TEST_<idx>`` argument and before the next test block (see
525 # `Argument Parsing and Ordering (tribits_add_advanced_test())`_).
526 #
527 # **NOTE:** The current implementation limits the number of ``TEST_<idx>``
528 # blocks to just 20 (i.e. for ``<idx>=0...19``). If more test blocks are
529 # added (e.g. ``TEST_20``), then an fatal error message will be printed and
530 # processing will end. To increase this max in a local scope, call::
531 #
532 # set(TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS <larger-num>)
533 #
534 # where ``<larger-num> > 20``. This can be set in any scope in any
535 # ``CMakeLists.txt`` file or inside of a function and it will impact all of
536 # the future calls to ``tribits_add_advanced_test()`` in that scope.
537 #
538 # .. _TEST_<idx> COPY_FILES_TO_TEST_DIR Test Blocks and Arguments (tribits_add_advanced_test()):
539 #
540 # **TEST_<idx> COPY_FILES_TO_TEST_DIR Test Blocks and Arguments (tribits_add_advanced_test())**
541 #
542 # The arguments for the ``TEST_<idx>`` ``COPY_FILES_TO_TEST_DIR`` block are:
543 #
544 # ``COPY_FILES_TO_TEST_DIR <file0> <file1> ... <filen>``
545 #
546 # Required list of 1 or more file names for files that will be copied from
547 # ``<srcDir>/`` to ``<destDir>/``.
548 #
549 # ``SOURCE_DIR <srcDir>``
550 #
551 # Optional source directory where the files will be copied from. If
552 # ``<srcDir>`` is not given, then it is assumed to be
553 # ``${CMAKE_CURRENT_SOURCE_DIR}``. If ``<srcDir>`` is given but is a
554 # relative path, then it is interpreted relative to
555 # ``${CMAKE_CURRENT_SOURCE_DIR}``. If ``<srcDir>`` is an absolute path,
556 # then that path is used without modification.
557 #
558 # ``DEST_DIR <destDir>``
559 #
560 # Optional destination directory where the files will be copied to. If
561 # ``<destDir>`` is not given, then it is assumed to be the working
562 # directory where the test is running (typically a new directory created
563 # under ``${CMAKE_CURRENT_BINARY_DIR}`` when ``OVERALL_WORKING_DIR
564 # TEST_NAME`` is given). If ``<destDir>`` is given but is a relative
565 # path, then it is interpreted relative to the current test working
566 # directory. If ``<destDir>`` is an absolute path, then that path is used
567 # without modification. If ``<destDir>`` does not exist, then it will be
568 # created (including several directory levels deep if needed).
569 #
570 # .. _Test case Pass/Fail (tribits_add_advanced_test()):
571 #
572 # **Test case Pass/Fail (tribits_add_advanced_test())**
573 #
574 # The logic given below can be used to determine pass/fail criteria for a test
575 # case both based on what is printed in the test output **and** the return
576 # code for the test block command. Raw CTest, as of version 3.23, does not
577 # allow that. With raw CTest, one can only set pass/fail criteria based the
578 # test output **or** the return code, but not both. This make
579 # `tribits_add_advanced_test()`_ more attractive to use than
580 # `tribits_add_test()`_ or raw ``add_test()`` in cases where it is important
581 # to check both.
582 #
583 # The logic for how pass/fail for a ``TEST_<IDX>`` ``EXEC`` or ``CMND`` case
584 # is applied is given by::
585 #
586 # # A) Apply first set of pass/fail logic
587 # TEST_CASE_PASSED = FALSE
588 # If PASS_ANY specified:
589 # TEST_CASE_PASSED = TRUE
590 # Else If PASS_REGULAR_EXPRESSION is specified:
591 # For each "<regexi>" in PASS_REGULAR_EXPRESSION:
592 # If "<regexi>" matches STDOUT:
593 # TEST_CASE_PASSED = TRUE
594 # Endif
595 # Endforeach
596 # Else if PASS_REGULAR_EXPRESSION_ALL specified:
597 # TEST_CASE_PASSED = TRUE
598 # For each "<regexi>" in PASS_REGULAR_EXPRESSION_ALL:
599 # If "<regexi>" does not match STDOUT:
600 # TEST_CASE_PASSED = FALSE
601 # Endif
602 # Endforeach
603 # Else
604 # If command return code == 0:
605 # TEST_CASE_PASSED = TRUE
606 # Endif
607 # Endif
608 #
609 # # B) Check for failing regex matching?
610 # If FAIL_REGULAR_EXPRESSION specified:
611 # For each "<regexi>" in FAIL_REGULAR_EXPRESSION:
612 # If "<regexi>" matches STDOUT:
613 # TEST_CASE_PASSED = FALSE
614 # Endif
615 # Endforeach
616 # Endif
617 #
618 # # C) Check for return code always 0 or !=0?
619 # If ALWAYS_FAIL_ON_NONZERO_RETURN specified and return code != 0:
620 # TEST_CASE_PASSED = FALSE
621 # Else If ALWAYS_FAIL_ON_ZERO_RETURN specified and return code == 0:
622 # TEST_CASE_PASSED = FALSE
623 # Endif
624 #
625 # # D) Invert pass/fail result?
626 # If WILL_FAIL specified:
627 # If TEST_CASE_PASSED:
628 # TEST_CASE_PASSED = FALSE
629 # Else
630 # TEST_CASE_PASSED = TRUE
631 # Endif
632 # Endif
633 #
634 # Note that the above is the exact same logic that CTest uses to determine
635 # pass/fail w.r.t. to the CTest properties ``PASS_REGULAR_EXPRESSION``,
636 # ``FAIL_REGULAR_EXPRESSION`` and ``WILL_FAIL``. (It is just that raw
637 # CMake/CTest, as of version 3.23, does not support any pass/fail criteria
638 # like ``PASS_REGULAR_EXPRESSION_ALL`` or
639 # ``ALWAYS_FAIL_ON_NONZERO_RETURN``/``ALWAYS_FAIL_ON_ZERO_RETURN``.)
640 #
641 # .. _Overall Pass/Fail (tribits_add_advanced_test()):
642 #
643 # **Overall Pass/Fail (tribits_add_advanced_test())**
644 #
645 # By default, the overall test will be assumed to pass if it prints::
646 #
647 # "OVERALL FINAL RESULT: TEST PASSED (<testName>)"
648 #
649 # However, this can be changed by setting one of the following optional arguments:
650 #
651 # ``FINAL_PASS_REGULAR_EXPRESSION "<regex0>" "<regex1>" ...``
652 #
653 # If specified, the test will be assumed to pass if the output matches
654 # **any** of the provided regular expressions ``<regexi>``. (Sets the
655 # CTest property ``PASS_REGULAR_EXPRESSION`` for the overall test.)
656 #
657 # ``FINAL_FAIL_REGULAR_EXPRESSION "<regex0>" "<regex1>" ...``
658 #
659 # If specified, the test will be assumed to fail if the output matches
660 # **any** of the provided regular expressions ``<regexi>`` regardless if
661 # other criteria would have the test passing. (Sets the CTest property
662 # ``FAIL_REGULAR_EXPRESSION`` for the overall test.)
663 #
664 # **NOTE:** It is **not** recommended to set ``FINAL_PASS_REGULAR_EXPRESSION``
665 # or ``FINAL_FAIL_REGULAR_EXPRESSION`` directly, but instead to determine
666 # pass/fail for each test case individually as described in `TEST_<idx>
667 # EXEC/CMND Test Blocks and Arguments (tribits_add_advanced_test())`_ and
668 # `Test case Pass/Fail (tribits_add_advanced_test())`_. Otherwise, the test
669 # will confuse most people and the output behavior will seem very strange.
670 #
671 # .. _Argument Parsing and Ordering (tribits_add_advanced_test()):
672 #
673 # **Argument Parsing and Ordering (tribits_add_advanced_test())**
674 #
675 # The basic tool used for parsing the arguments to this function is the
676 # command ``cmake_parse_arguments()`` which has a certain set of behaviors.
677 # The parsing using ``cmake_parse_arguments()`` is actually done in two
678 # phases. There is a top-level parsing of the "overall" arguments listed in
679 # `Overall Arguments (tribits_add_advanced_test())`_ that also pulls out the
680 # test blocks. Then there is a second level of parsing using
681 # ``cmake_parse_arguments()`` for each of the ``TEST_<idx>`` blocks. Because
682 # of this usage, there are a few restrictions that one needs to be aware of
683 # when using ``tribits_add_advanced_test()``. This short sections tries to
684 # explain the behaviors and what is allowed and what is not allowed.
685 #
686 # For the most part, the "overall" arguments and the arguments inside of any
687 # individual ``TEST_<idx>`` blocks can be listed in any order but there are
688 # restrictions related to the grouping of overall arguments and ``TEST_<idx>``
689 # blocks which are as follows:
690 #
691 # * The ``<testNameBase>`` argument must be the first listed (it is the only
692 # positional argument).
693 #
694 # * The test cases ``TEST_<idx>`` must be listed in order (i.e. ``TEST_0
695 # ... TEST_1 ...``) and the test cases must be consecutive integers
696 # (e.g. can't jump from ``TEST_5`` to ``TEST_7``).
697 #
698 # * All of the arguments for a test case must appear directly below its
699 # ``TEST_<idx>`` keyword and before the next ``TEST_<idx+1>`` keyword or
700 # before any trailing overall keyword arguments.
701 #
702 # * None of the overall arguments (e.g. ``CATEGORIES``) can be listed inside
703 # of a ``TEST_<idx>`` block but otherwise can be listed before or after all
704 # of the ``TEST_<idx>`` blocks. (NOTE: The current implementation will
705 # actually allow overall arguments to be listed after all of the local
706 # arguments before the next TEST_<idx> block but this is confusing and will
707 # not be allowed in a future implementation).
708 #
709 # Other than that, the keyword arguments and options can appear in any order.
710 #
711 # .. ToDo: Add some examples of bad argument ordering and what will happen.
712 #
713 # .. _Implementation Details (tribits_add_advanced_test()):
714 #
715 # **Implementation Details (tribits_add_advanced_test())**
716 #
717 # Since raw CTest does not support the features provided by this function, the
718 # way an advanced test is implemented is that a ``cmake -P`` script with the
719 # name ``<testName>.cmake`` (with any '/' replaced with '__') gets created in
720 # the current binary directory that then gets added to CTest using::
721 #
722 # add_test(<testName> cmake [other options] -P <testName>.cmake)
723 #
724 # This ``cmake -P`` script then runs the various test cases and checks the
725 # pass/fail for each case to determine overall pass/fail and implement other
726 # functionality described above.
727 #
728 # .. _Setting Additional Test Properties (tribits_add_advanced_test()):
729 #
730 # **Setting Additional Test Properties (tribits_add_advanced_test())**
731 #
732 # After this function returns, if the test gets added using ``add_test()``,
733 # then additional properties can be set and changed using
734 # ``set_tests_properties(<testName> ...)``, where ``<testName>`` is returned
735 # using the ``ADDED_TEST_NAME_OUT <testName>`` argument. Therefore, any tests
736 # properties that are not directly supported by this function and passed
737 # through the argument list to this wrapper function can be set in the outer
738 # ``CMakeLists.txt`` file after the call to ``tribits_add_advanced_test()``.
739 # For example::
740 #
741 # tribits_add_advanced_test_test( someTest ...
742 # ADDED_TEST_NAME_OUT someTest_TEST_NAME )
743 #
744 # if (someTest_TEST_NAME)
745 # set_tests_properties( ${someTest_TEST_NAME}
746 # PROPERTIES ATTACHED_FILES someTest.log )
747 # endif()
748 #
749 # where the test writes a log file ``someTest.log`` that we want to submit to
750 # CDash also.
751 #
752 # This approach will work no matter what TriBITS names the individual test(s)
753 # or whether the test(s) are added or not (depending on other arguments like
754 # ``COMM``, ``XHOST``, etc.).
755 #
756 # The following built-in CTest test properties are set through `Overall
757 # Arguments (tribits_add_advanced_test())`_ or are otherwise automatically set
758 # by this function and should **NOT** be overridden by direct calls to
759 # ``set_tests_properties()``: ``ENVIRONMENT``, ``FAIL_REGULAR_EXPRESSION``,
760 # ``LABELS``, ``PASS_REGULAR_EXPRESSION``, ``RUN_SERIAL``, ``TIMEOUT``,
761 # ``WILL_FAIL``, and ``WORKING_DIRECTORY``.
762 #
763 # However, generally, other built-in CTest test properties can be set after
764 # the test is added like show above. Examples of test properties that can be
765 # set using direct calls to ``set_tests_properties()`` include
766 # ``ATTACHED_FILES``, ``ATTACHED_FILES_ON_FAIL``, ``COST``, ``DEPENDS``,
767 # ``MEASUREMENT``, and ``RESOURCE_LOCK``.
768 #
769 # For example, one can set a dependency between two tests using::
770 #
771 # tribits_add_advanced_test_test( test_a [...]
772 # ADDED_TEST_NAME_OUT test_a_TEST_NAME )
773 #
774 # tribits_add_advanced_test_test( test_b [...]
775 # ADDED_TEST_NAME_OUT test_z_TEST_NAME )
776 #
777 # if (test_a_TEST_NAME AND test_b_TEST_NAME)
778 # set_tests_properties(${test_b_TEST_NAME}
779 # PROPERTIES DEPENDS ${test_a_TEST_NAME})
780 # endif()
781 #
782 # This ensures that test ``test_b`` will always be run after ``test_a`` if
783 # both tests are run by CTest.
784 #
785 # .. _Running multiple tests at the same time (tribits_add_advanced_test()):
786 #
787 # **Running multiple tests at the same time (tribits_add_advanced_test())**
788 #
789 # Just as with `tribits_add_test()`_, setting ``NUM_MPI_PROCS <numProcs>`` or
790 # ``OVERALL_NUM_MPI_PROCS <numOverallProcs>`` or ``NUM_TOTAL_CORES_USED
791 # <numTotalCoresUsed>`` or ``OVERALL_NUM_TOTAL_CORES_USED
792 # <overallNumTotalCoresUsed>`` will set the ``PROCESSORS`` CTest property to
793 # allow CTest to schedule and run multiple tests at the same time when ``'ctest
794 # -j<N>'`` is used (see `Running multiple tests at the same time
795 # (tribits_add_test())`_).
796 #
797 # .. _Disabling Tests Externally (tribits_add_advanced_test()):
798 #
799 # **Disabling Tests Externally (tribits_add_advanced_test())**
800 #
801 # The test can be disabled externally by setting the CMake cache variable
802 # ``<testName>_DISABLE=TRUE``. This allows tests to be disabled on a
803 # case-by-case basis. The name ``<testName>`` must be the *exact* name
804 # that shows up in ``ctest -N`` when running the test.
805 #
806 # .. _Debugging and Examining Test Generation (tribits_add_advanced_test()):
807 #
808 # **Debugging and Examining Test Generation (tribits_add_advanced_test())**
809 #
810 # In order to see what tests get added and if not then why, configure with
811 # ``${PROJECT_NAME}_TRACE_ADD_TEST=ON``. That will print one line per test
812 # that shows that the test got added or not and if not then why the test was
813 # not added (i.e. due to ``COMM``, ``OVERALL_NUM_MPI_PROCS``,
814 # ``NUM_MPI_PROCS``, ``CATEGORIES``, ``HOST``, ``XHOST``, ``HOSTTYPE``, or
815 # ``XHOSTTYPE``).
816 #
817 # Likely the best way to debug test generation using this function is to
818 # examine the generated file ``<testName>.cmake`` in the current binary
819 # directory (see `Implementation Details (tribits_add_advanced_test())`_) and
820 # the generated ``CTestTestfile.cmake`` file that should list this test case.
821 #
822 # .. _Using tribits_add_advanced_test() in non-TriBITS CMake projects:
823 #
824 # **Using tribits_add_advanced_test() in non-TriBITS CMake projects**
825 #
826 # The function ``tribits_add_advanced_test()`` can be used to add tests in
827 # non-TriBITS projects. To do so, one just needs to set the variables
828 # ``${PROJECT_NAME}_ENABLE_TESTS=TRUE`` and ``${PROJECT_NAME}_TRIBITS_DIR``
829 # (pointing to the TriBITS location). For example, a valid project can be a
830 # simple as::
831 #
832 # cmake_minimum_required(VERSION 3.23.0)
833 # set(PROJECT_NAME TAATDriver)
834 # project(${PROJECT_NAME} NONE)
835 # set(${PROJECT_NAME}_TRACE_ADD_TEST TRUE)
836 # set(${PROJECT_NAME}_TRIBITS_DIR "" CACHE FILEPATH
837 # "Location of TriBITS to use." )
838 # set(PACKAGE_NAME ${PROJECT_NAME})
839 # set(${PACKAGE_NAME}_ENABLE_TESTS TRUE)
840 # include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake")
841 # include(CTest)
842 # enable_testing()
843 #
844 # tribits_add_advanced_test( HelloWorld
845 # OVERALL_WORKING_DIRECTORY TEST_NAME
846 # TEST_0 CMND echo ARGS "Hello World!"
847 # PASS_REGULAR_EXPRESIOIN "Hello World"
848 # )
849 #
850 # Above, one can replace::
851 #
852 # include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake")
853 #
854 # with::
855 #
856 # list(PREPEND CMAKE_MODULE_PATH "${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support")
857 # include(TribitsAddAdvancedTest)
858 #
859 # and it will have the same effect.
860 #
861 function(tribits_add_advanced_test TEST_NAME_IN)
862
863 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
864 message("\nPACKAGE_ADD_ADVANCED_TEST: ${TEST_NAME_IN}\n")
865 endif()
866
867 tribits_set_tribits_package_name()
868
869 global_set(TRIBITS_SET_TEST_PROPERTIES_INPUT)
870 global_set(MESSAGE_WRAPPER_INPUT)
871
872 # Set the full TEST_NAME
873 set(TEST_NAME ${PACKAGE_NAME}_${TEST_NAME_IN})
874
875 #
876 # A) Parse the overall arguments and figure out how many tests
877 # commands we will have
878 #
879
880 # Set maximum number of TEST_<idx> blocks
881 tribits_add_advanced_test_max_num_test_cmnd_idx_compute()
882 set(MAX_NUM_TEST_CMND_IDX ${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_CMND_IDX})
883
884 set(TEST_IDX_LIST "")
885 foreach( TEST_CMND_IDX RANGE ${MAX_NUM_TEST_CMND_IDX})
886 list( APPEND TEST_IDX_LIST TEST_${TEST_CMND_IDX} )
887 endforeach()
888
889 set(optionsList FAIL_FAST RUN_SERIAL SKIP_CLEAN_OVERALL_WORKING_DIRECTORY)
890
891 set(oneValueKeywordsList DISABLED)
892
893 set(multiValueKeywordsList
894 ${TEST_IDX_LIST} OVERALL_WORKING_DIRECTORY
895 LIST_SEPARATOR
896 OVERALL_NUM_MPI_PROCS OVERALL_NUM_TOTAL_CORES_USED
897 CATEGORIES COMM HOST XHOST HOSTTYPE XHOSTTYPE EXCLUDE_IF_NOT_TRUE
898 FINAL_PASS_REGULAR_EXPRESSION FINAL_FAIL_REGULAR_EXPRESSION
899 TIMEOUT ENVIRONMENT KEYWORDS
900 ADDED_TEST_NAME_OUT
901 )
902
903 cmake_parse_arguments(
904 PARSE_ARGV 1 # NOTE: One named argument to skip over
905 PARSE # prefix
906 "${optionsList}"
907 "${oneValueKeywordsList}"
908 "${multiValueKeywordsList}"
909 )
910
911 tribits_check_for_unparsed_arguments()
912 tribits_add_advanced_test_check_exceed_max_num_test_blocks()
913
914 if(PARSE_ADDED_TEST_NAME_OUT)
915 set(${PARSE_ADDED_TEST_NAME_OUT} "" PARENT_SCOPE )
916 endif()
917
918 # Set the name of the cmake -P script.
919 string(REPLACE "/" "__" NORMALIZED_TEST_NAME "${TEST_NAME}")
920 set(TEST_SCRIPT_FILE_NAME "${NORMALIZED_TEST_NAME}.cmake")
921
922 # Set the relative overall working directory and abs working directory
923 if (PARSE_OVERALL_WORKING_DIRECTORY)
924 if ("${PARSE_OVERALL_WORKING_DIRECTORY}" STREQUAL "TEST_NAME")
925 set(PARSE_OVERALL_WORKING_DIRECTORY ${NORMALIZED_TEST_NAME})
926 endif()
927 # Test will run in created working subdir
928 set(ABS_OVERALL_WORKING_DIRECTORY
929 ${CMAKE_CURRENT_BINARY_DIR}/${PARSE_OVERALL_WORKING_DIRECTORY})
930 else()
931 # Test runs in current binary directory (not a good idea!)
932 set(ABS_OVERALL_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
933 endif()
934
935 #
936 # B) Add or don't add tests based on a number of criteria
937 #
938
939 set(ADD_THE_TEST FALSE)
940 tribits_add_test_process_enable_tests(ADD_THE_TEST)
941 if (NOT ADD_THE_TEST)
942 return()
943 endif()
944
945 tribits_add_test_process_skip_ctest_add_test(ADD_THE_TEST)
946 if (NOT ADD_THE_TEST)
947 return()
948 endif()
949
950 set(ADD_THE_TEST FALSE)
951 tribits_add_test_process_categories(ADD_THE_TEST)
952 if (NOT ADD_THE_TEST)
953 return()
954 endif()
955
956 set(ADD_THE_TEST FALSE)
957 tribits_add_test_process_host_hosttype(ADD_THE_TEST)
958 if (NOT ADD_THE_TEST)
959 return()
960 endif()
961
962 tribits_add_test_query_disable(DISABLE_THIS_TEST ${TEST_NAME})
963 if (DISABLE_THIS_TEST)
964 return()
965 endif()
966
967 tribits_set_run_serial(${TEST_NAME} "${PARSE_RUN_SERIAL}"
968 SET_RUN_SERIAL)
969
970 tribits_set_disabled_and_msg(${TEST_NAME} "${PARSE_DISABLED}"
971 SET_DISABLED_AND_MSG) # Adds the test but sets DISABLED test prop!
972
973 #
974 # C) Determine if we will add the serial or MPI tests based on input COMM
975 # and TPL_ENABLE_MPI
976 #
977
978 tribits_process_comm_args(ADD_SERIAL_TEST ADD_MPI_TEST ${PARSE_COMM})
979 if (NOT ADD_SERIAL_TEST AND NOT ADD_MPI_TEST)
980 return()
981 endif()
982
983 #
984 # D) Build the test script
985 #
986
987 set(ADD_THE_TEST TRUE)
988
989 set(TEST_SCRIPT_STR "")
990
991 string(APPEND TEST_SCRIPT_STR
992 "\n"
993 "#\n"
994 "# This is a CMake script and must be run as \"cmake -P <SCRIPT_NAME>\"\n"
995 "#\n"
996 "# NOTE: To see what commands this script runs, run it as:\n"
997 "#\n"
998 "# $ cmake -DSHOW_COMMANDS_ONLY=ON -P <SCRIPT_NAME>\n"
999 "#\n"
1000 "\n"
1001 "#\n"
1002 "# Variables\n"
1003 "#\n"
1004 "\n"
1005 "set( TEST_NAME ${TEST_NAME} )\n"
1006 "set( LIST_SEPARATOR \"${PARSE_LIST_SEPARATOR}\" )\n"
1007 )
1008
1009 # Loop through each test case
1010
1011 set(NUM_CMNDS 0)
1012 set(TEST_EXE_LIST "")
1013
1014 if (PARSE_OVERALL_NUM_MPI_PROCS AND PARSE_OVERALL_NUM_TOTAL_CORES_USED)
1015 if (PARSE_OVERALL_NUM_MPI_PROCS GREATER PARSE_OVERALL_NUM_TOTAL_CORES_USED)
1016 message_wrapper(FATAL_ERROR
1017 "ERROR: ${TEST_NAME}: OVERALL_NUM_MPI_PROCS='${PARSE_OVERALL_NUM_MPI_PROCS}' > OVERALL_NUM_TOTAL_CORES_USED='${PARSE_OVERALL_NUM_TOTAL_CORES_USED}' not allowed!")
1018 return()
1019 endif()
1020 endif()
1021
1022 # ToDo: Assert that OVERALL_NUM_TOTAL_CORES_USED >= OVERALL_NUM_MPI_PROCS
1023
1024 if (PARSE_OVERALL_NUM_MPI_PROCS)
1025 set(MAX_NUM_MPI_PROCS_USED ${PARSE_OVERALL_NUM_MPI_PROCS})
1026 set(MAX_NUM_PROCESSORS_USED ${PARSE_OVERALL_NUM_MPI_PROCS})
1027 else()
1028 set(MAX_NUM_MPI_PROCS_USED ${PARSE_OVERALL_NUM_MPI_PROCS})
1029 set(MAX_NUM_PROCESSORS_USED 1)
1030 endif()
1031
1032 set(HAS_AT_LEAST_ONE_EXEC FALSE)
1033
1034 foreach( TEST_CMND_IDX RANGE ${MAX_NUM_TEST_CMND_IDX} )
1035
1036 if (NOT PARSE_TEST_${TEST_CMND_IDX} )
1037 break()
1038 endif()
1039
1040 if (NOT ADD_THE_TEST)
1041 break()
1042 endif()
1043
1044 math( EXPR NUM_CMNDS ${NUM_CMNDS}+1 )
1045
1046 # Parse the test command case
1047
1048 # Search to see if we are copying files or not for this TEST_<IDX> block ...
1049
1050 set(PARSE_COPY_FILES_TO_TEST_DIR)
1051 set(COPY_FILES_TO_TEST_DIR_IDX FALSE)
1052 foreach(PARSE_TEST_IDX_ARGS ${PARSE_TEST_${TEST_CMND_IDX}})
1053 if (PARSE_TEST_IDX_ARGS STREQUAL "COPY_FILES_TO_TEST_DIR")
1054 set(COPY_FILES_TO_TEST_DIR_IDX TRUE)
1055 endif()
1056 endforeach()
1057
1058 if (COPY_FILES_TO_TEST_DIR_IDX)
1059
1060 # Do a special parse just for TEST_<IDX> blocks of type
1061 # COPY_FILES_TO_TEST_DIR
1062
1063 cmake_parse_arguments(
1064 #prefix
1065 PARSE
1066 #options
1067 ""
1068 # one_value_keywords
1069 ""
1070 # multi_value_keywords
1071 "COPY_FILES_TO_TEST_DIR;SOURCE_DIR;DEST_DIR"
1072 # Arguments to parse
1073 ${PARSE_TEST_${TEST_CMND_IDX}}
1074 )
1075 tribits_check_for_unparsed_arguments()
1076 tribits_assert_parse_arg_one_or_more_values(PARSE COPY_FILES_TO_TEST_DIR)
1077 tribits_assert_parse_arg_zero_or_one_value(PARSE SOURCE_DIR)
1078 tribits_assert_parse_arg_zero_or_one_value(PARSE DEST_DIR)
1079
1080 set(PARSE_EXEC "")
1081 set(PARSE_CMND "")
1082
1083 else()
1084
1085 # Parse TEST_<IDX> block args for types EXEC and CMND
1086
1087 set(testBlockOptionsList NOEXEPREFIX NOEXESUFFIX NO_ECHO_OUTPUT PASS_ANY
1088 STANDARD_PASS_OUTPUT ALWAYS_FAIL_ON_NONZERO_RETURN ALWAYS_FAIL_ON_ZERO_RETURN
1089 WILL_FAIL ADD_DIR_TO_NAME SKIP_CLEAN_WORKING_DIRECTORY
1090 )
1091
1092 set(testBlockMultiValueKeywordsList EXEC CMND ARGS DIRECTORY MESSAGE
1093 WORKING_DIRECTORY OUTPUT_FILE NUM_MPI_PROCS NUM_TOTAL_CORES_USED
1094 PASS_REGULAR_EXPRESSION_ALL FAIL_REGULAR_EXPRESSION PASS_REGULAR_EXPRESSION
1095 )
1096
1097 cmake_parse_arguments(
1098 PARSE #prefix
1099 "${testBlockOptionsList}"
1100 "" # one_value_keywords
1101 "${testBlockMultiValueKeywordsList}"
1102 ${PARSE_TEST_${TEST_CMND_IDX}}
1103 )
1104
1105 tribits_check_for_unparsed_arguments(PARSE) # ToDo: Use a different prefix!
1106
1107 endif()
1108
1109 #
1110 # Set up the command that will be written into the cmake -P *.cmake file
1111 #
1112
1113 set(ARGS_STR "${PARSE_ARGS}")
1114
1115 if (PARSE_EXEC)
1116
1117 #
1118 # This is an EXEC test block
1119 #
1120
1121 set(HAS_AT_LEAST_ONE_EXEC TRUE)
1122
1123 list( LENGTH PARSE_EXEC PARSE_EXEC_LEN )
1124 if (NOT PARSE_EXEC_LEN EQUAL 1)
1125 message(SEND_ERROR "Error, TEST_${TEST_CMND_IDX} EXEC = '${PARSE_EXEC}'"
1126 " must be a single name. To add arguments use ARGS <arg1> <arg2> ...." )
1127 endif()
1128
1129 tribits_add_test_get_exe_binary_name( "${PARSE_EXEC}"
1130 ${PARSE_NOEXEPREFIX} ${PARSE_NOEXESUFFIX}
1131 ${PARSE_ADD_DIR_TO_NAME} EXE_BINARY_NAME )
1132
1133 tribits_add_test_adjust_directory( ${EXE_BINARY_NAME} "${PARSE_DIRECTORY}"
1134 EXECUTABLE_PATH)
1135
1136 if (PARSE_NUM_MPI_PROCS)
1137 set(NUM_MPI_PROC_VAR_NAME "NUM_MPI_PROCS")
1138 else()
1139 set(PARSE_NUM_MPI_PROCS ${PARSE_OVERALL_NUM_MPI_PROCS})
1140 set(NUM_MPI_PROC_VAR_NAME "OVERALL_NUM_MPI_PROCS")
1141 endif()
1142
1143 tribits_add_test_get_num_procs_used("${PARSE_NUM_MPI_PROCS}"
1144 "${NUM_MPI_PROC_VAR_NAME}" NUM_PROCS_USED NUM_PROCS_USED_NAME)
1145
1146 if (NUM_PROCS_USED LESS 0)
1147 set(ADD_THE_TEST FALSE)
1148 elseif (NUM_PROCS_USED GREATER MAX_NUM_MPI_PROCS_USED)
1149 set(MAX_NUM_MPI_PROCS_USED ${NUM_PROCS_USED})
1150 endif()
1151
1152 if (PARSE_NUM_TOTAL_CORES_USED)
1153 set(NUM_TOTAL_CORES_USED ${PARSE_NUM_TOTAL_CORES_USED})
1154 set(NUM_TOTAL_CORES_USED_NAME "NUM_TOTAL_CORES_USED")
1155 else()
1156 set(NUM_TOTAL_CORES_USED ${PARSE_OVERALL_NUM_TOTAL_CORES_USED})
1157 set(NUM_TOTAL_CORES_USED_NAME "OVERALL_NUM_TOTAL_CORES_USED")
1158 endif()
1159
1160 tribits_add_test_get_num_total_cores_used("${TEST_NAME}${MPI_NAME_POSTFIX}"
1161 "${NUM_TOTAL_CORES_USED}" "${NUM_TOTAL_CORES_USED_NAME}"
1162 "${NUM_PROCS_USED}" "${NUM_PROCS_USED_NAME}"
1163 NUM_TOTAL_CORES_USED SKIP_TEST)
1164 if (SKIP_TEST)
1165 set(ADD_THE_TEST FALSE)
1166 endif()
1167
1168 if (NUM_TOTAL_CORES_USED GREATER MAX_NUM_PROCESSORS_USED)
1169 set(MAX_NUM_PROCESSORS_USED ${NUM_TOTAL_CORES_USED})
1170 endif()
1171
1172 if(ADD_THE_TEST)
1173 list(APPEND TEST_EXE_LIST ${EXECUTABLE_PATH})
1174 endif()
1175
1176 tribits_add_test_get_test_cmnd_array( TEST_CMND_ARRAY
1177 "${EXECUTABLE_PATH}" "${NUM_PROCS_USED}" ${ARGS_STR} )
1178
1179 elseif (PARSE_CMND)
1180
1181 #
1182 # This is a COMMAND test block
1183 #
1184
1185 list( LENGTH PARSE_CMND PARSE_CMND_LEN )
1186 if (NOT PARSE_CMND_LEN EQUAL 1)
1187 message_wrapper(SEND_ERROR "Error, TEST_${TEST_CMND_IDX} CMND = '${PARSE_CMND}'"
1188 " must be a single command. To add arguments use ARGS <arg1> <arg2> ...." )
1189 endif()
1190
1191 if (PARSE_NUM_TOTAL_CORES_USED)
1192 set(NUM_TOTAL_CORES_USED ${PARSE_NUM_TOTAL_CORES_USED})
1193 set(NUM_TOTAL_CORES_USED_NAME "NUM_TOTAL_CORES_USED")
1194 else()
1195 set(NUM_TOTAL_CORES_USED ${PARSE_OVERALL_NUM_TOTAL_CORES_USED})
1196 set(NUM_TOTAL_CORES_USED_NAME "OVERALL_NUM_TOTAL_CORES_USED")
1197 endif()
1198
1199 tribits_add_test_get_num_total_cores_used("${TEST_NAME}${MPI_NAME_POSTFIX}"
1200 "${NUM_TOTAL_CORES_USED}" "${NUM_TOTAL_CORES_USED_NAME}"
1201 "1" "DUMMY_NUM_MPI_PROCS" # Never be printed
1202 NUM_TOTAL_CORES_USED SKIP_TEST)
1203 if (SKIP_TEST)
1204 set(ADD_THE_TEST FALSE)
1205 endif()
1206
1207 if (NUM_TOTAL_CORES_USED GREATER MAX_NUM_PROCESSORS_USED)
1208 set(MAX_NUM_PROCESSORS_USED ${NUM_TOTAL_CORES_USED})
1209 endif()
1210
1211 if(ADD_THE_TEST)
1212 if (NOT TRIBITS_ADD_TEST_ADD_TEST_UNITTEST)
1213 find_program(CMND_PATH ${PARSE_CMND})
1214 else()
1215 set(CMND_PATH ${PARSE_CMND})
1216 endif()
1217 list(APPEND TEST_EXE_LIST ${CMND_PATH})
1218 endif()
1219
1220 set( TEST_CMND_ARRAY ${PARSE_CMND} ${ARGS_STR} )
1221
1222 elseif (PARSE_COPY_FILES_TO_TEST_DIR)
1223
1224 #
1225 # This is a COPY_FLES_TO_TEST_DIR block
1226 #
1227
1228 # FILES_TO_COPY_COMMA_SEP
1229 set(FILES_TO_COPY_COMMA_SEP "${PARSE_COPY_FILES_TO_TEST_DIR}")
1230 string(REPLACE ";" "," FILES_TO_COPY_COMMA_SEP
1231 "${FILES_TO_COPY_COMMA_SEP}" )
1232 # NOTE: Above, we have to replace ';' with ',' or the lower commands
1233 # string(APPEND ) will replace ';' with ''. This is *not* what we
1234 # want. In DriveAdvancedTest.cmake, we will replace the ',' with ';'
1235 # again :-)
1236
1237 # SOURCE_DIR
1238 if (PARSE_SOURCE_DIR)
1239 if (IS_ABSOLUTE "${PARSE_SOURCE_DIR}")
1240 set(COPY_FILES_TO_TEST_DIR_SOURCE_DIR
1241 "${PARSE_SOURCE_DIR}")
1242 else()
1243 set(COPY_FILES_TO_TEST_DIR_SOURCE_DIR
1244 "${CMAKE_CURRENT_SOURCE_DIR}/${PARSE_SOURCE_DIR}")
1245 endif()
1246 else()
1247 set(COPY_FILES_TO_TEST_DIR_SOURCE_DIR
1248 "${CMAKE_CURRENT_SOURCE_DIR}")
1249 endif()
1250
1251 # DEST_DIR
1252 if (PARSE_DEST_DIR)
1253 if (IS_ABSOLUTE "${PARSE_DEST_DIR}")
1254 set(COPY_FILES_TO_TEST_DIR_DEST_DIR
1255 "${PARSE_DEST_DIR}")
1256 else()
1257 set(COPY_FILES_TO_TEST_DIR_DEST_DIR
1258 "${ABS_OVERALL_WORKING_DIRECTORY}/${PARSE_DEST_DIR}")
1259 endif()
1260 else()
1261 set(COPY_FILES_TO_TEST_DIR_DEST_DIR
1262 "${ABS_OVERALL_WORKING_DIRECTORY}")
1263 endif()
1264
1265 else()
1266
1267 message( FATAL_ERROR
1268 "Must have EXEC, CMND, or COPY_FILES_TO_TEST_DIR for TEST_${TEST_CMND_IDX}" )
1269
1270 endif()
1271
1272 #
1273 # Write parts for this TEST_<IDX> block to TEST_SCRIPT_STR
1274 #
1275
1276 if (PARSE_COPY_FILES_TO_TEST_DIR)
1277
1278 # Write the vars for COPY_FILES_TO_TEST_DIR
1279
1280 string(APPEND TEST_SCRIPT_STR
1281 "\n"
1282 "set( TEST_${TEST_CMND_IDX}_COPY_FILES_TO_TEST_DIR"
1283 " \"${FILES_TO_COPY_COMMA_SEP}\")\n"
1284 )
1285 if (TRIBITS_ADD_ADVANCED_TEST_UNITTEST)
1286 global_set(TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_${TEST_CMND_IDX}
1287 "${TEST_CMND_STR}" )
1288 endif()
1289
1290 string(APPEND TEST_SCRIPT_STR
1291 "\n"
1292 "set( TEST_${TEST_CMND_IDX}_SOURCE_DIR"
1293 " \"${COPY_FILES_TO_TEST_DIR_SOURCE_DIR}\")\n"
1294 )
1295
1296 string(APPEND TEST_SCRIPT_STR
1297 "\n"
1298 "set( TEST_${TEST_CMND_IDX}_DEST_DIR"
1299 " \"${COPY_FILES_TO_TEST_DIR_DEST_DIR}\")\n"
1300 )
1301
1302 else()
1303
1304 # Write the command to be run for EXEC and CMND blocks ...
1305
1306 tribits_join_exec_process_set_args( TEST_CMND_STR "${TEST_CMND_ARRAY}" )
1307
1308 string(APPEND TEST_SCRIPT_STR
1309 "\n"
1310 "set( TEST_${TEST_CMND_IDX}_CMND ${TEST_CMND_STR} )\n"
1311 )
1312 if (TRIBITS_ADD_ADVANCED_TEST_UNITTEST)
1313 global_set(TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_${TEST_CMND_IDX}
1314 "${TEST_CMND_STR}" )
1315 endif()
1316
1317 endif()
1318
1319 if (PARSE_MESSAGE)
1320 string(APPEND TEST_SCRIPT_STR
1321 "\n"
1322 "set( TEST_${TEST_CMND_IDX}_MESSAGE \"${PARSE_MESSAGE}\" )\n"
1323 )
1324 endif()
1325
1326 if (PARSE_WORKING_DIRECTORY)
1327 if ("${PARSE_WORKING_DIRECTORY}" STREQUAL "TEST_NAME")
1328 set(PARSE_WORKING_DIRECTORY ${TEST_NAME})
1329 endif()
1330 string(APPEND TEST_SCRIPT_STR
1331 "\n"
1332 "set( TEST_${TEST_CMND_IDX}_WORKING_DIRECTORY \"${PARSE_WORKING_DIRECTORY}\" )\n"
1333 )
1334 string(APPEND TEST_SCRIPT_STR
1335 "\n"
1336 "set( TEST_${TEST_CMND_IDX}_SKIP_CLEAN_WORKING_DIRECTORY ${PARSE_SKIP_CLEAN_WORKING_DIRECTORY} )\n"
1337 )
1338 endif()
1339
1340 if (PARSE_OUTPUT_FILE)
1341 string(APPEND TEST_SCRIPT_STR
1342 "\n"
1343 "set( TEST_${TEST_CMND_IDX}_OUTPUT_FILE \"${PARSE_OUTPUT_FILE}\" )\n"
1344 )
1345 endif()
1346
1347 if (PARSE_NO_ECHO_OUTPUT)
1348 string(APPEND TEST_SCRIPT_STR
1349 "\n"
1350 "set( TEST_${TEST_CMND_IDX}_NO_ECHO_OUTPUT \"${PARSE_NO_ECHO_OUTPUT}\" )\n"
1351 )
1352 endif()
1353
1354 # Set up pass/fail
1355
1356 if (PARSE_PASS_ANY)
1357 string(APPEND TEST_SCRIPT_STR
1358 "\n"
1359 "set( TEST_${TEST_CMND_IDX}_PASS_ANY TRUE )\n"
1360 )
1361 elseif (PARSE_STANDARD_PASS_OUTPUT)
1362 string(APPEND TEST_SCRIPT_STR
1363 "\n"
1364 "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION \"End Result: TEST PASSED\" )\n"
1365 )
1366 elseif (PARSE_PASS_REGULAR_EXPRESSION)
1367 string(APPEND TEST_SCRIPT_STR
1368 "\n"
1369 "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION \"${PARSE_PASS_REGULAR_EXPRESSION}\" )\n"
1370 )
1371 elseif (PARSE_PASS_REGULAR_EXPRESSION_ALL)
1372 string(APPEND TEST_SCRIPT_STR
1373 "\n"
1374 "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION_ALL "
1375 )
1376 foreach(REGEX_STR ${PARSE_PASS_REGULAR_EXPRESSION_ALL})
1377 string(APPEND TEST_SCRIPT_STR
1378 "\"${REGEX_STR}\" "
1379 )
1380 endforeach()
1381 string(APPEND TEST_SCRIPT_STR
1382 ")\n"
1383 )
1384 endif()
1385
1386 if (PARSE_FAIL_REGULAR_EXPRESSION)
1387 string(APPEND TEST_SCRIPT_STR
1388 "\n"
1389 "set( TEST_${TEST_CMND_IDX}_FAIL_REGULAR_EXPRESSION \"${PARSE_FAIL_REGULAR_EXPRESSION}\" )\n"
1390 )
1391 endif()
1392
1393 if (PARSE_ALWAYS_FAIL_ON_NONZERO_RETURN)
1394 string(APPEND TEST_SCRIPT_STR
1395 "\n"
1396 "set( TEST_${TEST_CMND_IDX}_ALWAYS_FAIL_ON_NONZERO_RETURN TRUE )\n"
1397 )
1398 endif()
1399
1400 if (PARSE_ALWAYS_FAIL_ON_ZERO_RETURN)
1401 string(APPEND TEST_SCRIPT_STR
1402 "\n"
1403 "set( TEST_${TEST_CMND_IDX}_ALWAYS_FAIL_ON_ZERO_RETURN TRUE )\n"
1404 )
1405 endif()
1406
1407 if (PARSE_WILL_FAIL)
1408 string(APPEND TEST_SCRIPT_STR
1409 "\n"
1410 "set( TEST_${TEST_CMND_IDX}_WILL_FAIL TRUE )\n"
1411 )
1412 endif()
1413
1414 endforeach()
1415
1416 # ToDo: Verify that TEST_${MAX_NUM_TEST_CMND_IDX}+1 does *not* exist!
1417
1418 #
1419 # F) Set the CTest test to run the new script
1420 #
1421
1422 if (ADD_THE_TEST)
1423
1424 #
1425 # F.1) Call add_test() and set the test properties
1426 #
1427
1428 set(TEST_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SCRIPT_FILE_NAME}")
1429
1430 if(NOT TRIBITS_ADD_TEST_ADD_TEST_UNITTEST)
1431 # Tell CTest to run our script for this test. Pass the test-type
1432 # configuration name to the script in the TEST_CONFIG variable.
1433 add_test( NAME ${TEST_NAME}
1434 COMMAND ${CMAKE_COMMAND} "-DTEST_CONFIG=\${CTEST_CONFIGURATION_TYPE}"
1435 -P "${TEST_SCRIPT_FILE}")
1436 endif()
1437
1438 if(PARSE_ADDED_TEST_NAME_OUT)
1439 set(${PARSE_ADDED_TEST_NAME_OUT} ${TEST_NAME} PARENT_SCOPE )
1440 endif()
1441
1442 list(REMOVE_DUPLICATES TEST_EXE_LIST)
1443 tribits_set_test_property(${TEST_NAME} PROPERTY REQUIRED_FILES ${TEST_EXE_LIST})
1444
1445 if(SET_RUN_SERIAL)
1446 tribits_set_tests_properties(${TEST_NAME} PROPERTIES RUN_SERIAL ON)
1447 endif()
1448
1449 tribits_private_add_test_add_label_and_keywords(${TEST_NAME})
1450
1451 #This if clause will set the number of PROCESSORS to reserve during testing
1452 #to the number requested for the test.
1453 if(MAX_NUM_PROCESSORS_USED)
1454 tribits_set_tests_properties(${TEST_NAME} PROPERTIES
1455 PROCESSORS "${MAX_NUM_PROCESSORS_USED}")
1456 endif()
1457
1458 tribits_private_add_test_add_environment_and_resource(${TEST_NAME}
1459 ${MAX_NUM_PROCESSORS_USED})
1460
1461 if (SET_DISABLED_AND_MSG)
1462 tribits_set_tests_properties(${TEST_NAME} PROPERTIES DISABLED ON)
1463 endif()
1464
1465 if (PARSE_FINAL_PASS_REGULAR_EXPRESSION)
1466 tribits_set_tests_properties( ${TEST_NAME} PROPERTIES
1467 PASS_REGULAR_EXPRESSION "${PARSE_FINAL_PASS_REGULAR_EXPRESSION}" )
1468 elseif (PARSE_FINAL_FAIL_REGULAR_EXPRESSION)
1469 tribits_set_tests_properties( ${TEST_NAME} PROPERTIES
1470 FAIL_REGULAR_EXPRESSION "${PARSE_FINAL_FAIL_REGULAR_EXPRESSION}" )
1471 else()
1472 tribits_set_tests_properties( ${TEST_NAME} PROPERTIES
1473 PASS_REGULAR_EXPRESSION
1474 "OVERALL FINAL RESULT: TEST PASSED .${TEST_NAME}." )
1475 endif()
1476
1477 tribits_private_add_test_set_timeout(${TEST_NAME} TIMEOUT_USED)
1478
1479 tribits_private_add_test_set_environment(${TEST_NAME})
1480
1481 if (TPL_ENABLE_MPI AND HAS_AT_LEAST_ONE_EXEC)
1482 set(MAX_NUM_MPI_PROCS_USED_TO_PRINT ${MAX_NUM_MPI_PROCS_USED})
1483 else()
1484 set(MAX_NUM_MPI_PROCS_USED_TO_PRINT "")
1485 endif()
1486
1487 tribits_private_add_test_print_added(${TEST_NAME}
1488 "${PARSE_CATEGORIES}" "${MAX_NUM_MPI_PROCS_USED_TO_PRINT}"
1489 "${MAX_NUM_PROCESSORS_USED}" "${TIMEOUT_USED}"
1490 "${SET_RUN_SERIAL}" "${SET_DISABLED_AND_MSG}")
1491
1492 #
1493 # F.2) Write the cmake -P script
1494 #
1495
1496 set(coreUtilsDir "${tribitsAddAdvancedTestModuleDir}/../utils")
1497 cmake_path(NORMAL_PATH coreUtilsDir)
1498 string(APPEND TEST_SCRIPT_STR
1499 "\n"
1500 "set(PROJECT_NAME ${PROJECT_NAME})\n"
1501 "\n"
1502 "set(${PROJECT_NAME}_TRIBITS_DIR ${${PROJECT_NAME}_TRIBITS_DIR})\n"
1503 "\n"
1504 "set(TEST_NAME ${TEST_NAME})\n"
1505 "\n"
1506 "set(NUM_CMNDS ${NUM_CMNDS})\n"
1507 "\n"
1508 "set(OVERALL_WORKING_DIRECTORY \"${PARSE_OVERALL_WORKING_DIRECTORY}\")\n"
1509 "\n"
1510 "set(SKIP_CLEAN_OVERALL_WORKING_DIRECTORY \"${PARSE_SKIP_CLEAN_OVERALL_WORKING_DIRECTORY}\")\n"
1511 "\n"
1512 "set(FAIL_FAST ${PARSE_FAIL_FAST})\n"
1513 "\n"
1514 "set(SHOW_START_END_DATE_TIME ${${PROJECT_NAME}_SHOW_TEST_START_END_DATE_TIME})\n"
1515 "\n"
1516 "set(SHOW_MACHINE_LOAD ${${PROJECT_NAME}_SHOW_MACHINE_LOAD_IN_TEST})\n"
1517 "\n"
1518 "set(CATEGORIES ${PARSE_CATEGORIES})\n"
1519 "\n"
1520 "set(PROCESSORS ${MAX_NUM_PROCESSORS_USED})\n"
1521 "\n"
1522 "set(TIMEOUT ${TIMEOUT_USED})\n"
1523 "\n"
1524 "#\n"
1525 "# Test invocation\n"
1526 "#\n"
1527 "\n"
1528 "include(\"${coreUtilsDir}/DriveAdvancedTest.cmake\")\n"
1529 "\n"
1530 "drive_advanced_test()\n"
1531 )
1532
1533 if (TRIBITS_ADD_ADVANCED_TEST_UNITTEST)
1534 global_set(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS ${NUM_CMNDS})
1535 # NOTE: This var only gets set if the advanced test gets added after
1536 # applying all of the various logic. Therefore, unit tests should only
1537 # check this variable for being empty to determine that the test was not
1538 # added.
1539 endif()
1540
1541 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
1542 print_var(TEST_SCRIPT_STR)
1543 endif()
1544
1545 # Write the script file
1546
1547 if (NOT TRIBITS_ADD_ADVANCED_TEST_SKIP_SCRIPT)
1548
1549 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
1550 message("\nWriting file \"${TEST_SCRIPT_FILE}\" ...")
1551 endif()
1552
1553 file( WRITE "${TEST_SCRIPT_FILE}"
1554 "${TEST_SCRIPT_STR}" )
1555
1556 endif()
1557
1558
1559 else()
1560
1561 global_set(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")
1562
1563 endif()
1564
1565 endfunction()