From d81d51d1555f7dc55b5bc8ec7d1eccb7f5e759f8 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 9 Dec 2014 15:46:00 +0300 Subject: [PATCH 1/2] assing labels to targets and sources --- cmake/OpenCVModule.cmake | 26 ++++++++++++++++++++++++++ modules/cudev/test/CMakeLists.txt | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 85beca606c..9a330e0deb 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -26,6 +26,7 @@ # To control the setup of the module you could also set: # the_description - text to be used as current module description +# the_label - label for current module # OPENCV_MODULE_TYPE - STATIC|SHARED - set to force override global settings for current module # OPENCV_MODULE_IS_PART_OF_WORLD - ON|OFF (default ON) - should the module be added to the opencv_world? # BUILD_${the_module}_INIT - ON|OFF (default ON) - initial value for BUILD_${the_module} @@ -191,6 +192,15 @@ macro(ocv_add_module _name) set(OPENCV_MODULE_${the_module}_IS_PART_OF_WORLD OFF CACHE INTERNAL "") endif() + if(NOT DEFINED the_label) + if(OPENCV_PROCESSING_EXTRA_MODULES) + set(the_label "Extra") + else() + set(the_label "Main") + endif() + endif() + set(OPENCV_MODULE_${the_module}_LABEL "${the_label};${the_module}" CACHE INTERNAL "") + if(BUILD_${the_module}) set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} "${the_module}" CACHE INTERNAL "List of OpenCV modules included into the build") else() @@ -763,6 +773,10 @@ macro(_ocv_create_module) unset(sub_links) unset(cuda_objs) + set_target_properties(${the_module} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Module") + set_source_files_properties(${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES} ${${the_module}_pch} + PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Module") + ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}) ocv_target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}) ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) @@ -970,6 +984,10 @@ function(ocv_add_perf_tests) ocv_target_link_libraries(${the_target} ${perf_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) add_dependencies(opencv_perf_tests ${the_target}) + set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};PerfTest") + set_source_files_properties(${OPENCV_PERF_${the_module}_SOURCES} ${${the_target}_pch} + PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};PerfTest") + # Additional target properties set_target_properties(${the_target} PROPERTIES DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" @@ -1036,6 +1054,10 @@ function(ocv_add_accuracy_tests) ocv_target_link_libraries(${the_target} ${test_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) add_dependencies(opencv_tests ${the_target}) + set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};AccuracyTest") + set_source_files_properties(${OPENCV_TEST_${the_module}_SOURCES} ${${the_target}_pch} + PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};AccuracyTest") + # Additional target properties set_target_properties(${the_target} PROPERTIES DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" @@ -1093,6 +1115,10 @@ function(ocv_add_samples) ocv_target_link_libraries(${the_target} ${samples_deps}) set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}") + set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample") + set_source_files_properties("${source}" + PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample") + if(ENABLE_SOLUTION_FOLDERS) set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "${module_id}-example-${name}" diff --git a/modules/cudev/test/CMakeLists.txt b/modules/cudev/test/CMakeLists.txt index b3474168e3..e4c753ee7e 100644 --- a/modules/cudev/test/CMakeLists.txt +++ b/modules/cudev/test/CMakeLists.txt @@ -32,6 +32,10 @@ if(OCV_DEPENDENCIES_FOUND) ocv_target_link_libraries(${the_target} ${test_deps} ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES}) add_dependencies(opencv_tests ${the_target}) + set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL}") + set_source_files_properties(${OPENCV_TEST_${the_module}_SOURCES} ${${the_target}_pch} + PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};AccuracyTest") + # Additional target properties set_target_properties(${the_target} PROPERTIES DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" From 02c48ab7d698092239b90aaebc280812d9cdf618 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 12 Dec 2014 18:21:57 +0300 Subject: [PATCH 2/2] add CTest support to build tree --- CMakeLists.txt | 2 ++ cmake/OpenCVModule.cmake | 20 ++++++++------------ cmake/OpenCVUtils.cmake | 29 +++++++++++++++++++++++++++++ modules/cudev/test/CMakeLists.txt | 4 +--- modules/ts/src/ts_func.cpp | 3 +++ 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1482dec73c..ec3d17928a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,8 @@ if(DEFINED CMAKE_BUILD_TYPE) set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} ) endif() +enable_testing() + project(OpenCV CXX C) if(MSVC) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 9a330e0deb..92894b8b81 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -1008,6 +1008,12 @@ function(ocv_add_perf_tests) if(NOT BUILD_opencv_world) _ocv_add_precompiled_headers(${the_target}) endif() + + ocv_add_test_from_target("${the_target}" "Performance" "${the_target}") + ocv_add_test_from_target("opencv_sanity_${name}" "Sanity" "${the_target}" + "--perf_min_samples=1" + "--perf_force_samples=1" + "--perf_verify_sanity") else(OCV_DEPENDENCIES_FOUND) # TODO: warn about unsatisfied dependencies endif(OCV_DEPENDENCIES_FOUND) @@ -1068,21 +1074,11 @@ function(ocv_add_accuracy_tests) set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy") endif() - enable_testing() - get_target_property(LOC ${the_target} LOCATION) - add_test(${the_target} "${LOC}") - - if(WINRT) - # removing APPCONTAINER from tests to run from console - # look for detailed description inside of ocv_create_module macro above - add_custom_command(TARGET "opencv_test_${name}" - POST_BUILD - COMMAND link.exe /edit /APPCONTAINER:NO $(TargetPath)) - endif() - if(NOT BUILD_opencv_world) _ocv_add_precompiled_headers(${the_target}) endif() + + ocv_add_test_from_target("${the_target}" "Accuracy" "${the_target}") else(OCV_DEPENDENCIES_FOUND) # TODO: warn about unsatisfied dependencies endif(OCV_DEPENDENCIES_FOUND) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index e105f87267..e4e8771bf6 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -911,3 +911,32 @@ function(ocv_download) set(DOWNLOAD_PACKAGE_LOCATION ${DOWNLOAD_TARGET} PARENT_SCOPE) endfunction() + +function(ocv_add_test_from_target test_name test_kind the_target) + if(CMAKE_VERSION VERSION_GREATER "2.8" AND NOT CMAKE_CROSSCOMPILING) + if(NOT "${test_kind}" MATCHES "^(Accuracy|Performance|Sanity)$") + message(FATAL_ERROR "Unknown test kind : ${test_kind}") + endif() + if(NOT TARGET "${the_target}") + message(FATAL_ERROR "${the_target} is not a CMake target") + endif() + + string(TOLOWER "${test_kind}" test_kind_lower) + set(test_report_dir "${CMAKE_BINARY_DIR}/test-reports/${test_kind_lower}") + file(MAKE_DIRECTORY "${test_report_dir}") + + add_test(NAME "${test_name}" + COMMAND "${the_target}" + "--gtest_output=xml:${the_target}.xml" + ${ARGN}) + + set_tests_properties("${test_name}" PROPERTIES + LABELS "${OPENCV_MODULE_${the_module}_LABEL};${test_kind}" + WORKING_DIRECTORY "${test_report_dir}") + + if(OPENCV_TEST_DATA_PATH) + set_tests_properties("${test_name}" PROPERTIES + ENVIRONMENT "OPENCV_TEST_DATA_PATH=${OPENCV_TEST_DATA_PATH}") + endif() + endif() +endfunction() diff --git a/modules/cudev/test/CMakeLists.txt b/modules/cudev/test/CMakeLists.txt index e4c753ee7e..a7bd6328bc 100644 --- a/modules/cudev/test/CMakeLists.txt +++ b/modules/cudev/test/CMakeLists.txt @@ -46,9 +46,7 @@ if(OCV_DEPENDENCIES_FOUND) set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy") endif() - enable_testing() - get_target_property(LOC ${the_target} LOCATION) - add_test(${the_target} "${LOC}") + ocv_add_test_from_target("${the_target}" "Accuracy" "${the_target}") if(INSTALL_TESTS) install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 202a96f367..b6409ad37f 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -2951,6 +2951,9 @@ MatComparator::operator()(const char* expr1, const char* expr2, void printVersionInfo(bool useStdOut) { + // Tell CTest not to discard any output + if(useStdOut) std::cout << "CTEST_FULL_OUTPUT" << std::endl; + ::testing::Test::RecordProperty("cv_version", CV_VERSION); if(useStdOut) std::cout << "OpenCV version: " << CV_VERSION << std::endl;