Commit 44c7f0b8 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Cleaning python testing macros.

When attemping to add tests using vtk_add_test_python_mpi(), issues were
spotted in the vtkTestingMacros code. This commit addresses those
issues.

VTK_PYTHON_EXE is no longer globally defined in CMakeLists.txt.
vtk_add_test_python_mpi() and vtk_add_test_python() assume a good
default is none is set (this allows for applications like ParaView to
use these macros while overriding the executable to run).

We use generator expressions to point to the default
vtkpython/pvtkpython executables which works better when MPI
(mpiexec/mpirun) is being used to launch the test executable.
parent 695b4817
......@@ -370,9 +370,14 @@ endfunction()
# The 'vtk_test_prefix' variable may be set to create separate tests from a
# single test name (e.g., running with different arguments), but should be
# used only when required.
#
# Before calling this function, you can define VTK_PYTHON_EXE to point the
# executable (or generator expression for the executable) to run for the test.
# If VTK_PYTHON_EXE is not defined, `vtkpython` is assumed i.e.
# ($<TARGET_FILE:vtkpython>)
function(vtk_add_test_python)
if(NOT VTK_PYTHON_EXE)
message(FATAL_ERROR "VTK_PYTHON_EXE not set")
if (NOT DEFINED VTK_PYTHON_EXE)
set(VTK_PYTHON_EXE "\$<TARGET_FILE:vtkpython>")
endif()
set(python_options
NO_DATA
......@@ -447,6 +452,10 @@ function(vtk_add_test_python)
endforeach()
endfunction()
# Before calling this function, you can define VTK_PYTHON_EXE to point the
# executable (or generator expression for the executable) to run for the test.
# If VTK_PYTHON_EXE is not defined, `vtkpython` is assumed i.e.
# ($<TARGET_FILE:pvtkpython>)
function(vtk_add_test_python_mpi)
set(_vtk_test_python_suffix "-MPI")
......@@ -460,7 +469,9 @@ function(vtk_add_test_python_mpi)
${VTK_MPI_PRENUMPROC_FLAGS} ${VTK_MPI_NUMPROC_FLAG} ${numprocs}
${VTK_MPI_PREFLAGS})
set (VTK_PYTHON_EXE "\\$<TARGET_FILE:pvtkpython>")
if (NOT DEFINED VTK_PYTHON_EXE)
set(VTK_PYTHON_EXE "\$<TARGET_FILE:pvtkpython>")
endif()
vtk_add_test_python(${ARGN})
endfunction()
......
......@@ -476,7 +476,6 @@ endif()
if(VTK_WRAP_PYTHON)
set(VTK_WRAP_PYTHON_EXE vtkWrapPython)
set(VTK_WRAP_PYTHON_INIT_EXE vtkWrapPythonInit)
set(VTK_PYTHON_EXE vtkpython)
# Force the WrappingPythonCore module to on if wrapping is on
set(Module_vtkWrappingPythonCore ON CACHE BOOL "Core Python wrapping library"
FORCE)
......
# Macro to convert tcl tests to python and add those tests.
# Assumes VTK_WRAP_PYTHON is on and PYTHON_EXECUTABLE is defined.
MACRO (CONVERT_TCL_TEST_TO_PY tcl_tests kit_name)
IF(NOT "${${tcl_tests}}" STREQUAL "")
SET (input_dir ${VTK_SOURCE_DIR}/${kit_name}/Testing/Tcl)
SET (output_dir ${VTK_BINARY_DIR}/${kit_name}/Testing/Python)
SET (target_name ${kit_name}PythonTests)
SET(CMD ${PYTHON_EXECUTABLE})
SET (CONVERTED_TESTS)
SET (CONVERTER_SCRIPT "${VTK_BINARY_DIR}/Utilities/vtkTclTest2Py/vtkTclToPyConvertor.py")
SET (TESTS_TO_CONVERT)
SET (CONVERSIONLIST)
FOREACH(test ${${tcl_tests}})
SET(input "${input_dir}/${test}.tcl")
SET(output "${output_dir}/${test}.py")
SET (CONVERTED_TESTS ${CONVERTED_TESTS} "${output}")
SET (CONVERSIONLIST ${CONVERSIONLIST} "${input};${output}")
SET (TESTS_TO_CONVERT ${TESTS_TO_CONVERT} "${input}")
#Add the py test.
IF (${VTK_DATA_ROOT})
ADD_TEST(${test}Python ${VTK_PYTHON_EXE}
${VTK_BINARY_DIR}/Utilities/vtkTclTest2Py/rtImageTest.py
${output}
-D ${VTK_DATA_ROOT}
-T ${VTK_TEST_OUTPUT_DIR}
-V Baseline/${kit_name}/${test}.png
-A "${VTK_BINARY_DIR}/Utilities/vtkTclTest2Py"
-A "${VTK_LIBRARY_DIR}"
)
ELSE ()
ADD_TEST(${test}Python ${VTK_PYTHON_EXE}
${VTK_BINARY_DIR}/Utilities/vtkTclTest2Py/rtImageTest.py
${output}
-T ${VTK_TEST_OUTPUT_DIR}
-V Baseline/${kit_name}/${test}.png
-A "${VTK_BINARY_DIR}/Utilities/vtkTclTest2Py"
-A "${VTK_LIBRARY_DIR}"
)
ENDIF ()
ENDFOREACH()
CONFIGURE_FILE(
${VTK_SOURCE_DIR}/Utilities/vtkTclTest2Py/vtkTestsToConvert.in
${output_dir}/vtkTestsToConvert
@ONLY
)
ADD_CUSTOM_COMMAND(
OUTPUT "${output_dir}/conversion_complete"
COMMAND ${CMD}
ARGS ${CONVERTER_SCRIPT}
-l "${output_dir}/vtkTestsToConvert"
-t "${output_dir}/conversion_complete"
-A "${VTK_BINARY_DIR}/Utilities/vtkTclTest2Py"
-A "${VTK_BINARY_DIR}/Wrapping/Python"
-A "${VTK_LIBRARY_DIR}"
DEPENDS ${TESTS_TO_CONVERT}
${output_dir}/vtkTestsToConvert
${CONVERTER_SCRIPT}
COMMENT "Converting Tcl test"
)
ADD_CUSTOM_TARGET(${target_name} ALL DEPENDS
"${output_dir}/conversion_complete")
ADD_DEPENDENCIES(${target_name} vtktcltest2py_pyc)
# TODO: add explicit dependency between the vtk{Name}Kit.cmake files and the
# the test conversion.
ENDIF()
ENDMACRO ()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment