From 03f8be561db31f55449c843b35a2665c865cb988 Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Sat, 24 Aug 2002 04:50:56 +0000 Subject: [PATCH] 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 --- src/tools/cppunit/TestListener.cpp | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/tools/cppunit/TestListener.cpp b/src/tools/cppunit/TestListener.cpp index 08584ff6f9..e394b4cf3a 100644 --- a/src/tools/cppunit/TestListener.cpp +++ b/src/tools/cppunit/TestListener.cpp @@ -4,11 +4,14 @@ #include #include #include +#include +#include void BTestListener::startTest( CppUnit::Test *test ) { fOkay = true; cout << test->getName() << endl; + startTime = real_time_clock_usecs(); } void @@ -25,9 +28,57 @@ BTestListener::addFailure( const CppUnit::TestFailure &failure ) { void BTestListener::endTest( CppUnit::Test *test ) { + bigtime_t length = real_time_clock_usecs() - startTime; if (fOkay) cout << " + PASSED" << endl; // else // cout << " - FAILED" << endl; + printTime(length); 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; + } +}