2016-01-26 20:45:15 +00:00
|
|
|
#AddCephTest is a module for adding tests to the "make check" target which runs CTest
|
|
|
|
|
|
|
|
#adds makes target/script into a test, test to check target, sets necessary environment variables
|
|
|
|
function(add_ceph_test test_name test_path)
|
2016-07-26 20:23:52 +00:00
|
|
|
add_test(NAME ${test_name} COMMAND ${test_path} ${ARGN})
|
2018-04-26 08:44:07 +00:00
|
|
|
if(TARGET ${test_name})
|
|
|
|
add_dependencies(tests ${test_name})
|
|
|
|
endif()
|
2016-07-13 13:14:30 +00:00
|
|
|
set_property(TEST
|
2016-01-26 20:45:15 +00:00
|
|
|
${test_name}
|
|
|
|
PROPERTY ENVIRONMENT
|
|
|
|
CEPH_ROOT=${CMAKE_SOURCE_DIR}
|
|
|
|
CEPH_BIN=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
|
|
|
CEPH_LIB=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
2016-01-26 20:32:05 +00:00
|
|
|
CEPH_BUILD_DIR=${CMAKE_BINARY_DIR}
|
2016-01-26 20:45:15 +00:00
|
|
|
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib
|
|
|
|
PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}:${CMAKE_SOURCE_DIR}/src:$ENV{PATH}
|
2019-07-18 01:02:15 +00:00
|
|
|
PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cython_modules/lib.${Python${PYTHON_VERSION}_VERSION_MAJOR}:${CMAKE_SOURCE_DIR}/src/pybind
|
2016-05-10 13:50:17 +00:00
|
|
|
CEPH_BUILD_VIRTUALENV=${CEPH_BUILD_VIRTUALENV})
|
2016-07-14 07:59:14 +00:00
|
|
|
# none of the tests should take more than 1 hour to complete
|
|
|
|
set_property(TEST
|
|
|
|
${test_name}
|
2018-07-02 20:40:38 +00:00
|
|
|
PROPERTY TIMEOUT ${CEPH_TEST_TIMEOUT})
|
2016-01-26 20:45:15 +00:00
|
|
|
endfunction()
|
|
|
|
|
2018-06-15 05:54:31 +00:00
|
|
|
option(WITH_GTEST_PARALLEL "Enable running gtest based tests in parallel" OFF)
|
|
|
|
if(WITH_GTEST_PARALLEL)
|
2019-08-05 01:41:28 +00:00
|
|
|
if(NOT TARGET gtest-parallel_ext)
|
|
|
|
set(gtest_parallel_source_dir ${CMAKE_CURRENT_BINARY_DIR}/gtest-parallel)
|
|
|
|
include(ExternalProject)
|
|
|
|
ExternalProject_Add(gtest-parallel_ext
|
|
|
|
SOURCE_DIR "${gtest_parallel_source_dir}"
|
|
|
|
GIT_REPOSITORY "https://github.com/google/gtest-parallel.git"
|
|
|
|
GIT_TAG "master"
|
|
|
|
CONFIGURE_COMMAND ""
|
|
|
|
BUILD_COMMAND ""
|
|
|
|
INSTALL_COMMAND "")
|
|
|
|
add_dependencies(tests gtest-parallel_ext)
|
|
|
|
find_package(Python REQUIRED)
|
|
|
|
set(GTEST_PARALLEL_COMMAND
|
|
|
|
${Python_EXECUTABLE} ${gtest_parallel_source_dir}/gtest-parallel)
|
|
|
|
endif()
|
2018-06-15 05:54:31 +00:00
|
|
|
endif()
|
|
|
|
|
2016-01-26 20:45:15 +00:00
|
|
|
#sets uniform compiler flags and link libraries
|
2017-10-03 13:15:50 +00:00
|
|
|
function(add_ceph_unittest unittest_name)
|
2018-06-14 13:24:07 +00:00
|
|
|
set(UNITTEST "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${unittest_name}")
|
|
|
|
# If the second argument is "parallel", it means we want a parallel run
|
2018-06-15 05:54:31 +00:00
|
|
|
if(WITH_GTEST_PARALLEL AND "${ARGV1}" STREQUAL "parallel")
|
2018-07-07 09:10:23 +00:00
|
|
|
set(UNITTEST ${GTEST_PARALLEL_COMMAND} ${UNITTEST})
|
2018-06-14 13:24:07 +00:00
|
|
|
endif()
|
|
|
|
add_ceph_test(${unittest_name} "${UNITTEST}")
|
2016-01-26 20:45:15 +00:00
|
|
|
target_link_libraries(${unittest_name} ${UNITTEST_LIBS})
|
|
|
|
endfunction()
|
2019-08-01 11:40:36 +00:00
|
|
|
|
2019-08-05 15:37:52 +00:00
|
|
|
function(add_tox_test name)
|
2019-08-01 11:40:36 +00:00
|
|
|
set(test_name run-tox-${name})
|
2019-08-04 06:31:03 +00:00
|
|
|
set(venv_path ${CEPH_BUILD_VIRTUALENV}/${name}-virtualenv)
|
2019-08-05 15:37:52 +00:00
|
|
|
cmake_parse_arguments(TOXTEST "" "TOX_PATH" "TOX_ENVS" ${ARGN})
|
|
|
|
if(DEFINED TOXTEST_TOX_PATH)
|
|
|
|
set(tox_path ${TOXTEST_TOX_PATH})
|
|
|
|
else()
|
|
|
|
set(tox_path ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
endif()
|
|
|
|
if(WITH_PYTHON2)
|
|
|
|
list(APPEND tox_envs py27)
|
|
|
|
endif()
|
|
|
|
if(WITH_PYTHON3)
|
|
|
|
list(APPEND tox_envs py3)
|
|
|
|
endif()
|
|
|
|
if(DEFINED TOXTEST_TOX_ENVS)
|
|
|
|
set(tox_envs ${TOXTEST_TOX_ENVS})
|
|
|
|
endif()
|
|
|
|
string(REPLACE ";" "," tox_envs "${tox_envs}")
|
2019-08-04 06:31:03 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${venv_path}/bin/activate
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/src/tools/setup-virtualenv.sh ${venv_path}
|
|
|
|
WORKING_DIRECTORY ${tox_path}
|
|
|
|
COMMENT "preparing venv for ${name}")
|
|
|
|
add_custom_target(${name}-venv
|
|
|
|
DEPENDS ${venv_path}/bin/activate)
|
|
|
|
add_dependencies(tests ${name}-venv)
|
2019-08-01 11:40:36 +00:00
|
|
|
add_test(
|
|
|
|
NAME ${test_name}
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/src/script/run_tox.sh
|
|
|
|
--source-dir ${CMAKE_SOURCE_DIR}
|
|
|
|
--build-dir ${CMAKE_BINARY_DIR}
|
|
|
|
--tox-path ${tox_path}
|
2019-08-05 15:37:52 +00:00
|
|
|
--tox-envs ${tox_envs}
|
2019-08-04 06:31:03 +00:00
|
|
|
--venv-path ${venv_path})
|
2019-08-01 11:40:36 +00:00
|
|
|
set_property(
|
|
|
|
TEST ${test_name}
|
|
|
|
PROPERTY ENVIRONMENT
|
|
|
|
CEPH_ROOT=${CMAKE_SOURCE_DIR}
|
|
|
|
CEPH_BIN=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
|
|
|
CEPH_LIB=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
|
|
|
CEPH_BUILD_VIRTUALENV=${CEPH_BUILD_VIRTUALENV}
|
|
|
|
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib
|
|
|
|
PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}:${CMAKE_SOURCE_DIR}/src:$ENV{PATH}
|
|
|
|
PYTHONPATH=${CMAKE_SOURCE_DIR}/src/pybind)
|
|
|
|
list(APPEND tox_test run-tox-${name})
|
|
|
|
endfunction()
|