1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #include "precomp.hpp"
43 #include "opencv2/core/core_c.h"
70 #if defined _WIN32 || defined WINCE
74 # include <sys/stat.h>
79 #define DUMP_CONFIG_PROPERTY(propertyName, propertyValue) \
81 std::stringstream ssName, ssValue;\
82 ssName << propertyName;\
83 ssValue << (propertyValue); \
84 ::testing::Test::RecordProperty(ssName.str(), ssValue.str()); \
87 #define DUMP_MESSAGE_STDOUT(msg) \
89 std::cout << msg << std::endl; \
92 #include "opencv2/core/opencl/opencl_info.hpp"
94 #include "opencv2/core/utils/allocator_stats.hpp"
95 namespace cv { namespace ocl {
96 cv::utils::AllocatorStatisticsInterface& getOpenCLAllocatorStatistics();
100 #include "opencv2/core/utils/allocator_stats.hpp"
102 CV_EXPORTS cv::utils::AllocatorStatisticsInterface& getAllocatorStatistics();
105 #include "opencv_tests_config.hpp"
107 #include "ts_tags.hpp"
109 #if defined(__GNUC__) && defined(__linux__)
111 size_t malloc_peak(void) __attribute__((weak));
112 void malloc_reset_peak(void) __attribute__((weak));
115 static size_t (*malloc_peak)(void) = 0;
116 static void (*malloc_reset_peak)(void) = 0;
119 namespace opencv_test {
120 bool required_opencv_test_namespace = false; // compilation check for non-refactored tests
126 uint64 param_seed = 0x12345678; // real value is passed via parseCustomOptions function
128 static std::string path_join(const std::string& prefix, const std::string& subpath)
130 CV_Assert(subpath.empty() || subpath[0] != '/');
133 bool skipSlash = prefix.size() > 0 ? (prefix[prefix.size()-1] == '/' || prefix[prefix.size()-1] == '\\') : false;
134 std::string path = prefix + (skipSlash ? "" : "/") + subpath;
140 /*****************************************************************************************\
141 * Exception and memory handlers *
142 \*****************************************************************************************/
144 // a few platform-dependent declarations
148 static void SEHTranslator( unsigned int /*u*/, EXCEPTION_POINTERS* pExp )
150 TS::FailureCode code = TS::FAIL_EXCEPTION;
151 switch( pExp->ExceptionRecord->ExceptionCode )
153 case EXCEPTION_ACCESS_VIOLATION:
154 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
155 case EXCEPTION_DATATYPE_MISALIGNMENT:
156 case EXCEPTION_FLT_STACK_CHECK:
157 case EXCEPTION_STACK_OVERFLOW:
158 case EXCEPTION_IN_PAGE_ERROR:
159 code = TS::FAIL_MEMORY_EXCEPTION;
161 case EXCEPTION_FLT_DENORMAL_OPERAND:
162 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
163 case EXCEPTION_FLT_INEXACT_RESULT:
164 case EXCEPTION_FLT_INVALID_OPERATION:
165 case EXCEPTION_FLT_OVERFLOW:
166 case EXCEPTION_FLT_UNDERFLOW:
167 case EXCEPTION_INT_DIVIDE_BY_ZERO:
168 case EXCEPTION_INT_OVERFLOW:
169 code = TS::FAIL_ARITHM_EXCEPTION;
171 case EXCEPTION_BREAKPOINT:
172 case EXCEPTION_ILLEGAL_INSTRUCTION:
173 case EXCEPTION_INVALID_DISPOSITION:
174 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
175 case EXCEPTION_PRIV_INSTRUCTION:
176 case EXCEPTION_SINGLE_STEP:
177 code = TS::FAIL_EXCEPTION;
185 static const int tsSigId[] = { SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGABRT, -1 };
187 static jmp_buf tsJmpMark;
189 static void signalHandler( int sig_code )
191 TS::FailureCode code = TS::FAIL_EXCEPTION;
195 code = TS::FAIL_ARITHM_EXCEPTION;
199 code = TS::FAIL_ARITHM_EXCEPTION;
202 code = TS::FAIL_EXCEPTION;
205 longjmp( tsJmpMark, (int)code );
211 // reads 16-digit hexadecimal number (i.e. 64-bit integer)
212 int64 readSeed( const char* str )
215 if( str && strlen(str) == 16 )
217 for( int i = 0; str[i]; i++ )
219 int c = tolower(str[i]);
223 (str[i] < 'a' ? str[i] - '0' : str[i] - 'a' + 10);
230 /*****************************************************************************************\
231 * Base Class for Tests *
232 \*****************************************************************************************/
237 test_case_count = -1;
240 BaseTest::~BaseTest()
245 void BaseTest::clear()
250 const CvFileNode* BaseTest::find_param( CvFileStorage* fs, const char* param_name )
252 CvFileNode* node = cvGetFileNodeByName(fs, 0, get_name().c_str());
253 return node ? cvGetFileNodeByName( fs, node, param_name ) : 0;
257 int BaseTest::read_params( CvFileStorage* )
263 bool BaseTest::can_do_fast_forward()
269 void BaseTest::safe_run( int start_from )
272 ts->update_context( 0, -1, true );
273 ts->update_context( this, -1, true );
275 if( !::testing::GTEST_FLAG(catch_exceptions) )
282 int _code = setjmp( tsJmpMark );
286 throw TS::FailureCode(_code);
291 catch (const cv::Exception& exc)
293 const char* errorStr = cvErrorStr(exc.code);
296 const char* delim = exc.err.find('\n') == cv::String::npos ? "" : "\n";
297 sprintf( buf, "OpenCV Error:\n\t%s (%s%s) in %s, file %s, line %d",
298 errorStr, delim, exc.err.c_str(), exc.func.size() > 0 ?
299 exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line );
300 ts->printf(TS::LOG, "%s\n", buf);
302 ts->set_failed_test_info( TS::FAIL_ERROR_IN_CALLED_FUNC );
304 catch (const TS::FailureCode& fc)
306 std::string errorStr = TS::str_from_code(fc);
307 ts->printf(TS::LOG, "General failure:\n\t%s (%d)\n", errorStr.c_str(), fc);
309 ts->set_failed_test_info( fc );
313 ts->printf(TS::LOG, "Unknown failure\n");
315 ts->set_failed_test_info( TS::FAIL_EXCEPTION );
319 ts->set_gtest_status();
323 void BaseTest::run( int start_from )
325 int test_case_idx, count = get_test_case_count();
326 int64 t_start = cvGetTickCount();
327 double freq = cv::getTickFrequency();
328 bool ff = can_do_fast_forward();
329 int progress = 0, code;
332 for( test_case_idx = ff && start_from >= 0 ? start_from : 0;
333 count < 0 || test_case_idx < count; test_case_idx++ )
335 ts->update_context( this, test_case_idx, ff );
336 progress = update_progress( progress, test_case_idx, count, (double)(t1 - t_start)/(freq*1000) );
338 code = prepare_test_case( test_case_idx );
339 if( code < 0 || ts->get_err_code() < 0 )
347 if( ts->get_err_code() < 0 )
350 if( validate_test_results( test_case_idx ) < 0 || ts->get_err_code() < 0 )
356 void BaseTest::run_func(void)
362 int BaseTest::get_test_case_count(void)
364 return test_case_count;
368 int BaseTest::prepare_test_case( int )
374 int BaseTest::validate_test_results( int )
380 int BaseTest::update_progress( int progress, int test_case_idx, int count, double dt )
382 int width = 60 - (int)get_name().size();
385 int t = cvRound( ((double)test_case_idx * width)/count );
388 ts->printf( TS::CONSOLE, "." );
392 else if( cvRound(dt) > progress )
394 ts->printf( TS::CONSOLE, "." );
395 progress = cvRound(dt);
402 BadArgTest::BadArgTest()
406 // oldErrorCbkData = 0;
409 BadArgTest::~BadArgTest(void)
413 int BadArgTest::run_test_case( int expected_code, const string& _descr )
417 const char* descr = _descr.c_str() ? _descr.c_str() : "";
423 catch(const cv::Exception& e)
426 if (e.code != expected_code &&
427 e.code != cv::Error::StsError && e.code != cv::Error::StsAssert // Exact error codes support will be dropped. Checks should provide proper text messages intead.
430 ts->printf(TS::LOG, "%s (test case #%d): the error code %d is different from the expected %d\n",
431 descr, test_case_idx, e.code, expected_code);
438 ts->printf(TS::LOG, "%s (test case #%d): unknown exception was thrown (the function has likely crashed)\n",
439 descr, test_case_idx);
445 ts->printf(TS::LOG, "%s (test case #%d): no expected exception was thrown\n",
446 descr, test_case_idx);
454 /*****************************************************************************************\
455 * Base Class for Test System *
456 \*****************************************************************************************/
458 /******************************** Constructors/Destructors ******************************/
462 rng_seed = (uint64)-1;
463 use_optimized = true;
464 test_case_count_scale = 1;
472 rng_seed = rng_seed0 = 0;
487 string TS::str_from_code( const TS::FailureCode code )
491 case OK: return "Ok";
492 case FAIL_GENERIC: return "Generic/Unknown";
493 case FAIL_MISSING_TEST_DATA: return "No test data";
494 case FAIL_INVALID_TEST_DATA: return "Invalid test data";
495 case FAIL_ERROR_IN_CALLED_FUNC: return "cvError invoked";
496 case FAIL_EXCEPTION: return "Hardware/OS exception";
497 case FAIL_MEMORY_EXCEPTION: return "Invalid memory access";
498 case FAIL_ARITHM_EXCEPTION: return "Arithmetic exception";
499 case FAIL_MEMORY_CORRUPTION_BEGIN: return "Corrupted memblock (beginning)";
500 case FAIL_MEMORY_CORRUPTION_END: return "Corrupted memblock (end)";
501 case FAIL_MEMORY_LEAK: return "Memory leak";
502 case FAIL_INVALID_OUTPUT: return "Invalid function output";
503 case FAIL_MISMATCH: return "Unexpected output";
504 case FAIL_BAD_ACCURACY: return "Bad accuracy";
505 case FAIL_HANG: return "Infinite loop(?)";
506 case FAIL_BAD_ARG_CHECK: return "Incorrect handling of bad arguments";
510 return "Generic/Unknown";
513 static int tsErrorCallback( int status, const char* func_name, const char* err_msg, const char* file_name, int line, TS* ts )
515 const char* delim = std::string(err_msg).find('\n') == std::string::npos ? "" : "\n";
516 ts->printf(TS::LOG, "OpenCV Error:\n\t%s (%s%s) in %s, file %s, line %d\n", cvErrorStr(status), delim, err_msg, func_name[0] != 0 ? func_name : "unknown function", file_name, line);
520 /************************************** Running tests **********************************/
522 void TS::init( const string& modulename )
524 data_search_subdir.push_back(modulename);
526 char* datapath_dir = getenv("OPENCV_TEST_DATA_PATH");
528 char* datapath_dir = OPENCV_TEST_DATA_PATH;
533 data_path = path_join(path_join(datapath_dir, modulename), "");
536 cv::redirectError((cv::ErrorCallback)tsErrorCallback, this);
538 if( ::testing::GTEST_FLAG(catch_exceptions) )
542 _set_se_translator( SEHTranslator );
545 for( int i = 0; tsSigId[i] >= 0; i++ )
546 signal( tsSigId[i], signalHandler );
553 _set_se_translator( 0 );
556 for( int i = 0; tsSigId[i] >= 0; i++ )
557 signal( tsSigId[i], SIG_DFL );
561 if( params.use_optimized == 0 )
562 cv::setUseOptimized(false);
564 rng = RNG(params.rng_seed);
568 void TS::set_gtest_status()
570 TS::FailureCode code = get_err_code();
575 sprintf(seedstr, "%08x%08x", (unsigned)(current_test_info.rng_seed>>32),
576 (unsigned)(current_test_info.rng_seed));
579 if( !output_buf[SUMMARY_IDX].empty() )
580 logs += "\n-----------------------------------\n\tSUM: " + output_buf[SUMMARY_IDX];
581 if( !output_buf[LOG_IDX].empty() )
582 logs += "\n-----------------------------------\n\tLOG:\n" + output_buf[LOG_IDX];
583 if( !output_buf[CONSOLE_IDX].empty() )
584 logs += "\n-----------------------------------\n\tCONSOLE: " + output_buf[CONSOLE_IDX];
585 logs += "\n-----------------------------------\n";
587 FAIL() << "\n\tfailure reason: " << str_from_code(code) <<
588 "\n\ttest case #" << current_test_info.test_case_idx <<
589 "\n\tseed: " << seedstr << logs;
593 void TS::update_context( BaseTest* test, int test_case_idx, bool update_ts_context )
595 if( current_test_info.test != test )
597 for( int i = 0; i <= CONSOLE_IDX; i++ )
598 output_buf[i] = string();
599 rng = RNG(params.rng_seed);
600 current_test_info.rng_seed0 = current_test_info.rng_seed = rng.state;
603 current_test_info.test = test;
604 current_test_info.test_case_idx = test_case_idx;
605 current_test_info.code = 0;
606 cvSetErrStatus( CV_StsOk );
607 if( update_ts_context )
608 current_test_info.rng_seed = rng.state;
612 void TS::set_failed_test_info( int fail_code )
614 if( current_test_info.code >= 0 )
615 current_test_info.code = TS::FailureCode(fail_code);
618 #if defined _MSC_VER && _MSC_VER < 1400
620 #define vsnprintf _vsnprintf
623 void TS::vprintf( int streams, const char* fmt, va_list l )
626 vsnprintf( str, sizeof(str)-1, fmt, l );
628 for( int i = 0; i < MAX_IDX; i++ )
629 if( (streams & (1 << i)) )
631 output_buf[i] += std::string(str);
632 // in the new GTest-based framework we do not use
633 // any output files (except for the automatically generated xml report).
634 // if a test fails, all the buffers are printed, so we do not want to duplicate the information and
635 // thus only add the new information to a single buffer and return from the function.
641 void TS::printf( int streams, const char* fmt, ... )
647 vprintf( streams, fmt, l );
659 void fillGradient(Mat& img, int delta)
661 const int ch = img.channels();
662 CV_Assert(!img.empty() && img.depth() == CV_8U && ch <= 4);
666 for(r=0; r<img.rows; r++)
669 int valR = (kR<=n) ? delta*kR : delta*(2*n-kR);
670 for(c=0; c<img.cols; c++)
673 int valC = (kC<=n) ? delta*kC : delta*(2*n-kC);
674 uchar vals[] = {uchar(valR), uchar(valC), uchar(200*r/img.rows), uchar(255)};
675 uchar *p = img.ptr(r, c);
676 for(i=0; i<ch; i++) p[i] = vals[i];
681 void smoothBorder(Mat& img, const Scalar& color, int delta)
683 const int ch = img.channels();
684 CV_Assert(!img.empty() && img.depth() == CV_8U && ch <= 4);
689 int nR = std::min(n, (img.rows+1)/2), nC = std::min(n, (img.cols+1)/2);
694 double k1 = r*delta/100., k2 = 1-k1;
695 for(c=0; c<img.cols; c++)
698 for(i=0; i<ch; i++) s[i] = p[i];
699 s = s * k1 + color * k2;
700 for(i=0; i<ch; i++) p[i] = uchar(s[i]);
702 for(c=0; c<img.cols; c++)
704 p = img.ptr(img.rows-r-1, c);
705 for(i=0; i<ch; i++) s[i] = p[i];
706 s = s * k1 + color * k2;
707 for(i=0; i<ch; i++) p[i] = uchar(s[i]);
711 for(r=0; r<img.rows; r++)
715 double k1 = c*delta/100., k2 = 1-k1;
717 for(i=0; i<ch; i++) s[i] = p[i];
718 s = s * k1 + color * k2;
719 for(i=0; i<ch; i++) p[i] = uchar(s[i]);
723 double k1 = c*delta/100., k2 = 1-k1;
724 p = img.ptr(r, img.cols-c-1);
725 for(i=0; i<ch; i++) s[i] = p[i];
726 s = s * k1 + color * k2;
727 for(i=0; i<ch; i++) p[i] = uchar(s[i]);
733 bool test_ipp_check = false;
735 void checkIppStatus()
739 int status = cv::ipp::getIppStatus();
740 EXPECT_LE(0, status) << cv::ipp::getIppErrorLocation().c_str();
744 static bool checkTestData = false;
745 bool skipUnstableTests = false;
746 bool runBigDataTests = false;
750 static size_t memory_usage_base = 0;
751 static uint64_t memory_usage_base_opencv = 0;
753 static uint64_t memory_usage_base_opencl = 0;
758 fflush(stdout); fflush(stderr);
759 cv::ipp::setIppStatus(0);
760 cv::theRNG().state = cvtest::param_seed;
761 cv::setNumThreads(cvtest::testThreads);
762 if (malloc_peak) // if memory profiler is available
765 memory_usage_base = malloc_peak(); // equal to malloc_current()
768 cv::utils::AllocatorStatisticsInterface& ocv_stats = cv::getAllocatorStatistics();
769 ocv_stats.resetPeakUsage();
770 memory_usage_base_opencv = ocv_stats.getCurrentUsage();
774 cv::utils::AllocatorStatisticsInterface& ocl_stats = cv::ocl::getOpenCLAllocatorStatistics();
775 ocl_stats.resetPeakUsage();
776 memory_usage_base_opencl = ocl_stats.getCurrentUsage();
784 ::cvtest::checkIppStatus();
785 uint64_t memory_usage = 0;
786 uint64_t ocv_memory_usage = 0, ocv_peak = 0;
787 if (malloc_peak) // if memory profiler is available
789 size_t peak = malloc_peak();
790 memory_usage = peak - memory_usage_base;
791 CV_LOG_INFO(NULL, "Memory_usage (malloc): " << memory_usage << " (base=" << memory_usage_base << ")");
794 // core/src/alloc.cpp: #define OPENCV_ALLOC_ENABLE_STATISTICS
795 // handle large buffers via fastAlloc()
796 // (not always accurate on heavy 3rdparty usage, like protobuf)
797 cv::utils::AllocatorStatisticsInterface& ocv_stats = cv::getAllocatorStatistics();
798 ocv_peak = ocv_stats.getPeakUsage();
799 ocv_memory_usage = ocv_peak - memory_usage_base_opencv;
800 CV_LOG_INFO(NULL, "Memory_usage (OpenCV): " << ocv_memory_usage << " (base=" << memory_usage_base_opencv << " current=" << ocv_stats.getCurrentUsage() << ")");
801 if (memory_usage == 0) // external profiler has higher priority (and accuracy)
802 memory_usage = ocv_memory_usage;
805 uint64_t ocl_memory_usage = 0, ocl_peak = 0;
807 cv::utils::AllocatorStatisticsInterface& ocl_stats = cv::ocl::getOpenCLAllocatorStatistics();
808 ocl_peak = ocl_stats.getPeakUsage();
809 ocl_memory_usage = ocl_peak - memory_usage_base_opencl;
810 CV_LOG_INFO(NULL, "Memory_usage (OpenCL): " << ocl_memory_usage << " (base=" << memory_usage_base_opencl << " current=" << ocl_stats.getCurrentUsage() << ")");
811 ::testing::Test::RecordProperty("ocl_memory_usage",
812 cv::format("%llu", (unsigned long long)ocl_memory_usage));
815 uint64_t ocl_memory_usage = 0;
817 if (malloc_peak // external memory profiler is available
818 || ocv_peak > 0 // or enabled OpenCV builtin allocation statistics
821 CV_LOG_INFO(NULL, "Memory usage total: " << (memory_usage + ocl_memory_usage));
822 ::testing::Test::RecordProperty("memory_usage",
823 cv::format("%llu", (unsigned long long)memory_usage));
824 ::testing::Test::RecordProperty("total_memory_usage",
825 cv::format("%llu", (unsigned long long)(memory_usage + ocl_memory_usage)));
829 void parseCustomOptions(int argc, char **argv)
831 const char * const command_line_keys =
832 "{ ipp test_ipp_check |false |check whether IPP works without failures }"
833 "{ test_seed |809564 |seed for random numbers generator }"
834 "{ test_threads |-1 |the number of worker threads, if parallel execution is enabled}"
835 "{ skip_unstable |false |skip unstable tests }"
836 "{ test_bigdata |false |run BigData tests (>=2Gb) }"
837 "{ test_require_data |false |fail on missing non-required test data instead of skip}"
839 "{ h help |false |print help info }"
842 cv::CommandLineParser parser(argc, argv, command_line_keys);
843 if (parser.get<bool>("help"))
845 std::cout << "\nAvailable options besides google test option: \n";
846 parser.printMessage();
849 test_ipp_check = parser.get<bool>("test_ipp_check");
852 test_ipp_check = getenv("OPENCV_IPP_CHECK") != NULL;
854 test_ipp_check = false;
857 param_seed = parser.get<unsigned int>("test_seed");
859 testThreads = parser.get<int>("test_threads");
861 skipUnstableTests = parser.get<bool>("skip_unstable");
862 runBigDataTests = parser.get<bool>("test_bigdata");
863 checkTestData = parser.get<bool>("test_require_data");
865 activateTestTags(parser);
868 static bool isDirectory(const std::string& path)
870 #if defined _WIN32 || defined WINCE
871 WIN32_FILE_ATTRIBUTE_DATA all_attrs;
873 wchar_t wpath[MAX_PATH];
874 size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH);
875 CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
876 BOOL status = ::GetFileAttributesExW(wpath, GetFileExInfoStandard, &all_attrs);
878 BOOL status = ::GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &all_attrs);
880 DWORD attributes = all_attrs.dwFileAttributes;
881 return status && ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
884 if (0 != stat(path.c_str(), &s))
886 return S_ISDIR(s.st_mode);
890 void addDataSearchPath(const std::string& path)
892 if (isDirectory(path))
893 TS::ptr()->data_search_path.push_back(path);
895 void addDataSearchSubDirectory(const std::string& subdir)
897 TS::ptr()->data_search_subdir.push_back(subdir);
900 static std::string findData(const std::string& relative_path, bool required, bool findDirectory)
902 #define TEST_TRY_FILE_WITH_PREFIX(prefix) \
904 std::string path = path_join(prefix, relative_path); \
905 /*printf("Trying %s\n", path.c_str());*/ \
908 if (isDirectory(path)) \
913 FILE* f = fopen(path.c_str(), "rb"); \
921 const std::vector<std::string>& search_path = TS::ptr()->data_search_path;
922 for(size_t i = search_path.size(); i > 0; i--)
924 const std::string& prefix = search_path[i - 1];
925 TEST_TRY_FILE_WITH_PREFIX(prefix);
928 const std::vector<std::string>& search_subdir = TS::ptr()->data_search_subdir;
931 char* datapath_dir = getenv("OPENCV_TEST_DATA_PATH");
933 char* datapath_dir = OPENCV_TEST_DATA_PATH;
936 std::string datapath;
939 datapath = datapath_dir;
940 //CV_Assert(isDirectory(datapath) && "OPENCV_TEST_DATA_PATH is specified but it doesn't exist");
941 if (isDirectory(datapath))
943 for(size_t i = search_subdir.size(); i > 0; i--)
945 const std::string& subdir = search_subdir[i - 1];
946 std::string prefix = path_join(datapath, subdir);
947 TEST_TRY_FILE_WITH_PREFIX(prefix);
951 #ifdef OPENCV_TEST_DATA_INSTALL_PATH
952 datapath = path_join("./", OPENCV_TEST_DATA_INSTALL_PATH);
953 if (isDirectory(datapath))
955 for(size_t i = search_subdir.size(); i > 0; i--)
957 const std::string& subdir = search_subdir[i - 1];
958 std::string prefix = path_join(datapath, subdir);
959 TEST_TRY_FILE_WITH_PREFIX(prefix);
962 #ifdef OPENCV_INSTALL_PREFIX
965 datapath = path_join(OPENCV_INSTALL_PREFIX, OPENCV_TEST_DATA_INSTALL_PATH);
966 if (isDirectory(datapath))
968 for(size_t i = search_subdir.size(); i > 0; i--)
970 const std::string& subdir = search_subdir[i - 1];
971 std::string prefix = path_join(datapath, subdir);
972 TEST_TRY_FILE_WITH_PREFIX(prefix);
978 const char* type = findDirectory ? "directory" : "data file";
979 if (required || checkTestData)
980 CV_Error(cv::Error::StsError, cv::format("OpenCV tests: Can't find required %s: %s", type, relative_path.c_str()));
981 throw SkipTestException(cv::format("OpenCV tests: Can't find %s: %s", type, relative_path.c_str()));
984 std::string findDataFile(const std::string& relative_path, bool required)
986 return findData(relative_path, required, false);
989 std::string findDataDirectory(const std::string& relative_path, bool required)
991 return findData(relative_path, required, true);
994 inline static std::string getSnippetFromConfig(const std::string & start, const std::string & end)
996 const std::string buildInfo = cv::getBuildInformation();
997 size_t pos1 = buildInfo.find(start);
998 if (pos1 != std::string::npos)
1000 pos1 += start.length();
1001 pos1 = buildInfo.find_first_not_of(" \t\n\r", pos1);
1003 size_t pos2 = buildInfo.find(end, pos1);
1004 if (pos2 != std::string::npos)
1006 pos2 = buildInfo.find_last_not_of(" \t\n\r", pos2);
1008 if (pos1 != std::string::npos && pos2 != std::string::npos && pos1 < pos2)
1010 return buildInfo.substr(pos1, pos2 - pos1 + 1);
1012 return std::string();
1015 inline static void recordPropertyVerbose(const std::string & property,
1016 const std::string & msg,
1017 const std::string & value,
1018 const std::string & build_value = std::string())
1020 ::testing::Test::RecordProperty(property, value);
1021 std::cout << msg << ": " << (value.empty() ? std::string("N/A") : value) << std::endl;
1022 if (!build_value.empty())
1024 ::testing::Test::RecordProperty(property + "_build", build_value);
1025 if (build_value != value)
1026 std::cout << "WARNING: build value differs from runtime: " << build_value << endl;
1030 inline static void recordPropertyVerbose(const std::string& property, const std::string& msg,
1031 const char* value, const char* build_value = NULL)
1033 return recordPropertyVerbose(property, msg,
1034 value ? std::string(value) : std::string(),
1035 build_value ? std::string(build_value) : std::string());
1039 #define CV_TEST_BUILD_CONFIG "Debug"
1041 #define CV_TEST_BUILD_CONFIG "Release"
1044 void SystemInfoCollector::OnTestProgramStart(const testing::UnitTest&)
1046 std::cout << "CTEST_FULL_OUTPUT" << std::endl; // Tell CTest not to discard any output
1047 recordPropertyVerbose("cv_version", "OpenCV version", cv::getVersionString(), CV_VERSION);
1048 recordPropertyVerbose("cv_vcs_version", "OpenCV VCS version", getSnippetFromConfig("Version control:", "\n"));
1049 recordPropertyVerbose("cv_build_type", "Build type", getSnippetFromConfig("Configuration:", "\n"), CV_TEST_BUILD_CONFIG);
1050 recordPropertyVerbose("cv_compiler", "Compiler", getSnippetFromConfig("C++ Compiler:", "\n"));
1051 recordPropertyVerbose("cv_parallel_framework", "Parallel framework", cv::currentParallelFramework());
1052 recordPropertyVerbose("cv_cpu_features", "CPU features", cv::getCPUFeaturesLine());
1054 recordPropertyVerbose("cv_ipp_version", "Intel(R) IPP version", cv::ipp::useIPP() ? cv::ipp::getIppVersion() : "disabled");
1057 cv::dumpOpenCLInformation();
1061 } //namespace cvtest