Changed TestOS_RNG to use a MeterFilter rather than an ArraySink with a NULL array. The NULL array meant ArraySink::Put2 returned early, and it did *not* update m_total. Even if Put2 did not exit early, it still could not update m_total because the bytes were *not* processed. This change was required in preparation for clearing UBsan errors in filters.cpp

pull/35/head
Jeffrey Walton 2015-07-19 07:15:06 -04:00
parent 8c259ee6b4
commit 1026b51922
1 changed files with 21 additions and 21 deletions

View File

@ -271,22 +271,22 @@ bool TestSettings()
bool TestOS_RNG() bool TestOS_RNG()
{ {
bool pass = true; bool pass = true;
member_ptr<RandomNumberGenerator> rng; member_ptr<RandomNumberGenerator> rng;
#ifdef BLOCKING_RNG_AVAILABLE #ifdef BLOCKING_RNG_AVAILABLE
try {rng.reset(new BlockingRng);} try {rng.reset(new BlockingRng);}
catch (OS_RNG_Err &) {} catch (OS_RNG_Err &) {}
#endif #endif
if (rng.get()) if (rng.get())
{ {
cout << "\nTesting operating system provided blocking random number generator...\n\n"; cout << "\nTesting operating system provided blocking random number generator...\n\n";
ArraySink *sink; MeterFilter meter;
RandomNumberSource test(*rng, UINT_MAX, false, new Deflator(sink=new ArraySink(NULL,0))); RandomNumberSource test(*rng, UINT_MAX, false, new Deflator(new Redirector(meter)));
unsigned long total=0, length=0; unsigned long total=0, length=0;
time_t t = time(NULL), t1 = 0; time_t t = time(NULL), t1 = 0;
// check that it doesn't take too long to generate a reasonable amount of randomness // check that it doesn't take too long to generate a reasonable amount of randomness
while (total < 16 && (t1 < 10 || total*8 > (unsigned long)t1)) while (total < 16 && (t1 < 10 || total*8 > (unsigned long)t1))
{ {
@ -294,7 +294,7 @@ bool TestOS_RNG()
total += 1; total += 1;
t1 = time(NULL) - t; t1 = time(NULL) - t;
} }
if (total < 16) if (total < 16)
{ {
cout << "FAILED:"; cout << "FAILED:";
@ -303,7 +303,7 @@ bool TestOS_RNG()
else else
cout << "passed:"; cout << "passed:";
cout << " it took " << long(t1) << " seconds to generate " << total << " bytes" << endl; cout << " it took " << long(t1) << " seconds to generate " << total << " bytes" << endl;
#if 0 // disable this part. it's causing an unpredictable pause during the validation testing #if 0 // disable this part. it's causing an unpredictable pause during the validation testing
if (t1 < 2) if (t1 < 2)
{ {
@ -315,7 +315,7 @@ bool TestOS_RNG()
test.Pump(1); test.Pump(1);
total += 1; total += 1;
} }
// if it generates too many bytes in a certain amount of time, // if it generates too many bytes in a certain amount of time,
// something's probably wrong // something's probably wrong
t = time(NULL); t = time(NULL);
@ -335,46 +335,46 @@ bool TestOS_RNG()
cout << " it generated " << length << " bytes in " << long(time(NULL) - t) << " seconds" << endl; cout << " it generated " << length << " bytes in " << long(time(NULL) - t) << " seconds" << endl;
} }
#endif #endif
test.AttachedTransformation()->MessageEnd(); test.AttachedTransformation()->MessageEnd();
if (sink->TotalPutLength() < total) if (meter.GetTotalBytes() < total)
{ {
cout << "FAILED:"; cout << "FAILED:";
pass = false; pass = false;
} }
else else
cout << "passed:"; cout << "passed:";
cout << " " << total << " generated bytes compressed to " << (size_t)sink->TotalPutLength() << " bytes by DEFLATE" << endl; cout << " " << total << " generated bytes compressed to " << (size_t)meter.GetTotalBytes() << " bytes by DEFLATE" << endl;
} }
else else
cout << "\nNo operating system provided blocking random number generator, skipping test." << endl; cout << "\nNo operating system provided blocking random number generator, skipping test." << endl;
rng.reset(NULL); rng.reset(NULL);
#ifdef NONBLOCKING_RNG_AVAILABLE #ifdef NONBLOCKING_RNG_AVAILABLE
try {rng.reset(new NonblockingRng);} try {rng.reset(new NonblockingRng);}
catch (OS_RNG_Err &) {} catch (OS_RNG_Err &) {}
#endif #endif
if (rng.get()) if (rng.get())
{ {
cout << "\nTesting operating system provided nonblocking random number generator...\n\n"; cout << "\nTesting operating system provided nonblocking random number generator...\n\n";
ArraySink *sink; MeterFilter meter;
RandomNumberSource test(*rng, 100000, true, new Deflator(sink=new ArraySink(NULL, 0))); RandomNumberSource test(*rng, 100000, true, new Deflator(new Redirector(meter)));
if (sink->TotalPutLength() < 100000) if (meter.GetTotalBytes() < 100000)
{ {
cout << "FAILED:"; cout << "FAILED:";
pass = false; pass = false;
} }
else else
cout << "passed:"; cout << "passed:";
cout << " 100000 generated bytes compressed to " << (size_t)sink->TotalPutLength() << " bytes by DEFLATE" << endl; cout << " 100000 generated bytes compressed to " << (size_t)meter.GetTotalBytes() << " bytes by DEFLATE" << endl;
} }
else else
cout << "\nNo operating system provided nonblocking random number generator, skipping test." << endl; cout << "\nNo operating system provided nonblocking random number generator, skipping test." << endl;
return pass; return pass;
} }