Skip to content

Commit

Permalink
[Pxr] Make building/installing tests optional.
Browse files Browse the repository at this point in the history
(Internal change: 1669641)
  • Loading branch information
superfunc authored and pixar-oss committed Nov 7, 2016
1 parent d8c2147 commit eaad278
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 156 deletions.
1 change: 1 addition & 0 deletions cmake/defaults/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#
option(PXR_STRICT_BUILD_MODE "Turn on additional warnings. Enforce all warnings as errors." OFF)
option(PXR_VALIDATE_GENERATED_CODE "Validate script generated code" OFF)
option(PXR_BUILD_TESTS "Build tests" ON)
option(PXR_BUILD_IMAGING "Build imaging components" ON)
option(PXR_BUILD_USD_IMAGING "Build USD imaging components" ON)
option(PXR_BUILD_KATANA_PLUGIN "Build usd katana plugin" OFF)
Expand Down
6 changes: 4 additions & 2 deletions cmake/defaults/ProjectDefaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

# Enable CTest
enable_testing()
if (PXR_BUILD_TESTS)
# Enable CTest
enable_testing()
endif()
320 changes: 166 additions & 154 deletions cmake/macros/Public.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -687,198 +687,210 @@ function(pxr_setup_python)
endfunction() # pxr_setup_python

function (pxr_create_test_module MODULE_NAME)
cmake_parse_arguments(tm "" "INSTALL_PREFIX;SOURCE_DIR" "" ${ARGN})
if (PXR_BUILD_TESTS)
cmake_parse_arguments(tm "" "INSTALL_PREFIX;SOURCE_DIR" "" ${ARGN})

if (NOT tm_SOURCE_DIR)
set(tm_SOURCE_DIR testenv)
endif()

# Look specifically for an __init__.py and a plugInfo.json prefixed by the
# module name. These will be installed without the module prefix.
set(initPyFile ${tm_SOURCE_DIR}/${MODULE_NAME}__init__.py)
set(plugInfoFile ${tm_SOURCE_DIR}/${MODULE_NAME}_plugInfo.json)
if (NOT tm_SOURCE_DIR)
set(tm_SOURCE_DIR testenv)
endif()

if (EXISTS ${initPyFile})
install(
FILES
${initPyFile}
RENAME
__init__.py
DESTINATION
tests/${tm_INSTALL_PREFIX}/lib/python/${MODULE_NAME}
)
endif()
# Look specifically for an __init__.py and a plugInfo.json prefixed by the
# module name. These will be installed without the module prefix.
set(initPyFile ${tm_SOURCE_DIR}/${MODULE_NAME}__init__.py)
set(plugInfoFile ${tm_SOURCE_DIR}/${MODULE_NAME}_plugInfo.json)

if (EXISTS ${initPyFile})
install(
FILES
${initPyFile}
RENAME
__init__.py
DESTINATION
tests/${tm_INSTALL_PREFIX}/lib/python/${MODULE_NAME}
)
endif()

if (EXISTS ${plugInfoFile})
install(
FILES
${plugInfoFile}
RENAME
plugInfo.json
DESTINATION
tests/${tm_INSTALL_PREFIX}/lib/python/${MODULE_NAME}
)
if (EXISTS ${plugInfoFile})
install(
FILES
${plugInfoFile}
RENAME
plugInfo.json
DESTINATION
tests/${tm_INSTALL_PREFIX}/lib/python/${MODULE_NAME}
)
endif()
endif()
endfunction() # pxr_create_test_module

function(pxr_build_test_shared_lib LIBRARY_NAME)
cmake_parse_arguments(bt
"" ""
"LIBRARIES;CPPFILES"
${ARGN}
)

add_library(${LIBRARY_NAME}
SHARED
${bt_CPPFILES}
if (PXR_BUILD_TESTS)
cmake_parse_arguments(bt
"" ""
"LIBRARIES;CPPFILES"
${ARGN}
)

add_library(${LIBRARY_NAME}
SHARED
${bt_CPPFILES}
)
target_link_libraries(${LIBRARY_NAME}
${bt_LIBRARIES}
)
set_target_properties(${LIBRARY_NAME}
PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
FOLDER "${PXR_PREFIX}/tests/lib"
)
target_link_libraries(${LIBRARY_NAME}
${bt_LIBRARIES}
)
set_target_properties(${LIBRARY_NAME}
PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
FOLDER "${PXR_PREFIX}/tests/lib"
)

# We always want this test to build after the package it's under, even if
# it doesn't link directly. This ensures that this test is able to include
# headers from its parent package.
add_dependencies(${LIBRARY_NAME} ${PXR_PACKAGE})
# We always want this test to build after the package it's under, even if
# it doesn't link directly. This ensures that this test is able to include
# headers from its parent package.
add_dependencies(${LIBRARY_NAME} ${PXR_PACKAGE})

# Test libraries can include the private headers of their parent PXR_PACKAGE
# library
target_include_directories(${LIBRARY_NAME}
PRIVATE $<TARGET_PROPERTY:${PXR_PACKAGE},INCLUDE_DIRECTORIES>
)
# Test libraries can include the private headers of their parent PXR_PACKAGE
# library
target_include_directories(${LIBRARY_NAME}
PRIVATE $<TARGET_PROPERTY:${PXR_PACKAGE},INCLUDE_DIRECTORIES>
)

install(TARGETS ${LIBRARY_NAME}
LIBRARY DESTINATION "tests/lib"
ARCHIVE DESTINATION "tests/lib"
)
install(TARGETS ${LIBRARY_NAME}
LIBRARY DESTINATION "tests/lib"
ARCHIVE DESTINATION "tests/lib"
)
endif()
endfunction() # pxr_build_test_shared_lib

function(pxr_build_test TEST_NAME)
cmake_parse_arguments(bt
"" ""
"LIBRARIES;CPPFILES"
${ARGN}
)
if (PXR_BUILD_TESTS)
cmake_parse_arguments(bt
"" ""
"LIBRARIES;CPPFILES"
${ARGN}
)

add_executable(${TEST_NAME}
${bt_CPPFILES}
)
target_link_libraries(${TEST_NAME}
${bt_LIBRARIES}
)
target_include_directories(${TEST_NAME}
PRIVATE $<TARGET_PROPERTY:${PXR_PACKAGE},INCLUDE_DIRECTORIES>
)
set_target_properties(${TEST_NAME}
PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
POSITION_INDEPENDENT_CODE ON
FOLDER "${PXR_PREFIX}/tests/bin"
)
add_executable(${TEST_NAME}
${bt_CPPFILES}
)
target_link_libraries(${TEST_NAME}
${bt_LIBRARIES}
)
target_include_directories(${TEST_NAME}
PRIVATE $<TARGET_PROPERTY:${PXR_PACKAGE},INCLUDE_DIRECTORIES>
)
set_target_properties(${TEST_NAME}
PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
POSITION_INDEPENDENT_CODE ON
FOLDER "${PXR_PREFIX}/tests/bin"
)

install(TARGETS ${TEST_NAME}
RUNTIME DESTINATION "tests"
)
install(TARGETS ${TEST_NAME}
RUNTIME DESTINATION "tests"
)
endif()
endfunction() # pxr_build_test

function(pxr_test_scripts)
foreach(file ${ARGN})
get_filename_component(destFile ${file} NAME_WE)
install(
PROGRAMS ${file}
DESTINATION tests
RENAME ${destFile}
)
endforeach()
if (PXR_BUILD_TESTS)
foreach(file ${ARGN})
get_filename_component(destFile ${file} NAME_WE)
install(
PROGRAMS ${file}
DESTINATION tests
RENAME ${destFile}
)
endforeach()
endif()
endfunction() # pxr_test_scripts

function(pxr_install_test_dir)
cmake_parse_arguments(bt
""
"SRC;DEST"
""
${ARGN}
)
if (PXR_BUILD_TESTS)
cmake_parse_arguments(bt
""
"SRC;DEST"
""
${ARGN}
)

install(
DIRECTORY ${bt_SRC}/
DESTINATION tests/ctest/${bt_DEST}
)
install(
DIRECTORY ${bt_SRC}/
DESTINATION tests/ctest/${bt_DEST}
)
endif()
endfunction() # pxr_install_test_dir

function(pxr_register_test TEST_NAME)
cmake_parse_arguments(bt
"PYTHON"
"COMMAND;STDOUT_REDIRECT;STDERR_REDIRECT;DIFF_COMPARE;EXPECTED_RETURN_CODE;TESTENV"
"ENV"
${ARGN}
)
if (PXR_BUILD_TESTS)
cmake_parse_arguments(bt
"PYTHON"
"COMMAND;STDOUT_REDIRECT;STDERR_REDIRECT;DIFF_COMPARE;EXPECTED_RETURN_CODE;TESTENV"
"ENV"
${ARGN}
)

# This harness is a filter which allows us to manipulate the test run,
# e.g. by changing the environment, changing the expected return code, etc.
set(testWrapperCmd ${PROJECT_SOURCE_DIR}/cmake/macros/testWrapper.py --verbose)
# This harness is a filter which allows us to manipulate the test run,
# e.g. by changing the environment, changing the expected return code, etc.
set(testWrapperCmd ${PROJECT_SOURCE_DIR}/cmake/macros/testWrapper.py --verbose)

if (bt_STDOUT_REDIRECT)
set(testWrapperCmd ${testWrapperCmd} --stdout-redirect=${bt_STDOUT_REDIRECT})
endif()
if (bt_STDOUT_REDIRECT)
set(testWrapperCmd ${testWrapperCmd} --stdout-redirect=${bt_STDOUT_REDIRECT})
endif()

if (bt_STDERR_REDIRECT)
set(testWrapperCmd ${testWrapperCmd} --stderr-redirect=${bt_STDERR_REDIRECT})
endif()
if (bt_STDERR_REDIRECT)
set(testWrapperCmd ${testWrapperCmd} --stderr-redirect=${bt_STDERR_REDIRECT})
endif()

# Not all tests will have testenvs, but if they do let the wrapper know so
# it can copy the testenv contents into the run directory. By default,
# assume the testenv has the same name as the test but allow it to be
# overridden by specifying TESTENV.
if (bt_TESTENV)
set(testenvDir ${CMAKE_INSTALL_PREFIX}/tests/ctest/${bt_TESTENV})
else()
set(testenvDir ${CMAKE_INSTALL_PREFIX}/tests/ctest/${TEST_NAME})
endif()
# Not all tests will have testenvs, but if they do let the wrapper know so
# it can copy the testenv contents into the run directory. By default,
# assume the testenv has the same name as the test but allow it to be
# overridden by specifying TESTENV.
if (bt_TESTENV)
set(testenvDir ${CMAKE_INSTALL_PREFIX}/tests/ctest/${bt_TESTENV})
else()
set(testenvDir ${CMAKE_INSTALL_PREFIX}/tests/ctest/${TEST_NAME})
endif()

set(testWrapperCmd ${testWrapperCmd} --testenv-dir=${testenvDir})
set(testWrapperCmd ${testWrapperCmd} --testenv-dir=${testenvDir})

if (bt_DIFF_COMPARE)
set(testWrapperCmd ${testWrapperCmd} --diff-compare=${bt_DIFF_COMPARE})
if (bt_DIFF_COMPARE)
set(testWrapperCmd ${testWrapperCmd} --diff-compare=${bt_DIFF_COMPARE})

# For now the baseline directory is assumed by convention from the test
# name. There may eventually be cases where we'd want to specify it by
# an argument though.
set(baselineDir ${testenvDir}/baseline)
set(testWrapperCmd ${testWrapperCmd} --baseline-dir=${baselineDir})
endif()
# For now the baseline directory is assumed by convention from the test
# name. There may eventually be cases where we'd want to specify it by
# an argument though.
set(baselineDir ${testenvDir}/baseline)
set(testWrapperCmd ${testWrapperCmd} --baseline-dir=${baselineDir})
endif()

if (bt_EXPECTED_RETURN_CODE)
set(testWrapperCmd ${testWrapperCmd}
--expected-return-code=${bt_EXPECTED_RETURN_CODE})
endif()
if (bt_EXPECTED_RETURN_CODE)
set(testWrapperCmd ${testWrapperCmd}
--expected-return-code=${bt_EXPECTED_RETURN_CODE})
endif()

if (bt_ENV)
foreach(env ${bt_ENV})
set(testWrapperCmd ${testWrapperCmd} --env-var=${env})
endforeach()
endif()
if (bt_ENV)
foreach(env ${bt_ENV})
set(testWrapperCmd ${testWrapperCmd} --env-var=${env})
endforeach()
endif()

# Ensure that Python imports the Python files built by this build
set(testWrapperCmd ${testWrapperCmd}
--env-var=PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib/python:${PYTHON_PATH})
# Ensure that Python imports the Python files built by this build
set(testWrapperCmd ${testWrapperCmd}
--env-var=PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib/python:${PYTHON_PATH})

# Ensure we run with the python executable known to the build
if (bt_PYTHON)
set(testCmd "${PYTHON_EXECUTABLE} ${bt_COMMAND}")
else()
set(testCmd "${bt_COMMAND}")
endif()
# Ensure we run with the python executable known to the build
if (bt_PYTHON)
set(testCmd "${PYTHON_EXECUTABLE} ${bt_COMMAND}")
else()
set(testCmd "${bt_COMMAND}")
endif()

add_test(
NAME ${TEST_NAME}
COMMAND ${PYTHON_EXECUTABLE} ${testWrapperCmd} ${testCmd}
)
add_test(
NAME ${TEST_NAME}
COMMAND ${PYTHON_EXECUTABLE} ${testWrapperCmd} ${testCmd}
)
endif()
endfunction() # pxr_register_test

function(pxr_setup_plugins)
Expand Down

0 comments on commit eaad278

Please sign in to comment.