nrtb-core team mailing list archive
-
nrtb-core team
-
Mailing list archive
-
Message #00140
[Branch ~fpstovall/nrtb/cpp_common] Rev 28: Added minimal automated unit test to build. It's not much, but it will indicate if the timer is w...
------------------------------------------------------------
revno: 28
committer: fpstovall@xxxxxxxxx
branch nick: dev
timestamp: Mon 2011-07-18 20:26:10 -0400
message:
Added minimal automated unit test to build. It's not much, but it will indicate if the timer is working close to right.
modified:
common/timer/Makefile
common/timer/timer_test.cpp
--
lp:~fpstovall/nrtb/cpp_common
https://code.launchpad.net/~fpstovall/nrtb/cpp_common
Your team NRTB Core is subscribed to branch lp:~fpstovall/nrtb/cpp_common.
To unsubscribe from this branch go to https://code.launchpad.net/~fpstovall/nrtb/cpp_common/+edit-subscription
=== modified file 'common/timer/Makefile'
--- common/timer/Makefile 2010-12-25 22:44:22 +0000
+++ common/timer/Makefile 2011-07-19 00:26:10 +0000
@@ -19,6 +19,7 @@
lib: timer_test
@cp -v hires_timer.h ../include
@cp -v hires_timer.o ../obj
+ @./timer_test
@echo build complete
hires_timer.o: hires_timer.h hires_timer.cpp Makefile
=== modified file 'common/timer/timer_test.cpp'
--- common/timer/timer_test.cpp 2010-12-25 22:44:22 +0000
+++ common/timer/timer_test.cpp 2011-07-19 00:26:10 +0000
@@ -28,30 +28,45 @@
{
hirez_timer overall;
hirez_timer interval;
- overall.start();
- interval.start();
- cout << "sleep 1 second" << endl;
- sleep(1);
- cout << overall.interval() << " | " << interval.stop() << " (stop)" << endl;
- cout << "sleep 3 seconds" << endl;
- sleep(3);
- cout << overall.interval() << " | " << interval.stop() << " (start)" << endl;
- interval.start();
- cout << "sleep 2 seconds" << endl;
- sleep(2);
- cout << overall.interval() << " | " << interval.stop() << " (reset)" << endl;
- interval.reset();
- interval.start();
- cout << "sleep 500000 useconds" << endl;
- usleep(500000);
- cout << overall.interval() << " | " << interval.stop() << endl;
- // test the advanced formationg function
- interval.start(109472.34);
- interval.stop();
- cout << "Extended interval_as_HMS() test: \""
- << interval.interval_as_HMS(true)
- << "\" or \"" << interval.interval_as_HMS() << "\"" << endl;
- cout << "Total run time: " << overall.interval() << " seconds." << endl;
- return 0;
+ int returnme = 0;
+ try
+ {
+ overall.start();
+ interval.start();
+ cout << "sleep 1 second" << endl;
+ sleep(1);
+ cout << overall.interval() << " | " << interval.stop() << " (stop)" << endl;
+ cout << "sleep 3 seconds" << endl;
+ sleep(3);
+ cout << overall.interval() << " | " << interval.stop() << " (start)" << endl;
+ interval.start();
+ cout << "sleep 2 seconds" << endl;
+ sleep(2);
+ cout << overall.interval() << " | " << interval.stop() << " (reset)" << endl;
+ interval.reset();
+ interval.start();
+ cout << "sleep 500000 useconds" << endl;
+ usleep(500000);
+ cout << overall.interval() << " | " << interval.stop() << endl;
+ // test the advanced formationg function
+ interval.start(109472.34);
+ interval.stop();
+ cout << "Extended interval_as_HMS() test: \""
+ << interval.interval_as_HMS(true)
+ << "\" or \"" << interval.interval_as_HMS() << "\"" << endl;
+ cout << "Total run time: " << overall.stop() << " seconds." << endl;
+ if ((overall.interval() < 6.5) or (overall.interval() > 6.503))
+ {
+ cerr << "Measured runtime "
+ << overall.interval()
+ << " is outside of expected limits, failed test" << endl;
+ returnme = 1;
+ };
+ }
+ catch (...)
+ {
+ returnme = 1;
+ };
+ return returnme;
};