vtkModuleTesting.cmake
Go to the documentation of this file.
1 #[==[.md
2 # `vtkModuleTesting`
3 
4 VTK uses the [ExternalData][] CMake module to handle the data management for
5 its test suite. Test data is only downloaded when a test which requires it is
6 enabled and it is cached so that every build does not need to redownload the
7 same data.
8 
9 To facilitate this workflow, there are a number of CMake functions available in
10 order to indicate that test data is required.
11 
12 [ExternalData]: TODO
13 #]==]
14 
15 include(ExternalData)
16 get_filename_component(_vtkModuleTesting_dir "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
17 
18 #[==[.md
19 ## Loading data
20 
21 Data may be downloaded manually using this function:
22 
23 ~~~
24 vtk_module_test_data(<PATHSPEC>...)
25 ~~~
26 
27 This will download data inside of the input data directory for the modules
28 being built at that time (see the `TEST_INPUT_DATA_DIRECTORY` argument of
30 
31 For supported `PATHSPEC` syntax, see the
32 [associated documentation][ExternalData pathspecs] in `ExternalData`. These
33 arguments are already wrapped in the `DATA{}` syntax and are assumed to be
34 relative paths from the input data directory.
35 
36 [ExternalData pathspecs]: TODO
37 #]==]
39  set(data_args)
40  foreach (arg IN LISTS ARGN)
41  if (IS_ABSOLUTE "${arg}")
42  list(APPEND data_args
43  "DATA{${arg}}")
44  else ()
45  list(APPEND data_args
46  "DATA{${_vtk_build_TEST_INPUT_DATA_DIRECTORY}/${arg}}")
47  endif ()
48  endforeach ()
49 
50  ExternalData_Expand_Arguments("${_vtk_build_TEST_DATA_TARGET}" _ ${data_args})
51 endfunction ()
52 
53 #[==[.md
54 ## Creating test executables
55 
56 This function creates an executable from the list of sources passed to it. It
57 is automatically linked to the module the tests are intended for as well as any
58 declared test dependencies of the module.
59 
60 ~~~
61 vtk_module_test_executable(<NAME> <SOURCE>...)
62 ~~~
63 
64 This function is not usually used directly, but instead through the other
65 convenience functions.
66 #]==]
67 function (vtk_module_test_executable name)
68  add_executable("${name}" ${ARGN})
69  get_property(test_depends GLOBAL
70  PROPERTY "_vtk_module_${_vtk_build_test}_test_depends")
71  get_property(test_optional_depends GLOBAL
72  PROPERTY "_vtk_module_${_vtk_build_test}_test_optional_depends")
73  set(optional_depends_flags)
74  foreach (test_optional_depend IN LISTS test_optional_depends)
75  if (TARGET "${test_optional_depend}")
76  list(APPEND test_depends
77  "${test_optional_depend}")
78  set(test_optional_depend_flag "1")
79  else ()
80  set(test_optional_depend_flag "0")
81  endif ()
82  string(REPLACE "::" "_" safe_test_optional_depend "${test_optional_depend}")
83  list(APPEND optional_depends_flags
84  "VTK_MODULE_ENABLE_${safe_test_optional_depend}=${test_optional_depend_flag}")
85  endforeach ()
86 
87  target_link_libraries("${name}"
88  PRIVATE
89  "${_vtk_build_test}"
90  ${test_depends})
91  target_compile_definitions("${name}"
92  PRIVATE
93  ${optional_depends_flags})
94 
95  vtk_module_autoinit(
96  TARGETS "${name}"
97  MODULES "${_vtk_build_test}"
98  ${test_depends})
99 endfunction ()
100 
101 #[==[.md
102 ## Test name parsing
103 
104 Test names default to using the basename of the filename which contains the
105 test. Two tests may share the same file by prefixing with a custom name for the
106 test and a comma.
107 
108 The two parsed syntaxes are:
109 
110  - `CustomTestName,TestFile`
111  - `TestFile`
112 
113 Note that `TestFile` should already have had its extension stripped (usually
114 done by `_vtk_test_parse_args`).
115 
116 In general, the name of a test will be `<EXENAME>-<TESTNAME>`, however, by
117 setting `vtk_test_prefix`, the test name will instead be
118 `<EXENAME>-<PREFIX><TESTNAME>`.
119 #]==]
120 
121 #[==[.md INTERNAL
122 This function parses the name from a testspec. The calling scope has
123 `test_name` and `test_file` variables set in it.
124 
125 ~~~
126 _vtk_test_parse_name(<TESTSPEC>)
127 ~~~
128 #]==]
129 function (_vtk_test_parse_name name)
130  if (name AND name MATCHES "^([^,]*),(.*)$")
131  set(test_name "${CMAKE_MATCH_1}" PARENT_SCOPE)
132  set(test_file "${CMAKE_MATCH_2}" PARENT_SCOPE)
133  else ()
134  set(test_name "${name}" PARENT_SCOPE)
135  set(test_file "${name}" PARENT_SCOPE)
136  endif ()
137 endfunction ()
138 
139 #[==[.md
140 ## Test function arguments
141 
142 Each test is specified using one of the two following syntaxes
143 
144  - `<NAME>.<SOURCE_EXT>`
145  - `<NAME>.<SOURCE_EXT>,<OPTIONS>`
146 
147 Where `NAME` is a valid test name. If present, the specified `OPTIONS` are only
148 for the associated test. The expected extension is specified by the associated
149 test function.
150 #]==]
151 
152 #[==[.md INTERNAL
153 Given a list of valid "options", this function will parse out a the following
154 variables:
155 
156  - `args`: Unrecognized arguments. These should be interpreted as arguments
157  that should be passed on the command line to all tests in this parse group.
158  - `options`: Options specified globally (for all tests in this group).
159  - `names`: A list containing all named tests. These should be parsed by
160  `_vtk_test_parse_name`.
161  - `_<NAME>_options`: Options specific to a certain test.
162 
163 ~~~
164 _vtk_test_parse_args(<OPTIONS> <SOURCE_EXT> <ARG>...)
165 ~~~
166 
167 In order to be recognized as a source file, the `SOURCE_EXT` must be used.
168 Without it, all non-option arguments are placed into `args`. Each test is
169 parsed out matching these:
170 #]==]
171 function (_vtk_test_parse_args options source_ext)
172  set(global_options)
173  set(names)
174  set(args)
175 
176  foreach (arg IN LISTS ARGN)
177  set(handled 0)
178  foreach (option IN LISTS options)
179  if (arg STREQUAL option)
180  list(APPEND global_options "${option}")
181  set(handled 1)
182  break ()
183  endif ()
184  endforeach ()
185  if (handled)
186  # Do nothing.
187  elseif (source_ext AND arg MATCHES "^([^.]*)\\.${source_ext},?(.*)$")
188  set(name "${CMAKE_MATCH_1}")
189  string(REPLACE "," ";" "_${name}_options" "${CMAKE_MATCH_2}")
190  list(APPEND names "${name}")
191  else ()
192  list(APPEND args "${arg}")
193  endif ()
194  endforeach ()
195 
196  foreach (name IN LISTS names)
197  set("_${name}_options" "${_${name}_options}"
198  PARENT_SCOPE)
199  endforeach ()
200  set(options "${global_options}"
201  PARENT_SCOPE)
202  set(names "${names}"
203  PARENT_SCOPE)
204  set(args "${args}"
205  PARENT_SCOPE)
206 endfunction ()
207 
208 #[==[.md INTERNAL
209 For handling global option settings, this function sets variables in the
210 calling scoped named `<PREFIX><OPTION>` to either `0` or `1` if the option is
211 present in the remaining argument list.
212 
213 ~~~
214 _vtk_test_set_options(<OPTIONS> <PREFIX> <ARG>...)
215 ~~~
216 
217 Additionally, a non-`0` default for a given option may be specified by a
218 variable with the same name as the option and specifying a prefix for the
219 output variables.
220 #]==]
221 function (_vtk_test_set_options options prefix)
222  foreach (option IN LISTS options)
223  set(default 0)
224  if (prefix)
225  set(default "${${option}}")
226  endif ()
227  set("${prefix}${option}" "${default}"
228  PARENT_SCOPE)
229  endforeach ()
230  foreach (option IN LISTS ARGN)
231  set("${prefix}${option}" 1
232  PARENT_SCOPE)
233  endforeach ()
234 endfunction ()
235 
236 # If set, use the maximum number of processors for tests. Otherwise, just use 1
237 # processor by default.
238 set(VTK_MPI_NUMPROCS "2" CACHE STRING
239  "Number of processors available to run parallel tests.")
240 # Hide the variable if we don't have `MPIEXEC_EXECUTABLE` anyways.
241 if (MPIEXEC_EXECUTABLE)
242  set(_vtk_mpi_max_numprocs_type STRING)
243 else ()
244  set(_vtk_mpi_max_numprocs_type INTERNAL)
245 endif ()
246 set_property(CACHE VTK_MPI_NUMPROCS
247  PROPERTY
248  TYPE "${_vtk_mpi_max_numprocs_type}")
249 
250 #[==[.md
251 ## C++ tests
252 
253 This function declares C++ tests. Source files are required to use the `cxx`
254 extension.
255 
256 ~~~
257 vtk_add_test_cxx(<EXENAME> <VARNAME> <ARG>...)
258 ~~~
259 
260 Each argument should be either an option, a test specification, or it is passed
261 as flags to all tests declared in the group. The list of tests is set in the
262 `<VARNAME>` variable in the calling scope.
263 
264 Options:
265 
266  - `NO_DATA`: The test does not need to know the test input data directory. If
267  it does, it is passed on the command line via the `-D` flag.
268  - `NO_VALID`: The test does not have a valid baseline image. If it does, the
269  baseline is assumed to be in `../Data/Baseline/<NAME>.png` relative to the
270  current source directory. If alternate baseline images are required,
271  `<NAME>` may be suffixed by `_1`, `_2`, etc. The valid image is passed via
272  the `-V` flag.
273  - `NO_OUTPUT`: The test does not need to write out any data to the
274  filesystem. If it does, a directory which may be written to is passed via
275  the `-T` flag.
276 
277 Additional flags may be passed to tests using the `${_vtk_build_test}_ARGS`
278 variable or the `<NAME>_ARGS` variable.
279 #]==]
280 function (vtk_add_test_cxx exename _tests)
281  set(cxx_options
282  NO_DATA
283  NO_VALID
284  NO_OUTPUT)
285  _vtk_test_parse_args("${cxx_options}" "cxx" ${ARGN})
286  _vtk_test_set_options("${cxx_options}" "" ${options})
287 
288  set(_vtk_fail_regex "(\n|^)ERROR: " "instance(s)? still around")
289 
290  foreach (name IN LISTS names)
291  _vtk_test_set_options("${cxx_options}" "local_" ${_${name}_options})
292  _vtk_test_parse_name("${name}")
293 
294  set(_D "")
295  if (NOT local_NO_DATA)
296  set(_D -D "${_vtk_build_TEST_OUTPUT_DATA_DIRECTORY}")
297  endif ()
298 
299  set(_T "")
300  if (NOT local_NO_OUTPUT)
301  set(_T -T "${_vtk_build_TEST_OUTPUT_DIRECTORY}")
302  endif ()
303 
304  set(_V "")
305  if (NOT local_NO_VALID)
306  set(_V -V "DATA{${CMAKE_CURRENT_SOURCE_DIR}/../Data/Baseline/${test_name}.png,:}")
307  endif ()
308 
309  if (VTK_USE_MPI AND
310  VTK_SERIAL_TESTS_USE_MPIEXEC)
311  set(_vtk_test_cxx_pre_args
312  "${MPIEXEC_EXECUTABLE}"
313  "${MPIEXEC_NUMPROC_FLAG}" "1"
314  ${MPIEXEC_PREFLAGS})
315  endif()
316 
317  ExternalData_add_test("${_vtk_build_TEST_DATA_TARGET}"
318  NAME "${_vtk_build_test}Cxx-${vtk_test_prefix}${test_name}"
319  COMMAND "${_vtk_test_cxx_pre_args}" "$<TARGET_FILE:${exename}>"
320  "${test_file}"
321  ${args}
322  ${${_vtk_build_test}_ARGS}
323  ${${name}_ARGS}
324  ${_D} ${_T} ${_V})
325  set_tests_properties("${_vtk_build_test}Cxx-${vtk_test_prefix}${test_name}"
326  PROPERTIES
327  LABELS "${_vtk_build_test_labels}"
328  FAIL_REGULAR_EXPRESSION "${_vtk_fail_regex}"
329  # This must match VTK_SKIP_RETURN_CODE in vtkTestingObjectFactory.h
330  SKIP_RETURN_CODE 125
331  )
332 
333  list(APPEND ${_tests} "${test_file}")
334  endforeach ()
335 
336  set("${_tests}" ${${_tests}} PARENT_SCOPE)
337 endfunction ()
338 
339 #[==[.md
340 ### MPI tests
341 
342 This function declares C++ tests which should be run under an MPI environment.
343 Source files are required to use the `cxx` extension.
344 
345 ~~~
346 vtk_add_test_mpi(<EXENAME> <VARNAME> <ARG>...)
347 ~~~
348 
349 Each argument should be either an option, a test specification, or it is passed
350 as flags to all tests declared in the group. The list of tests is set in the
351 `<VARNAME>` variable in the calling scope.
352 
353 Options:
354 
355  - `TESTING_DATA`
356  - `NO_VALID`: The test does not have a valid baseline image. If it does, the
357  baseline is assumed to be in `../Data/Baseline/<NAME>.png` relative to the
358  current source directory. If alternate baseline images are required,
359  `<NAME>` may be suffixed by `_1`, `_2`, etc. The valid image is passed via
360  the `-V` flag.
361 
362 Each test is run using the number of processors specified by the following
363 variables (using the first one which is set):
364 
365  - `<NAME>_NUMPROCS`
366  - `<EXENAME>_NUMPROCS`
367  - `VTK_MPI_NUMPROCS` (defaults to `2`)
368 
369 Additional flags may be passed to tests using the `${_vtk_build_test}_ARGS`
370 variable or the `<NAME>_ARGS` variable.
371 #]==]
372 function (vtk_add_test_mpi exename _tests)
373  set(mpi_options
374  TESTING_DATA
375  NO_VALID
376  )
377  _vtk_test_parse_args("${mpi_options}" "cxx" ${ARGN})
378  _vtk_test_set_options("${mpi_options}" "" ${options})
379 
380  set(_vtk_fail_regex "(\n|^)ERROR: " "instance(s)? still around")
381 
382  set(default_numprocs ${VTK_MPI_NUMPROCS})
383  if (${exename}_NUMPROCS)
384  set(default_numprocs ${${exename}_NUMPROCS})
385  endif ()
386 
387  foreach (name IN LISTS names)
388  _vtk_test_set_options("${mpi_options}" "local_" ${_${name}_options})
389  _vtk_test_parse_name(${name})
390 
391  set(_D "")
392  set(_T "")
393  set(_V "")
394  if (local_TESTING_DATA)
395  set(_D -D "${_vtk_build_TEST_OUTPUT_DATA_DIRECTORY}")
396  set(_T -T "${_vtk_build_TEST_OUTPUT_DIRECTORY}")
397  set(_V "")
398  if (NOT local_NO_VALID)
399  set(_V -V "DATA{${CMAKE_CURRENT_SOURCE_DIR}/../Data/Baseline/${name}.png,:}")
400  endif ()
401  endif ()
402 
403  set(numprocs ${default_numprocs})
404  if (${name}_NUMPROCS)
405  set(numprocs "${${name}_NUMPROCS}")
406  endif ()
407 
408  ExternalData_add_test("${_vtk_build_TEST_DATA_TARGET}"
409  NAME "${_vtk_build_test}Cxx-MPI-${vtk_test_prefix}${test_name}"
410  COMMAND "${MPIEXEC_EXECUTABLE}"
411  "${MPIEXEC_NUMPROC_FLAG}" "${numprocs}"
412  ${MPIEXEC_PREFLAGS}
413  "$<TARGET_FILE:${exename}>"
414  "${test_file}"
415  ${_D} ${_T} ${_V}
416  ${args}
417  ${${_vtk_build_test}_ARGS}
418  ${${name}_ARGS}
419  ${MPIEXEC_POSTFLAGS})
420  set_tests_properties("${_vtk_build_test}Cxx-MPI-${vtk_test_prefix}${test_name}"
421  PROPERTIES
422  LABELS "${_vtk_build_test_labels}"
423  PROCESSORS "${numprocs}"
424  FAIL_REGULAR_EXPRESSION "${_vtk_fail_regex}"
425  # This must match VTK_SKIP_RETURN_CODE in vtkTestingObjectFactory.h"
426  SKIP_RETURN_CODE 125
427  )
428  set_property(TEST "${_vtk_build_test}Cxx-MPI-${vtk_test_prefix}${test_name}" APPEND
429  PROPERTY
430  REQUIRED_FILES "$<TARGET_FILE:${exename}>")
431  list(APPEND ${_tests} "${test_file}")
432  endforeach ()
433 
434  set(${_tests} ${${_tests}} PARENT_SCOPE)
435 endfunction ()
436 
437 #[==[.md
438 ### C++ test executable
439 
440 ~~~
441 vtk_test_cxx_executable(<EXENAME> <VARNAME> [RENDERING_FACTORY] [<SRC>...])
442 ~~~
443 
444 Creates an executable named `EXENAME` which contains the tests listed in the
445 variable named in the `VARNAME` argument. The `EXENAME` must match the
446 `EXENAME` passed to the test declarations when building the list of tests.
447 
448 If `RENDERING_FACTORY` is provided, VTK's rendering factories are initialized
449 during the test.
450 
451 Any additional arguments are added as additional sources for the executable.
452 #]==]
453 function (vtk_test_cxx_executable exename _tests)
454  set(exe_options
455  RENDERING_FACTORY)
456  _vtk_test_parse_args("${exe_options}" "" ${ARGN})
457  _vtk_test_set_options("${exe_options}" "" ${options})
458 
459  if (NOT ${_tests})
460  # No tests -> no need for an executable.
461  return()
462  endif ()
463 
464  if (RENDERING_FACTORY)
465  include("${_vtkModuleTesting_dir}/vtkTestingRenderingDriver.cmake")
466  set(test_driver vtkTestingObjectFactory.h)
467  else ()
468  include("${_vtkModuleTesting_dir}/vtkTestingDriver.cmake")
469  set(test_driver vtkTestDriver.h)
470  endif ()
471 
472  set(extra_sources ${args})
473 
474  create_test_sourcelist(test_sources "${exename}.cxx" ${${_tests}}
475  EXTRA_INCLUDE "${test_driver}")
476 
477  if (_vtk_build_test)
478  vtk_module_test_executable("${exename}" ${test_sources} ${extra_sources})
479  else ()
480  message(FATAL_ERROR "_vtk_build_test is not set!")
481  endif ()
482 endfunction ()
483 
484 #[==[.md INTERNAL
485 MPI executables used to have their own test executable function. This is no
486 longer necessary and is deprecated. Instead, `vtk_test_cxx_executable` should
487 be used instead.
488 #]==]
489 function (vtk_test_mpi_executable exename _tests)
490  message(DEPRECATION
491  "The `vtk_test_mpi_executable` function is deprecated; use "
492  "`vtk_test_cxx_executable` instead.")
493  vtk_test_cxx_executable("${exename}" "${_tests}" ${ARGN})
494 endfunction ()
495 
496 #[==[.md
497 ## Python tests
498 
499 This function declares Python tests. Test files are required to use the `py`
500 extension.
501 
502 ~~~
503 vtk_add_test_python(<EXENAME> <VARNAME> <ARG>...)
504 ~~~
505 #]==]
506 
507 #[==[.md INTERNAL
508 If the `_vtk_testing_python_exe` variable is not set, the `vtkpython` binary is
509 used by default. Additional arguments may be passed in this variable as well.
510 #]==]
511 
512 #[==[.md
513 Options:
514 
515  - `NO_DATA`
516  - `NO_VALID`
517  - `NO_OUTPUT`
518  - `NO_RT`
519  - `JUST_VALID`
520 
521 Each argument should be either an option, a test specification, or it is passed
522 as flags to all tests declared in the group. The list of tests is set in the
523 `<VARNAME>` variable in the calling scope.
524 
525 Options:
526 
527  - `NO_DATA`: The test does not need to know the test input data directory. If
528  it does, it is passed on the command line via the `-D` flag.
529  - `NO_OUTPUT`: The test does not need to write out any data to the
530  filesystem. If it does, a directory which may be written to is passed via
531  the `-T` flag.
532  - `NO_VALID`: The test does not have a valid baseline image. If it does, the
533  baseline is assumed to be in `../Data/Baseline/<NAME>.png` relative to the
534  current source directory. If alternate baseline images are required,
535  `<NAME>` may be suffixed by `_1`, `_2`, etc. The valid image is passed via
536  the `-V` flag.
537  - `NO_RT`: If `NO_RT` is specified, `-B` is passed instead of `-V`, only
538  providing a baseline dir, assuming `NO_VALID` is not specified.
539  - `DIRECT_DATA` : If `DIRECT_DATA` is specified, the baseline path will be provided
540  as is, without the use of ExternalData_add_test.
541  - `JUST_VALID`: Only applies when both `NO_VALID` and `NO_RT` are not
542  present. If it is not specified, `-A` is passed with path to the directory
543  of the `vtkTclTest2Py` Python package and the test is run via the
544  `rtImageTest.py` script. Note that this currently only works when building
545  against a VTK build tree; the VTK install tree does not include this script
546  or its associated Python package.
547 
548 Additional flags may be passed to tests using the `${_vtk_build_test}_ARGS`
549 variable or the `<NAME>_ARGS` variable.
550 
551 Note that the `vtkTclTest2Py` support will eventually be removed. It is a
552 legacy of the conversion of many tests from Tcl to Python.
553 #]==]
554 function (vtk_add_test_python)
555  if (NOT _vtk_testing_python_exe)
556  set(_vtk_testing_python_exe "$<TARGET_FILE:VTK::vtkpython>")
557  endif ()
558  set(python_options
559  NO_DATA
560  NO_VALID
561  NO_OUTPUT
562  NO_RT
563  DIRECT_DATA
564  JUST_VALID
565  )
566  _vtk_test_parse_args("${python_options}" "py" ${ARGN})
567  _vtk_test_set_options("${python_options}" "" ${options})
568 
569  set(_vtk_fail_regex "(\n|^)ERROR: " "instance(s)? still around")
570 
571  foreach (name IN LISTS names)
572  _vtk_test_set_options("${python_options}" "local_" ${_${name}_options})
573  _vtk_test_parse_name(${name})
574 
575  set(_D "")
576  if (NOT local_NO_DATA)
577  set(_D -D "${_vtk_build_TEST_OUTPUT_DATA_DIRECTORY}")
578  endif ()
579 
580  set(rtImageTest "")
581  set(_B "")
582  set(_V "")
583  set(_A "")
584  if (NOT local_NO_VALID)
585  if (local_NO_RT)
586  if (local_DIRECT_DATA)
587  set(_B -B "${CMAKE_CURRENT_SOURCE_DIR}/Data/Baseline/")
588  else ()
589  set(_B -B "DATA{${CMAKE_CURRENT_SOURCE_DIR}/../Data/Baseline/,REGEX:${test_name}(-.*)?(_[0-9]+)?.png}")
590  endif()
591  else ()
592  if (local_DIRECT_DATA)
593  set(_V -V "${CMAKE_CURRENT_SOURCE_DIR}/Data/Baseline/${test_name}.png")
594  else ()
595  set(_V -V "DATA{${CMAKE_CURRENT_SOURCE_DIR}/../Data/Baseline/${test_name}.png,:}")
596  endif()
597  if (NOT local_JUST_VALID)
598  # TODO: This should be fixed to also work from an installed VTK.
599  set(rtImageTest "${VTK_SOURCE_DIR}/Utilities/vtkTclTest2Py/rtImageTest.py")
600  set(_A -A "${VTK_SOURCE_DIR}/Utilities/vtkTclTest2Py")
601  endif ()
602  endif ()
603  endif ()
604 
605  set(_T "")
606  if (NOT local_NO_OUTPUT)
607  set(_T -T "${_vtk_build_TEST_OUTPUT_DIRECTORY}")
608  endif ()
609 
610  if (NOT _vtk_build_TEST_FILE_DIRECTORY)
611  set(_vtk_build_TEST_FILE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
612  endif()
613 
614  if (VTK_USE_MPI AND
615  VTK_SERIAL_TESTS_USE_MPIEXEC AND
616  NOT DEFINED _vtk_test_python_pre_args)
617  set(_vtk_test_python_pre_args
618  "${MPIEXEC_EXECUTABLE}"
619  "${MPIEXEC_NUMPROC_FLAG}" "1"
620  ${MPIEXEC_PREFLAGS})
621  endif()
622  set(testArgs NAME "${_vtk_build_test}Python${_vtk_test_python_suffix}-${vtk_test_prefix}${test_name}"
623  COMMAND ${_vtk_test_python_pre_args}
624  "${_vtk_testing_python_exe}" ${_vtk_test_python_args} --enable-bt
625  ${rtImageTest}
626  "${_vtk_build_TEST_FILE_DIRECTORY}/${test_file}.py"
627  ${args}
628  ${${_vtk_build_test}_ARGS}
629  ${${name}_ARGS}
630  ${_D} ${_B} ${_T} ${_V} ${_A})
631 
632  if (local_DIRECT_DATA)
633  add_test(${testArgs})
634  else ()
635  ExternalData_add_test("${_vtk_build_TEST_DATA_TARGET}" ${testArgs})
636  endif()
637 
638  set_tests_properties("${_vtk_build_test}Python${_vtk_test_python_suffix}-${vtk_test_prefix}${test_name}"
639  PROPERTIES
640  LABELS "${_vtk_build_test_labels}"
641  FAIL_REGULAR_EXPRESSION "${_vtk_fail_regex}"
642  # This must match the skip() function in vtk/test/Testing.py"
643  SKIP_RETURN_CODE 125
644  )
645 
646  if (numprocs)
647  set_tests_properties("${_vtk_build_test}Python${_vtk_test_python_suffix}-${vtk_test_prefix}${test_name}"
648  PROPERTIES
649  PROCESSORS "${numprocs}")
650  endif ()
651  endforeach ()
652 endfunction ()
653 
654 #[==[.md
655 ### MPI tests
656 
657 A small wrapper around `vtk_add_test_python` which adds support for running
658 MPI-aware tests written in Python.
659 
660 The `$<module library name>_NUMPROCS` variable may be used to use a non-default
661 number of processors for a test.
662 
663 This forces running with the `pvtkpython` executable.
664 #]==]
665 function (vtk_add_test_python_mpi)
666  set(_vtk_test_python_suffix "-MPI")
667 
668  set(numprocs "${VTK_MPI_NUMPROCS}")
669  _vtk_module_get_module_property("${_vtk_build_test}"
670  PROPERTY "library_name"
671  VARIABLE _vtk_test_python_library_name)
672  if (${_vtk_test_python_library_name}_NUMPROCS)
673  set(numprocs "${${_vtk_test_python_library_name}_NUMPROCS}")
674  endif ()
675 
676  set(_vtk_test_python_pre_args
677  "${MPIEXEC_EXECUTABLE}"
678  "${MPIEXEC_NUMPROC_FLAG}" "${numprocs}"
679  ${MPIEXEC_PREFLAGS})
680 
681  if (NOT _vtk_testing_python_exe)
682  set(_vtk_testing_python_exe "$<TARGET_FILE:VTK::pvtkpython>")
683  endif ()
684  vtk_add_test_python(${ARGN})
685 endfunction ()
data
order
function vtk_module_build()
Build modules and kits.
function vtk_test_cxx_executable(exename, _tests)
.md C++ test executable
name
time
function vtk_module_test_data()
.md vtkModuleTesting
enabled
documentation