26 #include <cppunit/ui/text/TestRunner.h> 27 #include <cppunit/TextOutputter.h> 28 #include <cppunit/extensions/TestFactoryRegistry.h> 29 #include <cppunit/extensions/HelperMacros.h> 30 #include <cppunit/TestAssert.h> 32 #include <coil/Time.h> 33 #include <coil/Task.h> 34 #include <coil/TimeValue.h> 44 :
public CppUnit::TestFixture ,
77 for (ic=0; ic<10; ic++)
92 for (ic=0; ic<10; ic++)
107 for (ic=0; ic<10; ic++)
122 for (ic=0; ic<100; ic++)
186 time_t tmstart, tmend;
199 for(ic=0; ic<10; ic++)
205 if(::difftime(tmend,tmstart)>=1.0)
219 sprintf(cstr,
"main:%d svc:%d", ic, icnt);
221 CPPUNIT_ASSERT_MESSAGE( cstr, (ic == icnt) );
229 for(ic=0; ic<10; ic++)
235 if(::difftime(tmend,tmstart)>=1.0)
249 sprintf(cstr,
"main:%d svc:%d", ic, icnt);
251 CPPUNIT_ASSERT_MESSAGE( cstr, (ic == icnt) );
278 dbcnt = double(end - start) / CLOCKS_PER_SEC;
279 sprintf(cstr,
"time:%f", dbcnt);
280 std::cout<<cstr<<std::endl;
281 CPPUNIT_ASSERT_MESSAGE( cstr, (dbcnt>9.7)&(dbcnt<10.3) );
294 dbcnt = double(end - start) / CLOCKS_PER_SEC;
295 sprintf(cstr,
"time:%f", dbcnt);
296 std::cout<<cstr<<std::endl;
297 CPPUNIT_ASSERT_MESSAGE( cstr, (dbcnt>9.7)&(dbcnt<10.3) );
324 dbcnt = double(end - start) / CLOCKS_PER_SEC;
325 sprintf(cstr,
"time:%f", dbcnt);
326 std::cout<<cstr<<std::endl;
327 CPPUNIT_ASSERT_MESSAGE( cstr, (dbcnt>9.7)&(dbcnt<10.3) );
341 double dbcntmax,dbcntmin,dbcntave;
346 for(icc=0;icc<=10;icc++)
351 for(ic=0;ic<100;ic++)
356 dbcnt = double(end - start) / CLOCKS_PER_SEC;
357 dbcntave = dbcntave + dbcnt;
367 std::cout<<
"sleep :"<<tv<<std::endl;
368 std::cout<<
"sleep time ave :"<<dbcntave/100<<std::endl;
369 std::cout<<
"sleep time max :"<<dbcntmax<<std::endl;
370 std::cout<<
"sleep time min :"<<dbcntmin<<std::endl;
384 time_t tmstart, tmend;
397 for(ic=0; ic<10; ic++)
403 if(::difftime(tmend,tmstart)>=1.0)
417 sprintf(cstr,
"main:%d svc:%d", ic, icnt);
419 CPPUNIT_ASSERT_MESSAGE( cstr, (ic == icnt) );
447 dbcnt = double(end - start) / CLOCKS_PER_SEC;
448 sprintf(cstr,
"time:%f", dbcnt);
449 std::cout<<cstr<<std::endl;
450 CPPUNIT_ASSERT_MESSAGE( cstr, (dbcnt>9.7)&(dbcnt<10.3) );
460 time_t tmstart, tmend;
474 if(::difftime(tmend,tmstart)>=10)
483 sprintf(cstr ,
"sec%ld ",l2-l1);
484 std::cout<<cstr<<std::endl;
485 CPPUNIT_ASSERT_MESSAGE( cstr, (l2- l1)==10 );
496 if((
double)(end-start)/CLOCKS_PER_SEC>0.1)
505 sprintf(cstr ,
"usec%ld ",l2-l1);
506 std::cout<<cstr<<std::endl;
507 CPPUNIT_ASSERT_MESSAGE( cstr, ((l2 - l1)>=80000) & ((l2 - l1)<=120000) );
519 int main(
int argc,
char* argv[])
531 std::string arg(argv[i]);
532 std::string next_arg;
533 if (i + 1 < argc) next_arg = argv[i + 1];
536 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
549 ofs.open(fname.c_str());
551 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
552 if ( arg ==
"--cerr" ) { target = 1;
break; }
553 if ( arg ==
"--xsl" )
555 if (next_arg ==
"") xsl =
"default.xsl";
558 if ( arg ==
"--namespace" )
562 std::cerr <<
"no namespace specified" << std::endl;
572 CppUnit::TextUi::TestRunner runner;
574 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
576 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
577 CppUnit::Outputter* outputter = 0;
578 std::ostream* stream = target ? &std::cerr : &std::cout;
582 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
585 std::cout <<
"XML_OUT" << std::endl;
586 outputter =
new CppUnit::XmlOutputter(&runner.result(),
588 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
591 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
594 runner.setOutputter(outputter);
598 CppUnit::TextUi::TestRunner runner;
599 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
600 CppUnit::Outputter* outputter =
601 new CppUnit::TextOutputter(&runner.result(), std::cout);
602 runner.setOutputter(outputter);
int main(int argc, char **argv)
int svc(void)
Test finalization.
CPPUNIT_TEST_SUITE(TimeTests)
long int sec() const
Get value of second time scale.
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
virtual int wait(void)
Waiting for the thread terminate.
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
virtual void setUp()
Test initialization.
std::string sprintf(char const *__restrict fmt,...)
Convert it into a format given with an argumen.
long int usec() const
Get value of micro second time scale.
CPPUNIT_TEST_SUITE_REGISTRATION(Time::TimeTests)
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
virtual void activate()
Create a thread.