Commit e01335bf authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

fixed buffer size and restored the use of compressed files in ml's load_save tests.

parent 4331f76d
...@@ -1551,14 +1551,13 @@ void CvSVM::optimize_linear_svm() ...@@ -1551,14 +1551,13 @@ void CvSVM::optimize_linear_svm()
return; return;
int var_count = get_var_count(); int var_count = get_var_count();
cv::AutoBuffer<double> vbuf; cv::AutoBuffer<double> vbuf(var_count);
double* v = vbuf; double* v = vbuf;
int sample_size = (int)(var_count*sizeof(sv[0][0]));
float** new_sv = (float**)cvMemStorageAlloc(storage, df_count*sizeof(new_sv[0])); float** new_sv = (float**)cvMemStorageAlloc(storage, df_count*sizeof(new_sv[0]));
for( i = 0; i < df_count; i++ ) for( i = 0; i < df_count; i++ )
{ {
new_sv[i] = (float*)cvMemStorageAlloc(storage, sample_size); new_sv[i] = (float*)cvMemStorageAlloc(storage, var_count*sizeof(new_sv[i][0]));
float* dst = new_sv[i]; float* dst = new_sv[i];
memset(v, 0, var_count*sizeof(v[0])); memset(v, 0, var_count*sizeof(v[0]));
int j, k, sv_count = df[i].sv_count; int j, k, sv_count = df[i].sv_count;
......
...@@ -64,11 +64,11 @@ int CV_SLMLTest::run_test_case( int testCaseIdx ) ...@@ -64,11 +64,11 @@ int CV_SLMLTest::run_test_case( int testCaseIdx )
if( code == cvtest::TS::OK ) if( code == cvtest::TS::OK )
{ {
get_error( testCaseIdx, CV_TEST_ERROR, &test_resps1 ); get_error( testCaseIdx, CV_TEST_ERROR, &test_resps1 );
fname1 = tempfile(".yml"); fname1 = tempfile(".yml.gz");
save( fname1.c_str() ); save( fname1.c_str() );
load( fname1.c_str() ); load( fname1.c_str() );
get_error( testCaseIdx, CV_TEST_ERROR, &test_resps2 ); get_error( testCaseIdx, CV_TEST_ERROR, &test_resps2 );
fname2 = tempfile(".yml"); fname2 = tempfile(".yml.gz");
save( fname2.c_str() ); save( fname2.c_str() );
} }
else else
...@@ -82,28 +82,49 @@ int CV_SLMLTest::validate_test_results( int testCaseIdx ) ...@@ -82,28 +82,49 @@ int CV_SLMLTest::validate_test_results( int testCaseIdx )
int code = cvtest::TS::OK; int code = cvtest::TS::OK;
// 1. compare files // 1. compare files
ifstream f1( fname1.c_str() ), f2( fname2.c_str() ); FILE *fs1 = fopen(fname1.c_str(), "rb"), *fs2 = fopen(fname2.c_str(), "rb");
string s1, s2; size_t sz1 = 0, sz2 = 0;
int lineIdx = 1; if( !fs1 || !fs2 )
CV_Assert( f1.is_open() && f2.is_open() ); code = cvtest::TS::FAIL_MISSING_TEST_DATA;
for( ; !f1.eof() && !f2.eof(); lineIdx++ ) if( code >= 0 )
{ {
getline( f1, s1 ); fseek(fs1, 0, SEEK_END); fseek(fs2, 0, SEEK_END);
getline( f2, s2 ); sz1 = ftell(fs1);
if( s1.compare(s2) != 0 ) sz2 = ftell(fs2);
fseek(fs1, 0, SEEK_SET); fseek(fs2, 0, SEEK_SET);
}
if( sz1 != sz2 )
code = cvtest::TS::FAIL_INVALID_OUTPUT;
if( code >= 0 )
{
const int BUFSZ = 1024;
uchar buf1[BUFSZ], buf2[BUFSZ];
for( size_t pos = 0; pos < sz1; )
{ {
ts->printf( cvtest::TS::LOG, size_t r1 = fread(buf1, 1, BUFSZ, fs1);
"in test case %d first (%s) and second (%s) saved files differ in %d-th line:\n%s\n\tvs\n%s\n", size_t r2 = fread(buf2, 1, BUFSZ, fs2);
testCaseIdx, fname1.c_str(), fname2.c_str(), if( r1 != r2 || memcmp(buf1, buf2, r1) != 0 )
lineIdx, s1.empty() ? "" : s1.c_str(), s2.empty() ? "" : s2.c_str() ); {
code = cvtest::TS::FAIL_INVALID_OUTPUT; ts->printf( cvtest::TS::LOG,
break; "in test case %d first (%s) and second (%s) saved files differ in %d-th kb\n",
testCaseIdx, fname1.c_str(), fname2.c_str(),
(int)pos );
code = cvtest::TS::FAIL_INVALID_OUTPUT;
break;
}
pos += r1;
} }
} }
f1.close();
f2.close(); if(fs1)
fclose(fs1);
if(fs2)
fclose(fs2);
// delete temporary files // delete temporary files
if( code == cvtest::TS::OK ) if( code >= 0 )
{ {
remove( fname1.c_str() ); remove( fname1.c_str() );
remove( fname2.c_str() ); remove( fname2.c_str() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment