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.
47 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
53 CvTest* CvTest::first = 0;
54 CvTest* CvTest::last = 0;
55 int CvTest::test_count = 0;
57 /*****************************************************************************************\
58 * Exception and memory handlers *
59 \*****************************************************************************************/
61 // a few platform-dependent declarations
63 #define CV_TS_NORMAL 0
68 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
76 static void cv_seh_translator( unsigned int /*u*/, EXCEPTION_POINTERS* pExp )
78 int code = CvTS::FAIL_EXCEPTION;
79 switch( pExp->ExceptionRecord->ExceptionCode )
81 case EXCEPTION_ACCESS_VIOLATION:
82 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
83 case EXCEPTION_DATATYPE_MISALIGNMENT:
84 case EXCEPTION_FLT_STACK_CHECK:
85 case EXCEPTION_STACK_OVERFLOW:
86 case EXCEPTION_IN_PAGE_ERROR:
87 code = CvTS::FAIL_MEMORY_EXCEPTION;
89 case EXCEPTION_FLT_DENORMAL_OPERAND:
90 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
91 case EXCEPTION_FLT_INEXACT_RESULT:
92 case EXCEPTION_FLT_INVALID_OPERATION:
93 case EXCEPTION_FLT_OVERFLOW:
94 case EXCEPTION_FLT_UNDERFLOW:
95 case EXCEPTION_INT_DIVIDE_BY_ZERO:
96 case EXCEPTION_INT_OVERFLOW:
97 code = CvTS::FAIL_ARITHM_EXCEPTION;
99 case EXCEPTION_BREAKPOINT:
100 case EXCEPTION_ILLEGAL_INSTRUCTION:
101 case EXCEPTION_INVALID_DISPOSITION:
102 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
103 case EXCEPTION_PRIV_INSTRUCTION:
104 case EXCEPTION_SINGLE_STEP:
105 code = CvTS::FAIL_EXCEPTION;
111 static void change_color( int color )
113 static int normal_attributes = -1;
114 HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
117 if( normal_attributes < 0 )
119 CONSOLE_SCREEN_BUFFER_INFO info;
120 GetConsoleScreenBufferInfo( hstdout, &info );
121 normal_attributes = info.wAttributes;
124 SetConsoleTextAttribute( hstdout,
125 (WORD)(color == CV_TS_NORMAL ? normal_attributes :
126 ((color & CV_TS_BLUE ? FOREGROUND_BLUE : 0)|
127 (color & CV_TS_GREEN ? FOREGROUND_GREEN : 0)|
128 (color & CV_TS_RED ? FOREGROUND_RED : 0)|FOREGROUND_INTENSITY)) );
135 static const int cv_ts_sig_id[] = { SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGABRT, -1 };
137 static jmp_buf cv_ts_jmp_mark;
139 void cv_signal_handler( int sig_code )
141 int code = CvTS::FAIL_EXCEPTION;
145 code = CvTS::FAIL_ARITHM_EXCEPTION;
149 code = CvTS::FAIL_ARITHM_EXCEPTION;
152 code = CvTS::FAIL_EXCEPTION;
155 longjmp( cv_ts_jmp_mark, code );
158 static void change_color( int color )
160 static const uchar ansi_tab[] = { 30, 34, 32, 36, 31, 35, 33, 37 };
164 if( color != CV_TS_NORMAL )
165 code = ansi_tab[color & (CV_TS_BLUE|CV_TS_GREEN|CV_TS_RED)];
166 sprintf( buf, "\x1b[%dm", code );
167 fputs( buf, stdout );
172 /***************************** memory manager *****************************/
174 typedef struct CvTestAllocBlock
176 struct CvTestAllocBlock* prev;
177 struct CvTestAllocBlock* next;
186 class CvTestMemoryManager
189 CvTestMemoryManager( CvTS* ts );
190 virtual ~CvTestMemoryManager();
192 virtual void clear_and_check( int min_index = -1 );
193 virtual void start_tracking( int index_to_stop_at=-1 );
194 virtual void stop_tracking_and_check();
195 int get_alloc_index() { return index; }
197 static void* alloc_proxy( size_t size, void* userdata );
198 static int free_proxy( void* ptr, void* userdata );
201 virtual void* alloc( size_t size );
202 virtual int free( void* ptr );
203 virtual int free_block( CvTestAllocBlock* block );
208 int index_to_stop_at;
209 const char* guard_pattern;
212 enum { MAX_MARKS = 1024 };
213 int marks[MAX_MARKS];
216 CvTestAllocBlock* first;
217 CvTestAllocBlock* last;
221 void* CvTestMemoryManager::alloc_proxy( size_t size, void* userdata )
223 return ((CvTestMemoryManager*)userdata)->alloc( size );
227 int CvTestMemoryManager::free_proxy( void* ptr, void* userdata )
229 return ((CvTestMemoryManager*)userdata)->free( ptr );
233 CvTestMemoryManager::CvTestMemoryManager( CvTS* _test_system )
236 guard_pattern = "THIS IS A GUARD PATTERN!";
237 guard_size = (int)strlen(guard_pattern);
238 block_align = CV_MALLOC_ALIGN;
243 index_to_stop_at = -1;
248 CvTestMemoryManager::~CvTestMemoryManager()
254 void CvTestMemoryManager::clear_and_check( int min_index )
256 int alloc_index = -1;
257 CvTestAllocBlock* block;
258 int leak_size = 0, leak_block_count = 0, mem_size = 0;
261 while( marks_top > 0 && marks[marks_top - 1] >= min_index )
264 for( block = last; block != 0; )
266 CvTestAllocBlock* prev = block->prev;
267 if( block->index < min_index )
269 leak_size += (int)block->size;
271 alloc_index = block->index;
272 mem_addr = block->data;
273 mem_size = (int)block->size;
278 if( leak_block_count > 0 )
280 ts->set_failed_test_info( CvTS::FAIL_MEMORY_LEAK, alloc_index );
281 ts->printf( CvTS::LOG, "Memory leaks: %u blocks, %u bytes total\n"
282 "%s leaked block: %p, %u bytes\n",
283 leak_block_count, leak_size, leak_block_count > 1 ? "The first" : "The",
284 mem_addr, mem_size );
287 index = block ? block->index + 1 : 0;
291 void CvTestMemoryManager::start_tracking( int _index_to_stop_at )
294 marks[marks_top++] = index;
295 assert( marks_top <= MAX_MARKS );
297 index_to_stop_at = _index_to_stop_at >= index ? _index_to_stop_at : -1;
301 void CvTestMemoryManager::stop_tracking_and_check()
305 int min_index = marks[--marks_top];
306 clear_and_check( min_index );
311 int CvTestMemoryManager::free_block( CvTestAllocBlock* block )
314 char* data = block->data;
316 if( block->origin == 0 || ((size_t)block->origin & (sizeof(double)-1)) != 0 )
317 code = CvTS::FAIL_MEMORY_CORRUPTION_BEGIN;
319 if( memcmp( data - guard_size, guard_pattern, guard_size ) != 0 )
320 code = CvTS::FAIL_MEMORY_CORRUPTION_BEGIN;
321 else if( memcmp( data + block->size, guard_pattern, guard_size ) != 0 )
322 code = CvTS::FAIL_MEMORY_CORRUPTION_END;
327 block->prev->next = block->next;
328 else if( first == block )
332 block->next->prev = block->prev;
333 else if( last == block )
336 free( block->origin );
340 ts->set_failed_test_info( code, block->index );
341 ts->printf( CvTS::LOG, "Corrupted block (%s): %p, %u bytes\n",
342 code == CvTS::FAIL_MEMORY_CORRUPTION_BEGIN ? "beginning" : "end",
343 block->data, block->size );
350 void* CvTestMemoryManager::alloc( size_t size )
353 CvTestAllocBlock* block;
354 size_t new_size = sizeof(*block) + size + guard_size*2 + block_align + sizeof(size_t)*2;
355 char* ptr = (char*)malloc( new_size );
360 data = (char*)cvAlignPtr( ptr + sizeof(size_t) + sizeof(*block) + guard_size, block_align );
361 block = (CvTestAllocBlock*)cvAlignPtr( data - guard_size -
362 sizeof(size_t) - sizeof(*block), sizeof(size_t) );
367 block->next = block->prev = 0;
368 memcpy( data - guard_size, guard_pattern, guard_size );
369 memcpy( data + size, guard_pattern, guard_size );
371 if( track_blocks > 0 )
376 if( index == index_to_stop_at )
380 #if defined WIN32 || defined _WIN32
381 MessageBox( NULL, "The block that is corrupted and/or not deallocated has been just allocated\n"
382 "Press Ok to start debugging", "Memory Manager", MB_ICONERROR|MB_OK|MB_SYSTEMMODAL );
388 block->index = index++;
393 last = last->next = block;
395 first = last = block;
404 int CvTestMemoryManager::free( void* ptr )
406 char* data = (char*)ptr;
407 CvTestAllocBlock* block = (CvTestAllocBlock*)
408 cvAlignPtr( data - guard_size - sizeof(size_t) - sizeof(*block), sizeof(size_t) );
410 int code = free_block( block );
411 if( code < 0 && ts->is_debug_mode() )
417 /***************************** error handler *****************************/
420 static int cvTestErrorCallback( int status, const char* func_name, const char* err_msg,
421 const char* file_name, int line, void* userdata )
423 if( status < 0 && status != CV_StsBackTrace && status != CV_StsAutoTrace )
424 ((CvTS*)userdata)->set_failed_test_info( CvTS::FAIL_ERROR_IN_CALLED_FUNC );
426 // print error message
427 return cvStdErrReport( status, func_name, err_msg, file_name, line, 0 );
431 /*****************************************************************************************\
432 * Base Class for Tests *
433 \*****************************************************************************************/
435 CvTest::CvTest( const char* _test_name, const char* _test_funcs, const char* _test_descr ) :
436 name(_test_name ? _test_name : ""), tested_functions(_test_funcs ? _test_funcs : ""),
437 description(_test_descr ? _test_descr : ""), ts(0)
448 timing_param_names = 0;
449 timing_param_current = 0;
450 timing_param_seqs = 0;
451 timing_param_idxs = 0;
452 timing_param_count = -1;
454 test_case_count = -1;
455 support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
463 CvTest* CvTest::get_first_test()
470 if( timing_param_current )
471 free( timing_param_current );
472 if( timing_param_seqs )
473 free( timing_param_seqs );
474 if( timing_param_idxs )
475 free( timing_param_idxs );
477 timing_param_current = 0;
478 timing_param_seqs = 0;
479 timing_param_idxs = 0;
480 timing_param_count = -1;
484 int CvTest::init( CvTS* _test_system )
488 return read_params( ts->get_file_storage() );
492 const char* CvTest::get_parent_name( const char* name, char* buffer )
494 const char* dash_pos = strrchr( name ? name : "", '-' );
498 if( name != (const char*)buffer )
499 strncpy( buffer, name, dash_pos - name );
500 buffer[dash_pos - name] = '\0';
505 const CvFileNode* CvTest::find_param( CvFileStorage* fs, const char* param_name )
508 const char* name = get_name();
509 CvFileNode* node = 0;
515 node = cvGetFileNodeByName( fs, 0, name );
518 node = cvGetFileNodeByName( fs, node, param_name );
522 name = get_parent_name( name, buffer );
529 void CvTest::start_write_param( CvFileStorage* fs )
533 cvStartWriteStruct( fs, get_name(), CV_NODE_MAP );
539 void CvTest::write_param( CvFileStorage* fs, const char* paramname, int val )
541 if( !ts->find_written_param( this, paramname, CV_NODE_INT, &val) )
543 start_write_param( fs );
544 cvWriteInt( fs, paramname, val );
549 void CvTest::write_param( CvFileStorage* fs, const char* paramname, double val )
551 if( !ts->find_written_param( this, paramname, CV_NODE_REAL, &val) )
553 start_write_param( fs );
554 cvWriteReal( fs, paramname, val );
559 void CvTest::write_param( CvFileStorage* fs, const char* paramname, const char* val )
561 if( !ts->find_written_param( this, paramname, CV_NODE_STRING, &val) )
563 start_write_param( fs );
564 cvWriteString( fs, paramname, val );
569 void CvTest::write_string_list( CvFileStorage* fs, const char* paramname, const char** val, int count )
573 start_write_param( fs );
578 cvStartWriteStruct( fs, paramname, CV_NODE_SEQ + CV_NODE_FLOW );
579 for( i = 0; i < count && val[i] != 0; i++ )
580 cvWriteString( fs, 0, val[i] );
581 cvEndWriteStruct( fs );
586 void CvTest::write_int_list( CvFileStorage* fs, const char* paramname,
587 const int* val, int count, int stop_value )
591 start_write_param( fs );
596 cvStartWriteStruct( fs, paramname, CV_NODE_SEQ + CV_NODE_FLOW );
597 for( i = 0; i < count && val[i] != stop_value; i++ )
598 cvWriteInt( fs, 0, val[i] );
599 cvEndWriteStruct( fs );
604 void CvTest::write_real_list( CvFileStorage* fs, const char* paramname,
605 const double* val, int count, double stop_value )
609 start_write_param( fs );
614 cvStartWriteStruct( fs, paramname, CV_NODE_SEQ + CV_NODE_FLOW );
615 for( i = 0; i < count && val[i] != stop_value; i++ )
616 cvWriteReal( fs, 0, val[i] );
617 cvEndWriteStruct( fs );
622 int CvTest::read_params( CvFileStorage* fs )
626 if(fs == NULL) return code;
628 if( ts->get_testing_mode() == CvTS::TIMING_MODE )
630 timing_param_names = find_param( fs, "timing_params" );
631 if( CV_NODE_IS_SEQ(timing_param_names->tag) )
633 CvSeq* seq = timing_param_names->data.seq;
635 cvStartReadSeq( seq, &reader );
638 timing_param_count = seq->total;
639 timing_param_seqs = (const CvFileNode**)malloc( timing_param_count*sizeof(timing_param_seqs[0]));
640 timing_param_idxs = (int*)malloc( timing_param_count*sizeof(timing_param_idxs[0]));
641 timing_param_current = (const CvFileNode**)malloc( timing_param_count*sizeof(timing_param_current[0]));
644 for( i = 0; i < timing_param_count; i++ )
646 CvFileNode* param_name = (CvFileNode*)(reader.ptr);
648 if( !CV_NODE_IS_STRING(param_name->tag) )
650 ts->printf( CvTS::LOG, "ERROR: name of timing parameter #%d is not a string\n", i );
655 timing_param_idxs[i] = 0;
656 timing_param_current[i] = 0;
657 timing_param_seqs[i] = find_param( fs, param_name->data.str.ptr );
658 if( !timing_param_seqs[i] )
660 ts->printf( CvTS::LOG, "ERROR: timing parameter %s is not found\n", param_name->data.str.ptr );
665 if( CV_NODE_IS_SEQ(timing_param_seqs[i]->tag) )
666 test_case_count *= timing_param_seqs[i]->data.seq->total;
668 CV_NEXT_SEQ_ELEM( seq->elem_size, reader );
671 if( i < timing_param_count )
672 timing_param_count = 0;
676 ts->printf( CvTS::LOG, "ERROR: \"timing_params\" is not found" );
685 int CvTest::get_next_timing_param_tuple()
690 if( timing_param_count <= 0 || !timing_param_names || !timing_param_seqs )
693 increment = timing_param_current[0] != 0; // if already have some valid test tuple, move to the next
694 for( i = 0; i < timing_param_count; i++ )
696 const CvFileNode* node = timing_param_seqs[i];
697 int total = CV_NODE_IS_SEQ(node->tag) ? node->data.seq->total : 1;
698 int new_idx = timing_param_idxs[i];
700 if( !timing_param_current[i] )
701 timing_param_idxs[i] = new_idx = 0;
705 if( new_idx >= total )
711 if( !timing_param_current[i] || new_idx != timing_param_idxs[i] )
713 if( CV_NODE_IS_SEQ(node->tag) )
714 timing_param_current[i] = (CvFileNode*)cvGetSeqElem( node->data.seq, new_idx );
716 timing_param_current[i] = node;
717 timing_param_idxs[i] = new_idx;
721 return !increment; // return 0 in case of overflow (i.e. if there is no more test cases)
725 const CvFileNode* CvTest::find_timing_param( const char* paramname )
727 if( timing_param_names )
731 cvStartReadSeq( timing_param_names->data.seq, &reader, 0 );
733 for( i = 0; i < timing_param_count; i++ )
735 const char* ptr = ((const CvFileNode*)(reader.ptr))->data.str.ptr;
736 if( ptr[0] == paramname[0] && strcmp(ptr, paramname) == 0 )
737 return timing_param_current[i];
738 CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader );
745 int CvTest::write_defaults(CvTS* _ts)
749 write_default_params( ts->get_file_storage() );
751 cvEndWriteStruct( ts->get_file_storage() );
756 int CvTest::write_default_params( CvFileStorage* fs )
758 if( ts->get_testing_mode() == CvTS::TIMING_MODE )
759 write_string_list( fs, "timing_params", default_timing_param_names, timing_param_count );
764 bool CvTest::can_do_fast_forward()
770 int CvTest::get_support_testing_modes()
772 return support_testing_modes;
775 void CvTest::safe_run( int start_from )
777 if(ts->is_debug_mode())
783 #if !defined WIN32 && !defined _WIN32
784 int _code = setjmp( cv_ts_jmp_mark );
793 catch (const cv::Exception& exc)
795 const char* errorStr = cvErrorStr(exc.code);
798 sprintf( buf, "OpenCV Error: %s (%s) in %s, file %s, line %d",
799 errorStr, exc.err.c_str(), exc.func.size() > 0 ?
800 exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line );
801 ts->printf(CvTS::LOG, "%s\n", buf);
802 ts->set_failed_test_info( CvTS::FAIL_ERROR_IN_CALLED_FUNC );
806 ts->set_failed_test_info( CvTS::FAIL_EXCEPTION );
812 void CvTest::run( int start_from )
814 int i, test_case_idx, count = get_test_case_count();
815 int64 t_start = cvGetTickCount();
816 double freq = cv::getTickFrequency();
817 bool ff = can_do_fast_forward();
818 int progress = 0, code;
819 std::vector<double> v_cpe, v_time;
822 for( test_case_idx = ff && start_from >= 0 ? start_from : 0;
823 count < 0 || test_case_idx < count; test_case_idx++ )
825 ts->update_context( this, test_case_idx, ff );
826 progress = update_progress( progress, test_case_idx, count, (double)(t1 - t_start)/(freq*1000) );
828 int64 t00 = 0, t0 = 0, t2 = 0, t3 = 0;
829 double t_acc = 0, t_cpu_acc = 0;
831 if( ts->get_testing_mode() == CvTS::TIMING_MODE )
833 const int iterations = 20;
834 code = prepare_test_case( test_case_idx );
836 if( code < 0 || ts->get_err_code() < 0 )
845 for( i = 0; i < iterations; i++ )
849 t0 = cv::getTickCount();
850 t2 = cv::getCPUTickCount();
852 t3 = cv::getCPUTickCount();
853 t1 = cv::getTickCount();
854 if( ts->get_err_code() < 0 )
857 if( t3 - t2 > 0 && t1 - t0 > 1 )
863 v_cpe.push_back((double)(t3 - t2));
864 v_time.push_back((double)(t1 - t0));
865 if( i >= 5 && t1 - t00 > freq*5 )
869 sort(v_cpe.begin(), v_cpe.end());
870 sort(v_time.begin(), v_time.end());
872 t_cpu_acc = v_cpe[i/2];
874 print_time( test_case_idx, t_acc, t_cpu_acc );
878 code = prepare_test_case( test_case_idx );
879 if( code < 0 || ts->get_err_code() < 0 )
886 if( ts->get_err_code() < 0 )
889 if( validate_test_results( test_case_idx ) < 0 || ts->get_err_code() < 0 )
896 void CvTest::run_func()
902 int CvTest::get_test_case_count()
904 return test_case_count;
908 int CvTest::prepare_test_case( int )
914 int CvTest::validate_test_results( int )
920 void CvTest::print_time( int /*test_case_idx*/, double /*time_usecs*/, double /*time_cpu_clocks*/ )
925 int CvTest::update_progress( int progress, int test_case_idx, int count, double dt )
927 int width = 60 - (int)strlen(get_name());
930 int t = cvRound( ((double)test_case_idx * width)/count );
933 ts->printf( CvTS::CONSOLE, "." );
937 else if( cvRound(dt) > progress )
939 ts->printf( CvTS::CONSOLE, "." );
940 progress = cvRound(dt);
946 /*****************************************************************************************\
947 * Base Class for Test System *
948 \*****************************************************************************************/
950 /******************************** Constructors/Destructors ******************************/
955 version = CV_TS_VERSION;
958 memory_manager = new CvTestMemoryManager(this);
959 cvSetMemoryManager( CvTestMemoryManager::alloc_proxy,
960 CvTestMemoryManager::free_proxy,
962 ostrm_suffixes[SUMMARY_IDX] = ".sum";
963 ostrm_suffixes[LOG_IDX] = ".log";
964 ostrm_suffixes[CSV_IDX] = ".csv";
965 ostrm_suffixes[CONSOLE_IDX] = 0;
967 memset( output_streams, 0, sizeof(output_streams) );
968 memset( ¶ms, 0, sizeof(params) );
969 selected_tests = new CvTestPtrVec();
970 failed_tests = new CvTestInfoVec();
971 written_params = new CvTestPtrVec();
972 logbufsize = 1 << 18; // 256K
974 logbuf = new char[logbufsize];
985 for( test = get_first_test(); test != 0; test = test->get_next() )
988 for( i = 0; i <= CONSOLE_IDX; i++ )
992 else if( i == CONSOLE_IDX )
995 if( i < CONSOLE_IDX && output_streams[i].f )
997 fclose( output_streams[i].f );
998 output_streams[i].f = 0;
1001 if( i == LOG_IDX && output_streams[i].default_handle > 0 )
1003 dup2( output_streams[i].default_handle, 2 );
1004 output_streams[i].default_handle = 0;
1006 output_streams[i].enable = 1;
1008 cvReleaseFileStorage( &fs );
1009 selected_tests->clear();
1010 failed_tests->clear();
1011 if( ostrm_base_name )
1013 free( ostrm_base_name );
1014 ostrm_base_name = 0;
1016 params.rng_seed = (uint64)-1;
1017 params.debug_mode = -1;
1018 params.print_only_failed = 0;
1019 params.skip_header = 0;
1020 params.test_mode = CORRECTNESS_CHECK_MODE;
1021 params.timing_mode = MIN_TIME;
1022 params.use_optimized = -1;
1023 params.color_terminal = 1;
1025 if( memory_manager )
1026 memory_manager->clear_and_check();
1035 if( written_params )
1037 for( int i = 0; i < written_params->size(); i++ )
1038 free( written_params->at(i) );
1039 delete written_params;
1042 delete selected_tests;
1043 delete failed_tests;
1048 const char* CvTS::str_from_code( int code )
1052 case OK: return "Ok";
1053 case FAIL_GENERIC: return "Generic/Unknown";
1054 case FAIL_MISSING_TEST_DATA: return "No test data";
1055 case FAIL_INVALID_TEST_DATA: return "Invalid test data";
1056 case FAIL_ERROR_IN_CALLED_FUNC: return "cvError invoked";
1057 case FAIL_EXCEPTION: return "Hardware/OS exception";
1058 case FAIL_MEMORY_EXCEPTION: return "Invalid memory access";
1059 case FAIL_ARITHM_EXCEPTION: return "Arithmetic exception";
1060 case FAIL_MEMORY_CORRUPTION_BEGIN: return "Corrupted memblock (beginning)";
1061 case FAIL_MEMORY_CORRUPTION_END: return "Corrupted memblock (end)";
1062 case FAIL_MEMORY_LEAK: return "Memory leak";
1063 case FAIL_INVALID_OUTPUT: return "Invalid function output";
1064 case FAIL_MISMATCH: return "Unexpected output";
1065 case FAIL_BAD_ACCURACY: return "Bad accuracy";
1066 case FAIL_HANG: return "Infinite loop(?)";
1067 case FAIL_BAD_ARG_CHECK: return "Incorrect handling of bad arguments";
1068 default: return "Generic/Unknown";
1072 /************************************** Running tests **********************************/
1074 void CvTS::make_output_stream_base_name( const char* config_name )
1076 int k, len = (int)strlen( config_name );
1078 if( ostrm_base_name )
1079 free( ostrm_base_name );
1081 for( k = len-1; k >= 0; k-- )
1083 char c = config_name[k];
1084 if( c == '.' || c == '/' || c == '\\' || c == ':' )
1088 if( k > 0 && config_name[k] == '.' )
1091 ostrm_base_name = (char*)malloc( len + 1 );
1092 memcpy( ostrm_base_name, config_name, len );
1093 ostrm_base_name[len] = '\0';
1097 void CvTS::set_handlers( bool on )
1101 cvSetErrMode( CV_ErrModeParent );
1102 cvRedirectError( cvStdErrReport );
1103 #if defined WIN32 || defined _WIN32
1105 _set_se_translator( cv_seh_translator );
1108 for( int i = 0; cv_ts_sig_id[i] >= 0; i++ )
1109 signal( cv_ts_sig_id[i], cv_signal_handler );
1114 cvSetErrMode( CV_ErrModeLeaf );
1115 cvRedirectError( cvGuiBoxReport );
1116 #if defined WIN32 || defined _WIN32
1118 _set_se_translator( 0 );
1121 for( int i = 0; cv_ts_sig_id[i] >= 0; i++ )
1122 signal( cv_ts_sig_id[i], SIG_DFL );
1128 void CvTS::set_data_path( const char* data_path )
1130 if( data_path == params.data_path )
1133 if( params.data_path )
1134 delete[] params.data_path;
1137 int size = (int)strlen(data_path)+1;
1138 bool append_slash = data_path[size-1] != '/' && data_path[size-1] != '\\';
1139 params.data_path = new char[size+1];
1140 memcpy( params.data_path, data_path, size );
1142 strcat( params.data_path, "/" );
1147 typedef struct CvTsParamVal
1149 const char* fullname;
1154 int CvTS::find_written_param( CvTest* test, const char* paramname, int valtype, const void* val )
1156 const char* testname = test->get_name();
1157 bool add_to_list = test->get_func_list()[0] == '\0';
1159 int paramname_len = (int)strlen(paramname);
1160 int paramval_len = valtype == CV_NODE_INT ? (int)sizeof(int) :
1161 valtype == CV_NODE_REAL ? (int)sizeof(double) : -1;
1162 const char* name = CvTest::get_parent_name( testname, buffer );
1167 if( paramval_len < 0 )
1169 assert(0); // unsupported parameter type
1175 int i, len = (int)strlen(buffer);
1177 memcpy( buffer + len + 1, paramname, paramname_len + 1 );
1178 for( i = 0; i < written_params->size(); i++ )
1180 CvTsParamVal* param = (CvTsParamVal*)written_params->at(i);
1181 if( strcmp( param->fullname, buffer ) == 0 )
1183 if( (paramval_len > 0 && memcmp( param->val, val, paramval_len ) == 0) ||
1184 (paramval_len < 0 && strcmp( (const char*)param->val, (const char*)val ) == 0) )
1189 if( i < written_params->size() )
1192 name = CvTest::get_parent_name( buffer, buffer );
1197 int bufsize, fullname_len = (int)strlen(testname) + paramname_len + 2;
1198 CvTsParamVal* param;
1199 if( paramval_len < 0 )
1200 paramval_len = (int)strlen((const char*)val) + 1;
1201 bufsize = sizeof(*param) + fullname_len + paramval_len;
1202 param = (CvTsParamVal*)malloc(bufsize);
1203 param->fullname = (const char*)(param + 1);
1204 param->val = param->fullname + fullname_len;
1205 sprintf( (char*)param->fullname, "%s.%s", testname, paramname );
1206 memcpy( (void*)param->val, val, paramval_len );
1207 written_params->push( param );
1215 #define MAX_PATH 1024
1218 static int CV_CDECL cmp_test_names( const void* a, const void* b )
1220 return strcmp( (*(const CvTest**)a)->get_name(), (*(const CvTest**)b)->get_name() );
1223 int CvTS::run( int argc, char** argv )
1225 time( &start_time );
1227 int i, write_params = 0;
1229 CvTestPtrVec all_tests;
1232 // 0. reset all the parameters, reorder tests
1235 #if defined WIN32 || defined _WIN32
1236 cv::setBreakOnError(true);
1239 for( test = get_first_test(), i = 0; test != 0; test = test->get_next(), i++ )
1240 all_tests.push(test);
1242 if( all_tests.size() > 0 && all_tests.data() )
1243 qsort( all_tests.data(), all_tests.size(), sizeof(CvTest*), cmp_test_names );
1245 // 1. parse command line options
1246 for( i = 1; i < argc; i++ )
1248 if( strcmp( argv[i], "-h" ) == 0 || strcmp( argv[i], "--help" ) == 0 )
1253 else if( strcmp( argv[i], "-f" ) == 0 )
1254 config_name = argv[++i];
1255 else if( strcmp( argv[i], "-w" ) == 0 )
1257 else if( strcmp( argv[i], "-t" ) == 0 )
1258 params.test_mode = TIMING_MODE;
1259 else if( strcmp( argv[i], "-O0" ) == 0 || strcmp( argv[i], "-O1" ) == 0 )
1260 params.use_optimized = argv[i][2] - '0';
1261 else if( strcmp( argv[i], "-l" ) == 0 )
1263 else if( strcmp( argv[i], "-d" ) == 0 )
1264 set_data_path(argv[++i]);
1265 else if( strcmp( argv[i], "-nc" ) == 0 )
1266 params.color_terminal = 0;
1267 else if( strcmp( argv[i], "-r" ) == 0 )
1268 params.debug_mode = 0;
1269 else if( strcmp( argv[i], "-tn" ) == 0 )
1271 params.test_filter_pattern = argv[++i];
1272 params.test_filter_mode = CHOOSE_TESTS;
1277 //#if !defined WIN32 && !defined _WIN32
1280 char * confname = getenv("configname");
1282 config_name = confname;
1285 if( !params.data_path || !params.data_path[0] )
1287 char* datapath = getenv("datapath");
1289 set_data_path(datapath);
1292 // this is the fallback for the current OpenCV autotools setup
1293 if( !params.data_path || !params.data_path[0] )
1295 char* srcdir = getenv("srcdir");
1299 sprintf( buf, "%s/../../opencv_extra/testdata/", srcdir );
1309 printf( LOG, "ERROR: output config name is not specified\n" );
1312 fs = cvOpenFileStorage( config_name, 0, CV_STORAGE_WRITE );
1315 printf( LOG, "ERROR: could not open config file %s\n", config_name );
1318 cvWriteComment( fs, CV_TS_VERSION " config file", 0 );
1319 cvStartWriteStruct( fs, "common", CV_NODE_MAP );
1320 write_default_params( fs );
1321 cvEndWriteStruct( fs );
1323 for( i = 0; i < all_tests.size(); i++ )
1325 test = (CvTest*)all_tests[i];
1326 if( !(test->get_support_testing_modes() & get_testing_mode()) )
1328 test->write_defaults( this );
1331 cvReleaseFileStorage( &fs );
1336 printf( LOG, "WARNING: config name is not specified, using default parameters\n" );
1339 // 2. read common parameters of test system
1340 fs = cvOpenFileStorage( config_name, 0, CV_STORAGE_READ );
1343 printf( LOG, "ERROR: could not open config file %s", config_name );
1348 if( params.test_mode == CORRECTNESS_CHECK_MODE || fs )
1350 // in the case of algorithmic tests we always run read_params,
1351 // even if there is no config file
1352 if( read_params(fs) < 0 )
1356 if( !ostrm_base_name )
1357 make_output_stream_base_name( config_name ? config_name : argv[0] );
1359 ostream_testname_mask = -1; // disable printing test names at initial stage
1361 // 3. open file streams
1362 for( i = 0; i < CONSOLE_IDX; i++ )
1364 char filename[MAX_PATH];
1365 sprintf( filename, "%s%s", ostrm_base_name, ostrm_suffixes[i] );
1366 output_streams[i].f = fopen( filename, "wt" );
1367 if( !output_streams[i].f )
1369 printf( LOG, "ERROR: could not open %s\n", filename );
1375 // redirect stderr to log file
1377 output_streams[i].default_handle = dup(2);
1378 dup2( fileno(output_streams[i].f), 2 );
1382 // 4. traverse through the list of all registered tests.
1383 // Initialize the selected tests and put them into the separate sequence
1384 for( i = 0; i < all_tests.size(); i++ )
1386 test = (CvTest*)all_tests[i];
1387 if( !(test->get_support_testing_modes() & get_testing_mode()) )
1390 if( strcmp( test->get_func_list(), "" ) != 0 && filter(test) )
1392 if( test->init(this) >= 0 )
1394 selected_tests->push( test );
1396 ::printf( "%s\n", test->get_name() );
1399 printf( LOG, "WARNING: an error occured during test %s initialization\n", test->get_name() );
1409 // 5. setup all the neccessary handlers and print header
1410 set_handlers( !params.debug_mode );
1412 if( params.use_optimized == 0 )
1415 if( !params.skip_header )
1416 print_summary_header( SUMMARY + LOG + CONSOLE + CSV );
1417 rng = params.rng_seed;
1418 update_context( 0, -1, true );
1420 // 6. run all the tests
1421 for( i = 0; i < selected_tests->size(); i++ )
1423 CvTest* test = (CvTest*)selected_tests->at(i);
1427 if( memory_manager )
1428 memory_manager->start_tracking();
1429 update_context( test, -1, true );
1430 current_test_info.rng_seed0 = current_test_info.rng_seed;
1432 ostream_testname_mask = 0; // reset "test name was printed" flags
1434 if( output_streams[LOG_IDX].f )
1435 fflush( output_streams[LOG_IDX].f );
1437 temp = current_test_info;
1439 if( get_err_code() >= 0 )
1441 update_context( test, -1, false );
1442 current_test_info.rng_seed = temp.rng_seed;
1443 current_test_info.base_alloc_index = temp.base_alloc_index;
1446 if( memory_manager )
1447 memory_manager->stop_tracking_and_check();
1449 code = get_err_code();
1452 if( !params.print_only_failed )
1454 printf( SUMMARY + CONSOLE, "\t" );
1455 set_color( CV_TS_GREEN );
1456 printf( SUMMARY + CONSOLE, "Ok\n" );
1457 set_color( CV_TS_NORMAL );
1462 printf( SUMMARY + CONSOLE, "\t" );
1463 set_color( CV_TS_RED );
1464 printf( SUMMARY + CONSOLE, "FAIL(%s)\n", str_from_code(code) );
1465 set_color( CV_TS_NORMAL );
1466 printf( LOG, "context: test case = %d, seed = %08x%08x\n",
1467 current_test_info.test_case_idx,
1468 (unsigned)(current_test_info.rng_seed>>32),
1469 (unsigned)(current_test_info.rng_seed));
1472 logbuf[logbufpos] = '\0';
1473 printf( SUMMARY + CONSOLE, ">>>\n%s\n", logbuf);
1475 failed_tests->push(current_test_info);
1476 if( params.rerun_immediately )
1481 ostream_testname_mask = -1;
1482 print_summary_tailer( SUMMARY + CONSOLE + LOG );
1484 if( !params.debug_mode && (params.rerun_failed || params.rerun_immediately) )
1487 update_context( 0, -1, true );
1488 for( i = 0; i < failed_tests->size(); i++ )
1490 CvTestInfo info = failed_tests->at(i);
1491 if( (info.code == FAIL_MEMORY_CORRUPTION_BEGIN ||
1492 info.code == FAIL_MEMORY_CORRUPTION_END ||
1493 info.code == FAIL_MEMORY_LEAK) && memory_manager )
1494 memory_manager->start_tracking( info.alloc_index - info.base_alloc_index
1495 + memory_manager->get_alloc_index() );
1496 rng = info.rng_seed;
1497 test->safe_run( info.test_case_idx );
1500 int nfailed = failed_tests ? (int)failed_tests->size() : 0;
1507 void CvTS::print_help()
1510 "Usage: <test_executable> [{-h|--help}][-l] [-r] [-w] [-t] [-f <config_name>] [-d <data_path>] [-O{0|1}]\n\n"
1511 "-d - specify the test data path\n"
1512 "-f - use parameters from the provided XML/YAML config file\n"
1513 " instead of the default parameters\n"
1514 "-h or --help - print this help information\n"
1515 "-l - list all the registered tests or subset of the tests,\n"
1516 " selected in the config file, and exit\n"
1517 "-nc - do not use colors in the console output\n"
1518 "-O{0|1} - disable/enable on-fly detection of IPP and other\n"
1519 " supported optimized libs. It's enabled by default\n"
1520 "-r - continue running tests after OS/Hardware exception occured\n"
1521 "-t - switch to the performance testing mode instead of\n"
1522 " the default algorithmic/correctness testing mode\n"
1523 "-w - write default parameters of the algorithmic or\n"
1524 " performance (when -t is passed) tests to the specifed\n"
1525 " config file (see -f) and exit\n\n"
1526 //"Test data path and config file can also be specified by the environment variables 'config' and 'datapath'.\n\n"
1531 #if defined WIN32 || defined _WIN32
1532 const char* default_data_path = "../tests/cv/testdata/";
1534 const char* default_data_path = "../../../../tests/cv/testdata/";
1538 int CvTS::read_params( CvFileStorage* fs )
1540 CvFileNode* node = fs ? cvGetFileNodeByName( fs, 0, "common" ) : 0;
1541 if(params.debug_mode < 0)
1542 params.debug_mode = cvReadIntByName( fs, node, "debug_mode", 1 ) != 0;
1543 params.skip_header = cvReadIntByName( fs, node, "skip_header", 0 ) != 0;
1544 params.print_only_failed = cvReadIntByName( fs, node, "print_only_failed", 0 ) != 0;
1545 params.rerun_failed = cvReadIntByName( fs, node, "rerun_failed", 0 ) != 0;
1546 params.rerun_immediately = cvReadIntByName( fs, node, "rerun_immediately", 0 ) != 0;
1547 const char* str = cvReadStringByName( fs, node, "filter_mode", "tests" );
1548 params.test_filter_mode = strcmp( str, "functions" ) == 0 ? CHOOSE_FUNCTIONS : CHOOSE_TESTS;
1549 str = cvReadStringByName( fs, node, "test_mode", params.test_mode == TIMING_MODE ? "timing" : "correctness" );
1550 params.test_mode = strcmp( str, "timing" ) == 0 || strcmp( str, "performance" ) == 0 ?
1551 TIMING_MODE : CORRECTNESS_CHECK_MODE;
1552 str = cvReadStringByName( fs, node, "timing_mode", params.timing_mode == AVG_TIME ? "avg" : "min" );
1553 params.timing_mode = strcmp( str, "average" ) == 0 || strcmp( str, "avg" ) == 0 ? AVG_TIME : MIN_TIME;
1554 params.test_filter_pattern = cvReadStringByName( fs, node, params.test_filter_mode == CHOOSE_FUNCTIONS ?
1555 "functions" : "tests", "" );
1556 params.resource_path = cvReadStringByName( fs, node, "." );
1557 if( params.use_optimized < 0 )
1558 params.use_optimized = cvReadIntByName( fs, node, "use_optimized", -1 );
1559 if( !params.data_path || !params.data_path[0] )
1561 const char* data_path =
1562 cvReadStringByName( fs, node, "data_path", default_data_path );
1563 set_data_path(data_path);
1565 params.test_case_count_scale = cvReadRealByName( fs, node, "test_case_count_scale", 1. );
1566 if( params.test_case_count_scale <= 0 )
1567 params.test_case_count_scale = 1.;
1568 str = cvReadStringByName( fs, node, "seed", 0 );
1569 params.rng_seed = 0;
1570 if( str && strlen(str) == 16 )
1572 params.rng_seed = 0;
1573 for( int i = 0; i < 16; i++ )
1575 int c = tolower(str[i]);
1578 params.rng_seed = 0;
1581 params.rng_seed = params.rng_seed * 16 +
1582 (str[i] < 'a' ? str[i] - '0' : str[i] - 'a' + 10);
1586 if( params.rng_seed == 0 )
1587 params.rng_seed = cvGetTickCount();
1589 str = cvReadStringByName( fs, node, "output_file_base_name", 0 );
1591 make_output_stream_base_name( str );
1597 void CvTS::write_default_params( CvFileStorage* fs )
1599 read_params(0); // fill parameters with default values
1601 cvWriteInt( fs, "debug_mode", params.debug_mode );
1602 cvWriteInt( fs, "skip_header", params.skip_header );
1603 cvWriteInt( fs, "print_only_failed", params.print_only_failed );
1604 cvWriteInt( fs, "rerun_failed", params.rerun_failed );
1605 cvWriteInt( fs, "rerun_immediately", params.rerun_immediately );
1606 cvWriteString( fs, "filter_mode", params.test_filter_mode == CHOOSE_FUNCTIONS ? "functions" : "tests" );
1607 cvWriteString( fs, "test_mode", params.test_mode == TIMING_MODE ? "timing" : "correctness" );
1608 cvWriteString( fs, "data_path", params.data_path ? params.data_path : default_data_path, 1 );
1609 if( params.test_mode == TIMING_MODE )
1610 cvWriteString( fs, "timing_mode", params.timing_mode == AVG_TIME ? "avg" : "min" );
1611 // test_filter, seed & output_file_base_name are not written
1615 void CvTS::enable_output_streams( int stream_mask, int value )
1617 for( int i = 0; i < MAX_IDX; i++ )
1618 if( stream_mask & (1 << i) )
1619 output_streams[i].enable = value != 0;
1623 void CvTS::update_context( CvTest* test, int test_case_idx, bool update_ts_context )
1625 current_test_info.test = test;
1626 current_test_info.test_case_idx = test_case_idx;
1627 current_test_info.alloc_index = 0;
1628 current_test_info.code = 0;
1629 cvSetErrStatus( CV_StsOk );
1630 if( update_ts_context )
1632 current_test_info.rng_seed = rng;
1633 current_test_info.base_alloc_index = memory_manager ?
1634 memory_manager->get_alloc_index() : 0;
1639 void CvTS::set_failed_test_info( int fail_code, int alloc_index )
1641 if( fail_code == FAIL_MEMORY_CORRUPTION_BEGIN ||
1642 fail_code == FAIL_MEMORY_CORRUPTION_END ||
1643 current_test_info.code >= 0 )
1645 current_test_info.code = fail_code;
1646 current_test_info.alloc_index = alloc_index;
1651 const char* CvTS::get_libs_info( const char** addon_modules )
1653 const char* all_info = 0;
1654 cvGetModuleInfo( 0, &all_info, addon_modules );
1659 void CvTS::print_summary_header( int streams )
1661 char csv_header[256], *ptr = csv_header;
1664 printf( streams, "Engine: %s\n", version );
1667 struct tm *t2 = localtime( &t1 );
1669 strftime( buf, sizeof(buf)-1, "%c", t2 );
1670 printf( streams, "Execution Date & Time: %s\n", buf );
1671 printf( streams, "Config File: %s\n", config_name );
1672 const char* plugins = 0;
1673 const char* lib_verinfo = get_libs_info( &plugins );
1674 printf( streams, "Tested Libraries: %s\n", lib_verinfo );
1675 printf( streams, "Optimized Low-level Plugin\'s: %s\n", plugins );
1676 printf( streams, "=================================================\n");
1678 sprintf( ptr, "funcName,dataType,channels,size," );
1681 for( i = 0; i < CvTest::TIMING_EXTRA_PARAMS; i++ )
1683 sprintf( ptr, "param%d,", i );
1687 sprintf( ptr, "CPE,Time(uSecs)" );
1688 printf( CSV, "%s\n", csv_header );
1692 void CvTS::print_summary_tailer( int streams )
1694 printf( streams, "=================================================\n");
1695 if( selected_tests && failed_tests )
1699 double total_time = difftime( end_time, start_time );
1700 printf( streams, "Summary: %d out of %d tests failed\n",
1701 failed_tests->size(), selected_tests->size() );
1702 int minutes = cvFloor(total_time/60.);
1703 int seconds = cvRound(total_time - minutes*60);
1704 int hours = minutes / 60;
1706 printf( streams, "Running time: %02d:%02d:%02d\n", hours, minutes, seconds );
1711 void CvTS::vprintf( int streams, const char* fmt, va_list l )
1716 vsprintf( str, fmt, l );
1718 for( int i = 0; i < MAX_IDX; i++ )
1720 if( (streams & (1 << i)) && output_streams[i].enable )
1722 FILE* f = i == CONSOLE_IDX ? stdout :
1723 i == LOG_IDX ? stderr : output_streams[i].f;
1726 if( i != CSV_IDX && !(ostream_testname_mask & (1 << i)) && current_test_info.test )
1728 fprintf( f, "-------------------------------------------------\n" );
1729 if( i == CONSOLE_IDX || i == SUMMARY_IDX )
1730 fprintf( f, "[%08x%08x]\n", (int)(current_test_info.rng_seed0 >> 32),
1731 (int)(current_test_info.rng_seed0));
1732 fprintf( f, "%s: ", current_test_info.test->get_name() );
1734 ostream_testname_mask |= 1 << i;
1741 size_t len = strlen(str);
1742 CV_Assert(logbufpos + len < logbufsize);
1743 strcpy(logbuf + logbufpos, str);
1746 if( i == CONSOLE_IDX )
1755 void CvTS::printf( int streams, const char* fmt, ... )
1761 vprintf( streams, fmt, l );
1766 void CvTS::set_color(int color)
1768 if( params.color_terminal )
1769 change_color(color);
1772 static char* cv_strnstr( const char* str, int len,
1773 const char* pattern,
1774 int pattern_len = -1,
1775 int whole_word = 1 )
1779 if( len < 0 && pattern_len < 0 )
1780 return (char*)strstr( str, pattern );
1783 len = (int)strlen( str );
1785 if( pattern_len < 0 )
1786 pattern_len = (int)strlen( pattern );
1788 for( i = 0; i < len - pattern_len + 1; i++ )
1790 int j = i + pattern_len;
1791 if( str[i] == pattern[0] &&
1792 memcmp( str + i, pattern, pattern_len ) == 0 &&
1794 ((i == 0 || (!isalnum(str[i-1]) && str[i-1] != '_')) &&
1795 (j == len || (!isalnum(str[j]) && str[j] != '_')))))
1796 return (char*)(str + i);
1803 int CvTS::filter( CvTest* test )
1805 const char* pattern = params.test_filter_pattern;
1808 if( pattern && pattern[0] == '!' )
1814 if( !pattern || strcmp( pattern, "" ) == 0 || strcmp( pattern, "*" ) == 0 )
1817 if( params.test_filter_mode == CHOOSE_TESTS )
1821 while( pattern && *pattern )
1823 char *ptr, *endptr = (char*)strchr( pattern, ',' );
1824 int len, have_wildcard;
1830 ptr = (char*)strchr( pattern, '*' );
1833 len = (int)(ptr - pattern);
1838 len = (int)strlen( pattern );
1842 t_name_len = (int)strlen( test->get_name() );
1843 found = (t_name_len == len || (have_wildcard && t_name_len > len)) &&
1844 (len == 0 || memcmp( test->get_name(), pattern, len ) == 0);
1848 pattern = endptr + 1;
1849 while( isspace(*pattern) )
1853 if( found || !endptr )
1857 return found ^ inverse;
1861 assert( params.test_filter_mode == CHOOSE_FUNCTIONS );
1862 int glob_len = (int)strlen( pattern );
1863 const char* ptr = test->get_func_list();
1864 const char *tmp_ptr;
1866 while( ptr && *ptr )
1868 const char* endptr = ptr - 1;
1869 const char* name_ptr;
1870 const char* name_first_match;
1875 while( isspace(c) );
1880 assert( isalpha(c) );
1884 while( isalnum(c) || c == '_' );
1886 if( c == ':' ) // class
1888 assert( endptr[1] == ':' );
1889 endptr = endptr + 2;
1890 name_len = (int)(endptr - name_ptr);
1892 // find the first occurence of the class name
1894 name_first_match = cv_strnstr( pattern,
1895 glob_len, name_ptr, name_len, 1 );
1897 if( *endptr == '*' )
1899 if( name_first_match )
1904 assert( *endptr == '{' ); // a list of methods
1906 if( !name_first_match )
1908 // skip all the methods, if there is no such a class name
1910 endptr = strchr( endptr, '}' );
1911 assert( endptr != 0 );
1917 const char* method_name_ptr;
1918 int method_name_len;
1921 while( isspace(c) );
1925 assert( isalpha(c) );
1927 method_name_ptr = endptr;
1930 while( isalnum(c) || c == '_' );
1932 method_name_len = (int)(endptr - method_name_ptr);
1934 // search for class_name::* or
1935 // class_name::{...method_name...}
1936 tmp_ptr = name_first_match;
1939 const char* tmp_ptr2;
1940 tmp_ptr += name_len;
1941 if( *tmp_ptr == '*' )
1943 assert( *tmp_ptr == '{' );
1944 tmp_ptr2 = strchr( tmp_ptr, '}' );
1947 if( cv_strnstr( tmp_ptr, (int)(tmp_ptr2 - tmp_ptr) + 1,
1948 method_name_ptr, method_name_len, 1 ))
1951 tmp_ptr = cv_strnstr( tmp_ptr2, glob_len -
1952 (int)(tmp_ptr2 - pattern),
1953 name_ptr, name_len, 1 );
1959 while( isspace(c) );
1968 assert( !c || isspace(c) || c == ',' );
1969 name_len = (int)(endptr - name_ptr);
1974 const char *tmp_ptr2, *tmp_ptr3;
1976 tmp_ptr = cv_strnstr( tmp_ptr, glob_len -
1977 (int)(tmp_ptr - pattern), name_ptr, name_len, 1 );
1982 // make sure it is not a method
1983 tmp_ptr2 = strchr( tmp_ptr, '}' );
1987 tmp_ptr3 = strchr( tmp_ptr, '{' );
1988 if( tmp_ptr3 < tmp_ptr2 )
1991 tmp_ptr = tmp_ptr2 + 1;
1998 while( isspace(c) );