Added initial timing support. Individual test cases now display run time
information for verbosity >= v2. I'll probably add a command-line toggle specifically for timing info someday. I also hope to add per-test and per-suite run time info eventually as well. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@858 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,11 +4,14 @@
|
|||||||
#include <cppunit/Test.h>
|
#include <cppunit/Test.h>
|
||||||
#include <cppunit/TestFailure.h>
|
#include <cppunit/TestFailure.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
BTestListener::startTest( CppUnit::Test *test ) {
|
BTestListener::startTest( CppUnit::Test *test ) {
|
||||||
fOkay = true;
|
fOkay = true;
|
||||||
cout << test->getName() << endl;
|
cout << test->getName() << endl;
|
||||||
|
startTime = real_time_clock_usecs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -25,9 +28,57 @@ BTestListener::addFailure( const CppUnit::TestFailure &failure ) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
BTestListener::endTest( CppUnit::Test *test ) {
|
BTestListener::endTest( CppUnit::Test *test ) {
|
||||||
|
bigtime_t length = real_time_clock_usecs() - startTime;
|
||||||
if (fOkay)
|
if (fOkay)
|
||||||
cout << " + PASSED" << endl;
|
cout << " + PASSED" << endl;
|
||||||
// else
|
// else
|
||||||
// cout << " - FAILED" << endl;
|
// cout << " - FAILED" << endl;
|
||||||
|
printTime(length);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BTestListener::printTime(bigtime_t time) {
|
||||||
|
// Print out the elapsed time all pretty and stuff:
|
||||||
|
// time >= 1 minute: HH:MM:SS
|
||||||
|
// 1 minute > time: XXX ms
|
||||||
|
const bigtime_t oneMillisecond = 1000;
|
||||||
|
const bigtime_t oneSecond = oneMillisecond*1000;
|
||||||
|
const bigtime_t oneMinute = oneSecond*60;
|
||||||
|
const bigtime_t oneHour = oneMinute*60;
|
||||||
|
const bigtime_t oneDay = oneHour*24;
|
||||||
|
if (time >= oneDay) {
|
||||||
|
cout << " Your test ran for longer than an entire day. Honestly," << endl;
|
||||||
|
cout << " that's 24 hours. That's a long time. Please write shorter" << endl;
|
||||||
|
cout << " tests. Clock time: " << time << " microseconds." << endl;
|
||||||
|
} else {
|
||||||
|
cout << " Clock time: ";
|
||||||
|
if (time >= oneMinute) {
|
||||||
|
bool begun = true;
|
||||||
|
if (begun || time >= oneHour) {
|
||||||
|
begun = true;
|
||||||
|
cout.width(2);
|
||||||
|
cout.fill('0');
|
||||||
|
cout << time / oneHour << ":";
|
||||||
|
time %= oneHour;
|
||||||
|
}
|
||||||
|
if (begun || time >= oneMinute) {
|
||||||
|
begun = true;
|
||||||
|
cout.width(2);
|
||||||
|
cout.fill('0');
|
||||||
|
cout << time / oneMinute << ":";
|
||||||
|
time %= oneMinute;
|
||||||
|
}
|
||||||
|
if (begun || time >= oneSecond) {
|
||||||
|
begun = true;
|
||||||
|
cout.width(2);
|
||||||
|
cout.fill('0');
|
||||||
|
cout << time / oneSecond;
|
||||||
|
time %= oneSecond;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cout << time / oneMillisecond << " ms";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user