From 6a6d58d3896a6d20ab28bbbc962684478b2655a8 Mon Sep 17 00:00:00 2001 From: Evgeny Agafonchikov Date: Mon, 18 May 2015 11:57:18 +0300 Subject: [PATCH] Adding test support for WINRT --- CMakeLists.txt | 4 +- cmake/OpenCVCompilerOptions.cmake | 17 ++++ cmake/OpenCVModule.cmake | 47 ++++++++- modules/calib3d/test/test_fisheye.cpp | 1 + .../test/test_detectors_regression.cpp | 1 - modules/features2d/test/test_keypoints.cpp | 1 - .../test/test_matchers_algorithmic.cpp | 1 - modules/features2d/test/test_orb.cpp | 1 - .../test_rotation_and_scale_invariance.cpp | 1 - modules/imgproc/test/test_contours.cpp | 1 - modules/ts/CMakeLists.txt | 9 +- modules/ts/include/opencv2/ts.hpp | 99 +++++++++++++++++++ modules/ts/include/opencv2/ts/ts_gtest.h | 4 +- modules/ts/src/ts.cpp | 8 ++ modules/ts/src/ts_gtest.cpp | 27 +++-- modules/ts/src/ts_perf.cpp | 21 ++++ modules/video/test/test_tvl1optflow.cpp | 1 + platforms/winrt/readme.txt | 38 +++++++ platforms/winrt/setup_winrt.ps1 | 42 +++++++- 19 files changed, 303 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27d84703f2..89450fc58f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,8 +216,8 @@ OCV_OPTION(BUILD_ANDROID_EXAMPLES "Build examples for Android platform" OCV_OPTION(BUILD_DOCS "Create build rules for OpenCV Documentation" ON IF NOT WINRT) OCV_OPTION(BUILD_EXAMPLES "Build all examples" OFF ) OCV_OPTION(BUILD_PACKAGE "Enables 'make package_source' command" ON IF NOT WINRT) -OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" ON IF (NOT IOS AND NOT WINRT) ) -OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT IOS AND NOT WINRT) ) +OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" ON IF (NOT IOS) ) +OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT IOS) ) OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into debug libs (not MSCV only)" ON ) OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT for staticaly linked OpenCV" ON IF MSVC ) OCV_OPTION(BUILD_WITH_DYNAMIC_IPP "Enables dynamic linking of IPP (only for standalone IPP)" OFF ) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index 6c235ebfbf..fe3de3fed9 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -47,6 +47,18 @@ macro(add_extra_compiler_option option) endif() endmacro() +# Gets environment variable and puts its value to the corresponding preprocessor definition +# Useful for WINRT that has no access to environment variables +macro(add_env_definitions option) + set(value $ENV{${option}}) + if("${value}" STREQUAL "") + message(WARNING "${option} environment variable is empty. Please set it to appropriate location to get correct results") + else() + string(REPLACE "\\" "\\\\" value ${value}) + endif() + add_definitions("-D${option}=\"${value}\"") +endmacro() + # OpenCV fails some tests when 'char' is 'unsigned' by default add_extra_compiler_option(-fsigned-char) @@ -286,6 +298,11 @@ if(MSVC12 AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} /FS") endif() +# Adding additional using directory for WindowsPhone 8.0 to get Windows.winmd properly +if(WINRT_PHONE AND WINRT_8_0) + set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} /AI\$(WindowsSDK_MetadataPath)") +endif() + # Extra link libs if the user selects building static libs: if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID) # Android does not need these settings because they are already set by toolchain file diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 5de6f7399f..c37531a91b 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -684,6 +684,28 @@ macro(ocv_create_module) _ocv_create_module(${ARGN}) set(the_module_target ${the_module}) endif() + + if(WINRT) + # removing APPCONTAINER from modules to run from console + # in case of usual starting of WinRT test apps output is missing + # so starting of console version w/o APPCONTAINER is required to get test results + # also this allows to use opencv_extra test data for these tests + if(NOT "${the_module}" STREQUAL "opencv_ts" AND NOT "${the_module}" STREQUAL "opencv_hal") + add_custom_command(TARGET ${the_module} + POST_BUILD + COMMAND link.exe /edit /APPCONTAINER:NO $(TargetPath)) + endif() + + if("${the_module}" STREQUAL "opencv_ts") + # copy required dll files; WinRT apps need these dlls that are usually substituted by Visual Studio + # however they are not on path and need to be placed with executables to run from console w/o APPCONTAINER + add_custom_command(TARGET ${the_module} + POST_BUILD + COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\msvcp$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\msvcp$(PlatformToolsetVersion)_app.dll\"" + COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\msvcr$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\msvcr$(PlatformToolsetVersion)_app.dll\"" + COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\vccorlib$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\vccorlib$(PlatformToolsetVersion)_app.dll\"") + endif() + endif() endmacro() macro(_ocv_create_module) @@ -902,6 +924,10 @@ endmacro() function(ocv_add_perf_tests) ocv_debug_message("ocv_add_perf_tests(" ${ARGN} ")") + if(WINRT) + set(OPENCV_DEBUG_POSTFIX "") + endif() + set(perf_path "${CMAKE_CURRENT_LIST_DIR}/perf") if(BUILD_PERF_TESTS AND EXISTS "${perf_path}") __ocv_parse_test_sources(PERF ${ARGN}) @@ -936,11 +962,18 @@ function(ocv_add_perf_tests) DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" ) - if(ENABLE_SOLUTION_FOLDERS) set_target_properties(${the_target} PROPERTIES FOLDER "tests performance") endif() + 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_perf_${name}" + POST_BUILD + COMMAND link.exe /edit /APPCONTAINER:NO $(TargetPath)) + endif() + if(NOT BUILD_opencv_world) _ocv_add_precompiled_headers(${the_target}) endif() @@ -958,6 +991,10 @@ endfunction() function(ocv_add_accuracy_tests) ocv_debug_message("ocv_add_accuracy_tests(" ${ARGN} ")") + if(WINRT) + set(OPENCV_DEBUG_POSTFIX "") + endif() + set(test_path "${CMAKE_CURRENT_LIST_DIR}/test") if(BUILD_TESTS AND EXISTS "${test_path}") __ocv_parse_test_sources(TEST ${ARGN}) @@ -1000,6 +1037,14 @@ function(ocv_add_accuracy_tests) 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() diff --git a/modules/calib3d/test/test_fisheye.cpp b/modules/calib3d/test/test_fisheye.cpp index ba05f1ee26..4e7bf53634 100644 --- a/modules/calib3d/test/test_fisheye.cpp +++ b/modules/calib3d/test/test_fisheye.cpp @@ -43,6 +43,7 @@ #include "test_precomp.hpp" #include #include "../src/fisheye.hpp" +#include "opencv2/videoio.hpp" class fisheyeTest : public ::testing::Test { diff --git a/modules/features2d/test/test_detectors_regression.cpp b/modules/features2d/test/test_detectors_regression.cpp index 58c0b6dbf0..a235065172 100644 --- a/modules/features2d/test/test_detectors_regression.cpp +++ b/modules/features2d/test/test_detectors_regression.cpp @@ -40,7 +40,6 @@ //M*/ #include "test_precomp.hpp" -#include "opencv2/highgui.hpp" using namespace std; using namespace cv; diff --git a/modules/features2d/test/test_keypoints.cpp b/modules/features2d/test/test_keypoints.cpp index 4f5f8a0836..fb25514060 100644 --- a/modules/features2d/test/test_keypoints.cpp +++ b/modules/features2d/test/test_keypoints.cpp @@ -40,7 +40,6 @@ //M*/ #include "test_precomp.hpp" -#include "opencv2/highgui.hpp" #include "opencv2/core/core_c.h" using namespace std; diff --git a/modules/features2d/test/test_matchers_algorithmic.cpp b/modules/features2d/test/test_matchers_algorithmic.cpp index 8f66648599..0e3f2ffd55 100644 --- a/modules/features2d/test/test_matchers_algorithmic.cpp +++ b/modules/features2d/test/test_matchers_algorithmic.cpp @@ -40,7 +40,6 @@ //M*/ #include "test_precomp.hpp" -#include "opencv2/highgui.hpp" using namespace std; using namespace cv; diff --git a/modules/features2d/test/test_orb.cpp b/modules/features2d/test/test_orb.cpp index b7f854ba80..c02ea010cc 100644 --- a/modules/features2d/test/test_orb.cpp +++ b/modules/features2d/test/test_orb.cpp @@ -40,7 +40,6 @@ //M*/ #include "test_precomp.hpp" -#include "opencv2/highgui.hpp" using namespace std; using namespace cv; diff --git a/modules/features2d/test/test_rotation_and_scale_invariance.cpp b/modules/features2d/test/test_rotation_and_scale_invariance.cpp index f03fa14477..93ded0b6af 100644 --- a/modules/features2d/test/test_rotation_and_scale_invariance.cpp +++ b/modules/features2d/test/test_rotation_and_scale_invariance.cpp @@ -40,7 +40,6 @@ //M*/ #include "test_precomp.hpp" -#include "opencv2/highgui.hpp" using namespace std; using namespace cv; diff --git a/modules/imgproc/test/test_contours.cpp b/modules/imgproc/test/test_contours.cpp index b94408d3b8..d8d51f2fe1 100644 --- a/modules/imgproc/test/test_contours.cpp +++ b/modules/imgproc/test/test_contours.cpp @@ -40,7 +40,6 @@ //M*/ #include "test_precomp.hpp" -#include "opencv2/highgui.hpp" using namespace cv; using namespace std; diff --git a/modules/ts/CMakeLists.txt b/modules/ts/CMakeLists.txt index c0158ba416..2732924b74 100644 --- a/modules/ts/CMakeLists.txt +++ b/modules/ts/CMakeLists.txt @@ -1,12 +1,19 @@ set(the_description "The ts module") -if(IOS OR WINRT) +if(IOS) ocv_module_disable(ts) endif() set(OPENCV_MODULE_TYPE STATIC) set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE) +if(WINRT) + # WINRT doesn't have access to environment variables + # so adding corresponding macros during CMake run + add_env_definitions(OPENCV_TEST_DATA_PATH) + add_env_definitions(OPENCV_PERF_VALIDATION_DIR) +endif() + ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) ocv_add_module(ts INTERNAL opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui) diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 4a08182c62..0f3b3149de 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -588,3 +588,102 @@ int main(int argc, char **argv) \ #endif #include "opencv2/ts/ts_perf.hpp" + +#ifdef WINRT +#ifndef __FSTREAM_EMULATED__ +#define __FSTREAM_EMULATED__ +#include +#include +#include + +#undef ifstream +#undef ofstream +#define ifstream ifstream_emulated +#define ofstream ofstream_emulated + +namespace std { + +class ifstream : public stringstream +{ + FILE* f; +public: + ifstream(const char* filename, ios_base::openmode mode = ios_base::in) + : f(NULL) + { + string modeStr("r"); + printf("Open file (read): %s\n", filename); + if (mode & ios_base::binary) + modeStr += "b"; + f = fopen(filename, modeStr.c_str()); + + if (f == NULL) + { + printf("Can't open file: %s\n", filename); + return; + } + fseek(f, 0, SEEK_END); + size_t sz = ftell(f); + if (sz > 0) + { + char* buf = (char*) malloc(sz); + fseek(f, 0, SEEK_SET); + if (fread(buf, 1, sz, f) == sz) + { + this->str(std::string(buf, sz)); + } + free(buf); + } + } + + ~ifstream() { close(); } + bool is_open() const { return f != NULL; } + void close() + { + if (f) + fclose(f); + f = NULL; + this->str(""); + } +}; + +class ofstream : public stringstream +{ + FILE* f; +public: + ofstream(const char* filename, ios_base::openmode mode = ios_base::out) + : f(NULL) + { + open(filename, mode); + } + ~ofstream() { close(); } + void open(const char* filename, ios_base::openmode mode = ios_base::out) + { + string modeStr("w+"); + if (mode & ios_base::trunc) + modeStr = "w"; + if (mode & ios_base::binary) + modeStr += "b"; + f = fopen(filename, modeStr.c_str()); + printf("Open file (write): %s\n", filename); + if (f == NULL) + { + printf("Can't open file (write): %s\n", filename); + return; + } + } + bool is_open() const { return f != NULL; } + void close() + { + if (f) + { + fwrite(reinterpret_cast(this->str().c_str()), this->str().size(), 1, f); + fclose(f); + } + f = NULL; + this->str(""); + } +}; + +} // namespace std +#endif // __FSTREAM_EMULATED__ +#endif // WINRT diff --git a/modules/ts/include/opencv2/ts/ts_gtest.h b/modules/ts/include/opencv2/ts/ts_gtest.h index 243c63879c..cec926a08f 100644 --- a/modules/ts/include/opencv2/ts/ts_gtest.h +++ b/modules/ts/include/opencv2/ts/ts_gtest.h @@ -2924,7 +2924,7 @@ inline const char* StrNCpy(char* dest, const char* src, size_t n) { // StrError() aren't needed on Windows CE at this time and thus not // defined there. -#if !GTEST_OS_WINDOWS_MOBILE +#if !GTEST_OS_WINDOWS_MOBILE && !defined WINRT inline int ChDir(const char* dir) { return chdir(dir); } #endif inline FILE* FOpen(const char* path, const char* mode) { @@ -2948,7 +2948,7 @@ inline int Close(int fd) { return close(fd); } inline const char* StrError(int errnum) { return strerror(errnum); } #endif inline const char* GetEnv(const char* name) { -#if GTEST_OS_WINDOWS_MOBILE +#if GTEST_OS_WINDOWS_MOBILE || defined WINRT // We are on Windows CE, which has no environment variables. return NULL; #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index 29fd056fea..232124a96a 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -450,7 +450,11 @@ static int tsErrorCallback( int status, const char* func_name, const char* err_m void TS::init( const string& modulename ) { +#ifndef WINRT char* datapath_dir = getenv("OPENCV_TEST_DATA_PATH"); +#else + char* datapath_dir = OPENCV_TEST_DATA_PATH; +#endif if( datapath_dir ) { @@ -684,7 +688,11 @@ void parseCustomOptions(int argc, char **argv) test_ipp_check = parser.get("test_ipp_check"); if (!test_ipp_check) +#ifndef WINRT test_ipp_check = getenv("OPENCV_IPP_CHECK") != NULL; +#else + test_ipp_check = false; +#endif } /* End of file. */ diff --git a/modules/ts/src/ts_gtest.cpp b/modules/ts/src/ts_gtest.cpp index 50c8808aff..29a3996be8 100644 --- a/modules/ts/src/ts_gtest.cpp +++ b/modules/ts/src/ts_gtest.cpp @@ -4054,7 +4054,7 @@ enum GTestColor { COLOR_YELLOW }; -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !defined WINRT // Returns the character attribute for the given color. WORD GetColorAttribute(GTestColor color) { @@ -4122,7 +4122,7 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_list args; va_start(args, fmt); -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || GTEST_OS_IOS +#if GTEST_OS_WINDOWS_MOBILE || WINRT || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || GTEST_OS_IOS const bool use_color = false; #else static const bool in_color_mode = @@ -4137,7 +4137,7 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) { return; } -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !defined WINRT const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); // Gets the current text color. @@ -5320,7 +5320,7 @@ void UnitTest::AddTestPartResult( // with another testing framework) and specify the former on the // command line for debugging. if (GTEST_FLAG(break_on_failure)) { -#if GTEST_OS_WINDOWS +#if GTEST_OS_WINDOWS && !defined WINRT // Using DebugBreak on Windows allows gtest to still break into a debugger // when a failure happens and both the --gtest_break_on_failure and // the --gtest_catch_exceptions flags are specified. @@ -5398,7 +5398,7 @@ int UnitTest::Run() { // process. In either case the user does not want to see pop-up dialogs // about crashes - they are expected. if (impl()->catch_exceptions() || in_death_test_child_process) { -# if !GTEST_OS_WINDOWS_MOBILE +# if !GTEST_OS_WINDOWS_MOBILE && !defined WINRT // SetErrorMode doesn't exist on CE. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); @@ -7110,6 +7110,7 @@ bool DeathTestImpl::Passed(bool status_ok) { } # if GTEST_OS_WINDOWS +#ifndef WINRT // WindowsDeathTest implements death tests on Windows. Due to the // specifics of starting new processes on Windows, death tests there are // always threadsafe, and Google Test considers the @@ -7301,6 +7302,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { set_spawned(true); return OVERSEE_TEST; } +#endif # else // We are not on Windows. // ForkingDeathTest provides implementations for most of the abstract @@ -7711,10 +7713,14 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex, } # if GTEST_OS_WINDOWS - if (GTEST_FLAG(death_test_style) == "threadsafe" || GTEST_FLAG(death_test_style) == "fast") { +#ifndef WINRT *test = new WindowsDeathTest(statement, regex, file, line); +#else + printf("DeathTest is not supported on winrt!\n"); + return false; +#endif } # else @@ -7758,6 +7764,7 @@ static void SplitString(const ::std::string& str, char delimiter, } # if GTEST_OS_WINDOWS +#ifndef WINRT // Recreates the pipe and event handles from the provided parameters, // signals the event, and returns a file descriptor wrapped around the pipe // handle. This function is called in the child process only. @@ -7823,6 +7830,7 @@ int GetStatusFileDescriptor(unsigned int parent_process_id, return write_fd; } +#endif # endif // GTEST_OS_WINDOWS // Returns a newly created InternalRunDeathTestFlag object with fields @@ -7840,7 +7848,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { int write_fd = -1; # if GTEST_OS_WINDOWS - +#ifndef WINRT unsigned int parent_process_id = 0; size_t write_handle_as_size_t = 0; size_t event_handle_as_size_t = 0; @@ -7857,6 +7865,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { write_fd = GetStatusFileDescriptor(parent_process_id, write_handle_as_size_t, event_handle_as_size_t); +#endif # else if (fields.size() != 4 @@ -7974,7 +7983,7 @@ static bool IsPathSeparator(char c) { // Returns the current working directory, or "" if unsuccessful. FilePath FilePath::GetCurrentDir() { -#if GTEST_OS_WINDOWS_MOBILE +#if GTEST_OS_WINDOWS_MOBILE || WINRT // Windows CE doesn't have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); @@ -8765,6 +8774,7 @@ class CapturedStream { public: // The ctor redirects the stream to a temporary file. explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { +#ifndef WINRT # if GTEST_OS_WINDOWS char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT @@ -8810,6 +8820,7 @@ class CapturedStream { fflush(NULL); dup2(captured_fd, fd_); close(captured_fd); +#endif } ~CapturedStream() { diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index f5ba1d81e6..ef8f0af9a0 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -185,7 +185,11 @@ void Regression::init(const std::string& testSuitName, const std::string& ext) return; } +#ifndef WINRT const char *data_path_dir = getenv("OPENCV_TEST_DATA_PATH"); +#else + const char *data_path_dir = OPENCV_TEST_DATA_PATH; +#endif const char *path_separator = "/"; if (data_path_dir) @@ -814,7 +818,12 @@ void TestBase::Init(const std::vector & availableImpls, param_force_samples = args.get("perf_force_samples"); param_write_sanity = args.has("perf_write_sanity"); param_verify_sanity = args.has("perf_verify_sanity"); + +#ifndef WINRT test_ipp_check = !args.has("perf_ipp_check") ? getenv("OPENCV_IPP_CHECK") != NULL : true; +#else + test_ipp_check = false; +#endif param_threads = args.get("perf_threads"); #ifdef CV_COLLECT_IMPL_DATA param_collect_impl = args.has("perf_collect_impl"); @@ -881,7 +890,11 @@ void TestBase::Init(const std::vector & availableImpls, #endif { +#ifndef WINRT const char* path = getenv("OPENCV_PERF_VALIDATION_DIR"); +#else + const char* path = OPENCV_PERF_VALIDATION_DIR; +#endif if (path) perf_validation_results_directory = path; } @@ -1185,7 +1198,11 @@ bool TestBase::next() printf("Performance is unstable, it may be a result of overheat problems\n"); printf("Idle delay for %d ms... \n", perf_validation_idle_delay_ms); #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 +#ifndef WINRT_8_0 Sleep(perf_validation_idle_delay_ms); +#else + WaitForSingleObjectEx(GetCurrentThread(), perf_validation_idle_delay_ms, FALSE); +#endif #else usleep(perf_validation_idle_delay_ms * 1000); #endif @@ -1635,7 +1652,11 @@ std::string TestBase::getDataPath(const std::string& relativePath) throw PerfEarlyExitException(); } +#ifndef WINRT const char *data_path_dir = getenv("OPENCV_TEST_DATA_PATH"); +#else + const char *data_path_dir = OPENCV_TEST_DATA_PATH; +#endif const char *path_separator = "/"; std::string path; diff --git a/modules/video/test/test_tvl1optflow.cpp b/modules/video/test/test_tvl1optflow.cpp index b829c7c895..e4b80637ec 100644 --- a/modules/video/test/test_tvl1optflow.cpp +++ b/modules/video/test/test_tvl1optflow.cpp @@ -108,6 +108,7 @@ namespace flow(i, j) = u; } } + file.close(); } bool isFlowCorrect(Point2f u) diff --git a/platforms/winrt/readme.txt b/platforms/winrt/readme.txt index 011e449161..c35d18d21f 100644 --- a/platforms/winrt/readme.txt +++ b/platforms/winrt/readme.txt @@ -119,3 +119,41 @@ To generate Windows Phone 8.1 x86 project files in the opencv/bin dir mkdir bin cd bin cmake -G "Visual Studio 12 2013" -DCMAKE_SYSTEM_NAME=WindowsPhone -DCMAKE_SYSTEM_VERSION=8.1 ../ + +Running tests for Windows Store +=============================== +1. You might need to install this if you haven't already: http://www.microsoft.com/en-US/download/details.aspx?id=40784 + +2. Set OPENCV_TEST_DATA_PATH environment variable to location of opencv_extra/testdata (cloning of https://github.com/Itseez/opencv_extra repo required) to get tests work correctly. Also, set OPENCV_PERF_VALIDATION_DIR environment variable in case you are planning to have place where to store performance test results and compare them with the future test runs. + +3. In case you'd like to adjust some flags that are defaulted by setup_winrt script, go to "Manual build" section. Otherwise go to platforms/winrt and execute + +setup_winrt.bat "WS" "8.1" "x64" + +This will generate all files needed to build open_cv projects for selected platform in opencv\bin\. Open the opencv\bin\ directory and open the OpenCV.sln. + +4. Set OCV solution to Release mode and build it. They should build without errors and generate executables in "bin\WS\8.1\x64\bin\Release\" (or similar path depending on the configuration) + +5. Running tests: + - **Accuracy:** Run opencv_test_{module}.exe via console or as usual by double clicking it. You should see output in the console window + - **Performance:** Run opencv_perf_{module}.exe via console or as usual by double clicking it. You should see output in the console window. In case you'd like to write test results to file use --perf_write_validation_results= parameter; To compare current results to previous use --perf_read_validation_results=. This should read/write files from/to OPENCV_PERF_VALIDATION_DIR + +Manual build +============ + + CMake interface: +----------------- + 1. Set CMAKE_SYSTEM_NAME to WindowsStore or WindowsPhone and CMAKE_SYSTEM_VERSION to 8.0 or 8.1 + 2. Set CMAKE_INSTALL_PREFIX using format "\WS\8.1\x64" (this structure is required by samples) + 3. Click "Configure" and choose required generator + 4. Click "Generate" + + Command line: +-------------- + 1. md bin + 2. cd bin + 3. Add any required parameters to this command and execute it: + + cmake -G "Visual Studio 12 2013 Win64" -DCMAKE_SYSTEM_NAME:String=WindowsStore -DCMAKE_SYSTEM_VERSION:String=8.1 -DCMAKE_VS_EFFECTIVE_PLATFORMS:String=x64 -DCMAKE_INSTALL_PREFIX:PATH=.\install\WS\8.1\x64\ .. + +Return to "Running tests for Windows Store", list item 4. \ No newline at end of file diff --git a/platforms/winrt/setup_winrt.ps1 b/platforms/winrt/setup_winrt.ps1 index ddd82864df..47a9946ace 100644 --- a/platforms/winrt/setup_winrt.ps1 +++ b/platforms/winrt/setup_winrt.ps1 @@ -51,6 +51,10 @@ Param( [ValidateNotNull()] $ARCHITECTURES_IN = "x86", + [parameter(Mandatory=$False)] + [String] + $TESTS = "None", + [parameter(Mandatory=$False)] [String] [ValidateNotNull()] @@ -129,6 +133,16 @@ function Call-MSBuild($path, $config) return $true } +function RunAccuracyTests($path) { + md "$path\bin\Release\accuracy" + python "$PSScriptRoot\..\..\modules\ts\misc\run.py" -w "$path\bin\Release\accuracy" -a "$path\bin\Release" +} + +function RunPerfTests($path) { + md "$path\bin\Release\perf" + python "$PSScriptRoot\..\..\modules\ts\misc\run.py" -w "$path\bin\Release\perf" "$path\bin\Release" +} + Function Execute() { If ($HELP.IsPresent) { ShowHelp @@ -174,6 +188,7 @@ Function Execute() { Throw "$($_) is not valid! Please use x86, x64, ARM" } } + D "Processed Architectures: $architectures" # Assuming we are in '/platforms/winrt' we should move up to sources root directory @@ -263,6 +278,25 @@ Function Execute() { Call-MSBuild "OpenCV.sln" "Release" Call-MSBuild "INSTALL.vcxproj" "Release" + + Try { + # Running tests for release versions: + If ($TESTS -eq "ALL") { + RunAccuracyTests "$path" + RunPerfTests "$path" + } else { + If($TESTS -eq "ACC") { + RunAccuracyTests "$path" + } + If($TESTS -eq "PERF") { + RunPerfTests "$path" + } + } + } Catch { + $ErrorMessage = $_.Exception.Message + L "Error: $ErrorMessage" + exit + } } } Catch { $ErrorMessage = $_.Exception.Message @@ -305,8 +339,10 @@ Function ShowHelp() { Write-Host " cmd> setup_winrt.bat [params]" Write-Host " cmd> PowerShell.exe -ExecutionPolicy Unrestricted -File setup_winrt.ps1 [params]" Write-Host " Parameters:" - Write-Host " setup_winrt [options] [platform] [version] [architecture] [generator] [install-path]" + Write-Host " setup_winrt [options] [platform] [version] [architecture] [tests] [generator] [install-path]" Write-Host " setup_winrt -b 'WP' 'x86,ARM' " + Write-Host " setup_winrt -b 'WP' 'x86,ARM' ALL" + Write-Host " setup_winrt -b 'WP' 'x86,ARM' -test PERF " Write-Host " setup_winrt -architecture x86 -platform WP " Write-Host " setup_winrt -arc x86 -plat 'WP,WS' " Write-Host " setup_winrt -a x86 -g 'Visual Studio 11 2012' -pl WP " @@ -329,6 +365,10 @@ Function ShowHelp() { Write-Host " Example: 'ARM,x64' " Write-Host " Options: x86, ARM, x64. Available options may be limited depending on your local setup. " Write-Host " Note that you'll need to use quotes to specify more than one architecture. " + Write-Host " tests - Test sets to run. Requires -b option otherwise ignored. " + Write-Host " Default: None. " + Write-Host " Example: 'ALL' " + Write-Host " Options: ACC, PERF, ALL. " Write-Host " generator - Visual Studio instance used to generate the projects. " Write-Host " Default: Visual Studio 12 2013 " Write-Host " Example: 'Visual Studio 11 2012' "