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