Tests: run tests from install path

Blender can only be run correctly from the install path since it requires Python
scripts, dynamic libraries and other files to be present. By default the install
path is the same as the build path, so it works anyway. But on the buildbot it
isn't. There was a workaround but it failed on Windows and macOS.

Now tests run from the install path. Detecting that path for ctest is more
complicated than I would like, but I couldn't find a better solution.

Ref T69541.
This commit is contained in:
Brecht Van Lommel 2019-09-07 14:03:39 +02:00
parent 708e81bdfa
commit 2028302f44
Notes: blender-bot 2023-02-14 08:29:54 +01:00
Referenced by issue #69541,  Run automated tests on buildbot
2 changed files with 33 additions and 30 deletions

View File

@ -22,15 +22,6 @@ import buildbot_utils
import os
import sys
def get_ctest_environment(builder):
info = buildbot_utils.VersionInfo(builder)
blender_version_dir = os.path.join(builder.install_dir, info.version)
env = os.environ.copy()
env['BLENDER_SYSTEM_SCRIPTS'] = os.path.join(blender_version_dir, 'scripts')
env['BLENDER_SYSTEM_DATAFILES'] = os.path.join(blender_version_dir, 'datafiles')
return env
def get_ctest_arguments(builder):
args = ['--output-on-failure']
if builder.platform == 'win':
@ -41,8 +32,7 @@ def test(builder):
os.chdir(builder.build_dir)
command = builder.command_prefix + ['ctest'] + get_ctest_arguments(builder)
ctest_env = get_ctest_environment(builder)
buildbot_utils.call(command, env=ctest_env, exit_on_error=False)
buildbot_utils.call(command, exit_on_error=False)
if __name__ == "__main__":
builder = buildbot_utils.create_builder_from_arguments()

View File

@ -32,24 +32,39 @@ file(MAKE_DIRECTORY ${TEST_OUT_DIR}/io_tests)
#~ message(FATAL_ERROR "CMake test directory not found!")
#~ endif()
# all calls to blender use this
# --env-system-scripts allows to run without the install target, but does
# not work for all configurations.
if(WITH_CYCLES OR (APPLE AND (${CMAKE_GENERATOR} MATCHES "Xcode")))
set(TEST_BLENDER_EXE_PARAMS --background -noaudio --factory-startup)
# Blender arguments for tests.
set(TEST_BLENDER_EXE_PARAMS --background -noaudio --factory-startup)
# Always run tests from install path, so all required scripts and libraries
# are available and we are testing the actual installation layout.
#
# Getting the install path of the executable is somewhat involved, as there are
# no direct CMake generator expressions to get the install paths of executables.
if(GENERATOR_IS_MULTI_CONFIG)
string(REPLACE "\${BUILD_TYPE}" "$<CONFIG>" TEST_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
else()
set(TEST_BLENDER_EXE_PARAMS --background -noaudio --factory-startup --env-system-scripts ${CMAKE_SOURCE_DIR}/release/scripts)
string(REPLACE "\${BUILD_TYPE}" "" TEST_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
endif()
# for testing with valgrind prefix: valgrind --track-origins=yes --error-limit=no
# set(TEST_BLENDER_EXE_BARE ${TEST_BLENDER_EXE})
# set(TEST_BLENDER_EXE ${TEST_BLENDER_EXE} ${TEST_BLENDER_EXE_PARAMS} )
if(MSVC)
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender.exe)
set(TEST_PYTHON_EXE "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>")
elseif(APPLE)
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/Blender.app/Contents/MacOS/Blender)
set(TEST_PYTHON_EXE)
else()
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender)
set(TEST_PYTHON_EXE)
endif()
# For testing with Valgrind
# set(TEST_BLENDER_EXE valgrind --track-origins=yes --error-limit=no ${TEST_BLENDER_EXE})
# Run Blender command with parameters.
function(add_blender_test testname)
add_test(
NAME ${testname}
COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS} ${ARGN}
COMMAND "${TEST_BLENDER_EXE}" ${TEST_BLENDER_EXE_PARAMS} ${ARGN}
)
# Don't fail tests on leaks since these often happen in external libraries
@ -62,9 +77,7 @@ function(add_python_test testname testscript)
if(MSVC)
add_test(
NAME ${testname}
COMMAND
"$<TARGET_FILE_DIR:blender>/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>"
${testscript} ${ARGN}
COMMAND ${TEST_PYTHON_EXE} ${testscript} ${ARGN}
)
else()
add_test(
@ -528,7 +541,7 @@ if(WITH_CYCLES OR WITH_OPENGL_RENDER_TESTS)
add_python_test(
cycles_${render_test}
${CMAKE_CURRENT_LIST_DIR}/cycles_render_tests.py
-blender "$<TARGET_FILE:blender>"
-blender "${TEST_BLENDER_EXE}"
-testdir "${TEST_SRC_DIR}/render/${render_test}"
-idiff "${OPENIMAGEIO_IDIFF}"
-outdir "${TEST_OUT_DIR}/cycles"
@ -541,7 +554,7 @@ if(WITH_CYCLES OR WITH_OPENGL_RENDER_TESTS)
add_python_test(
eevee_${render_test}_test
${CMAKE_CURRENT_LIST_DIR}/eevee_render_tests.py
-blender "$<TARGET_FILE:blender>"
-blender "${TEST_BLENDER_EXE}"
-testdir "${TEST_SRC_DIR}/render/${render_test}"
-idiff "${OPENIMAGEIO_IDIFF}"
-outdir "${TEST_OUT_DIR}/eevee"
@ -552,7 +565,7 @@ if(WITH_CYCLES OR WITH_OPENGL_RENDER_TESTS)
add_python_test(
workbench_${render_test}_test
${CMAKE_CURRENT_LIST_DIR}/workbench_render_tests.py
-blender "$<TARGET_FILE:blender>"
-blender "${TEST_BLENDER_EXE}"
-testdir "${TEST_SRC_DIR}/render/${render_test}"
-idiff "${OPENIMAGEIO_IDIFF}"
-outdir "${TEST_OUT_DIR}/workbench"
@ -579,7 +592,7 @@ if(WITH_OPENGL_DRAW_TESTS)
add_python_test(
opengl_draw_${child}
${CMAKE_CURRENT_LIST_DIR}/opengl_draw_tests.py
-blender "$<TARGET_FILE:blender>"
-blender "${TEST_BLENDER_EXE}"
-testdir "${child_path}"
-idiff "${OPENIMAGEIO_IDIFF}"
-outdir "${TEST_OUT_DIR}/opengl_draw"
@ -602,7 +615,7 @@ if(WITH_ALEMBIC)
add_python_test(
alembic_tests
${CMAKE_CURRENT_LIST_DIR}/alembic_tests.py
--blender "$<TARGET_FILE:blender>"
--blender "${TEST_BLENDER_EXE}"
--testdir "${TEST_SRC_DIR}/alembic"
--alembic-root "${ALEMBIC_ROOT_DIR}"
)
@ -619,7 +632,7 @@ if(WITH_CODEC_FFMPEG)
add_python_test(
ffmpeg
${CMAKE_CURRENT_LIST_DIR}/ffmpeg_tests.py
--blender "$<TARGET_FILE:blender>"
--blender "${TEST_BLENDER_EXE}"
--testdir "${TEST_SRC_DIR}/ffmpeg"
)
endif()