17 #ifndef PeriodicTask_cpp 18 #define PeriodicTask_cpp 20 #include <cppunit/ui/text/TestRunner.h> 21 #include <cppunit/TextOutputter.h> 22 #include <cppunit/extensions/TestFactoryRegistry.h> 23 #include <cppunit/extensions/HelperMacros.h> 24 #include <cppunit/TestAssert.h> 26 #include <coil/Time.h> 27 #include <coil/PeriodicTask.h> 35 void log(
const std::string& msg)
43 for (
int i = 0; i < (int)
m_log.size(); ++i)
45 if (
m_log[i] == msg) ++count;
64 std::cout <<
"mysvc(): " << cnt << std::endl;
74 m_logger->log(
"mysvc2");
83 m_logger->log(
"mysvc3");
108 :
public CppUnit::TestFixture
112 CPPUNIT_TEST(test_setTask);
113 CPPUNIT_TEST(test_setPeriodic);
114 CPPUNIT_TEST(test_signal);
115 CPPUNIT_TEST(test_executionMeasure);
116 CPPUNIT_TEST(test_periodicMeasure);
117 CPPUNIT_TEST_SUITE_END();
164 for (
int i(0); i < 10; ++i)
167 std::cout <<
"i: " << i << std::endl;
171 std::cout <<
"estat max: " << estat.
max_interval << std::endl;
172 std::cout <<
"estat min: " << estat.
min_interval << std::endl;
173 std::cout <<
"estat mean: " << estat.
mean_interval << std::endl;
174 std::cout <<
"estat sdev: " << estat.
std_deviation << std::endl;
176 std::cout <<
"pstat max: " << pstat.
max_interval << std::endl;
177 std::cout <<
"pstat min: " << pstat.
min_interval << std::endl;
178 std::cout <<
"pstat mean: " << pstat.
mean_interval << std::endl;
179 std::cout <<
"pstat sdev: " << pstat.
std_deviation << std::endl;
184 std::cout <<
"suspended: " << i << std::endl;
189 std::cout <<
"resumed: " << i << std::endl;
193 std::cout <<
"signal: " << i << std::endl;
221 CPPUNIT_ASSERT_EQUAL(0, logger.countLog(
"mysvc2"));
226 CPPUNIT_ASSERT(1<logger.countLog(
"mysvc2"));
236 std::ostringstream ss;
246 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"mysvc2"));
253 CPPUNIT_ASSERT(4>logger.
countLog(
"mysvc2"));
254 CPPUNIT_ASSERT(0<logger.
countLog(
"mysvc2"));
259 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"mysvc2"));
265 CPPUNIT_ASSERT(12>logger.
countLog(
"mysvc2"));
266 CPPUNIT_ASSERT(8<logger.
countLog(
"mysvc2"));
272 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"mysvc2"));
278 CPPUNIT_ASSERT(4>logger.
countLog(
"mysvc2"));
279 CPPUNIT_ASSERT(0<logger.
countLog(
"mysvc2"));
297 CPPUNIT_ASSERT_EQUAL(0, logger.
countLog(
"mysvc2"));
305 CPPUNIT_ASSERT(count == logger.
countLog(
"mysvc2"));
309 CPPUNIT_ASSERT(count+1 == logger.
countLog(
"mysvc2"));
312 CPPUNIT_ASSERT(count+2 == logger.
countLog(
"mysvc2"));
319 CPPUNIT_ASSERT(6>logger.
countLog(
"mysvc2"));
320 CPPUNIT_ASSERT(2<logger.
countLog(
"mysvc2"));
332 std::cout<<
"IN test_executionMeasure()"<<std::endl;
333 const double wait(0.03);
358 std::ostringstream ss;
359 ss <<
"wait: " << wait << std::endl;
365 CPPUNIT_ASSERT_MESSAGE(ss.str(),estat.
max_interval < (wait + 0.030));
366 CPPUNIT_ASSERT_MESSAGE(ss.str(),estat.
min_interval > (wait - 0.015));
367 CPPUNIT_ASSERT_MESSAGE(ss.str(),fabs(estat.
mean_interval - wait) < 0.03);
368 CPPUNIT_ASSERT_MESSAGE(ss.str(),estat.
std_deviation < (wait / 5.0));
386 ss <<
"wait: " << wait << std::endl;
392 CPPUNIT_ASSERT_MESSAGE(ss.str(),estat.
max_interval < (wait + 0.030));
393 CPPUNIT_ASSERT_MESSAGE(ss.str(),estat.
min_interval > (wait - 0.015));
394 CPPUNIT_ASSERT_MESSAGE(ss.str(),fabs(estat.
mean_interval - wait) < 0.03);
395 CPPUNIT_ASSERT_MESSAGE(ss.str(),estat.
std_deviation < (wait / 5.0));
417 std::cout<<
"IN test_periodicMeasure()"<<std::endl;
418 const double wait(0.05);
492 int main(
int argc,
char* argv[])
494 CppUnit::TextUi::TestRunner runner;
495 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
496 CppUnit::Outputter* outputter =
497 new CppUnit::TextOutputter(&runner.result(), std::cout);
498 runner.setOutputter(outputter);
503 #endif // PeriodicTask_cpp
int main(int argc, char **argv)
Structure for time statistics.
virtual void periodicMeasure(bool value)
Validate a Task period time measurement.
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
virtual void executionMeasure(bool value)
Validate a Task execute time measurement.
void log(const std::string &msg)
virtual int resume(void)
Resuming the suspended task.
virtual void activate()
Starting the task.
virtual void periodicMeasureCount(int n)
Task period time measurement count.
void test_periodicMeasure()
periodicMeasureテスト 実行周期は50ms,svcの実行時間は30ms。
static void setLogger(Logger *logger)
virtual void signal()
Executing the suspended task one tick.
virtual TimeMeasure::Statistics getExecStat()
Get a result in task execute time measurement.
void test_executionMeasure()
executionMeasureテスト 実行周期は50ms,svcの実行時間は30ms。
int countLog(const std::string &msg)
void test_setTask()
setTaskテスト
virtual bool setTask(TaskFuncBase *func, bool delete_in_dtor=true)
Setting task execution function.
~PeriodicTaskTests()
Destructor.
PeriodicTaskTests()
Constructor.
virtual void setPeriod(double period)
Setting task execution period.
virtual void executionMeasureCount(int n)
Task execute time measurement period.
virtual void tearDown()
Test finalization.
void test_signal()
signal,suspend,resume,finalizeテスト
::OutPortBase::Logger logger
virtual void finalize()
Finalizing the task.
CPPUNIT_TEST_SUITE_REGISTRATION(PeriodicTask::PeriodicTaskTests)
std::vector< std::string > m_log
virtual TimeMeasure::Statistics getPeriodStat()
Get a result in task period time measurement.
virtual int suspend(void)
Suspending the task.
virtual void setUp()
Test initialization.
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
void test_setPeriodic()
setPeriodicテスト