vtkModuleTesting.cmake 21 KB

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