tasks_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 10 15:59:49 CET 2005 tasks_test.cpp
3 
4  tasks_test.cpp - description
5  -------------------
6  begin : Mon January 10 2005
7  copyright : (C) 2005 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 #include "unit.hpp"
21 
22 #include "tasks_test.hpp"
23 
24 #include <cstdlib>
25 #include <cstring>
26 #include <iostream>
27 #include <vector>
28 
30 #include <os/TimeService.hpp>
31 #include <Logger.hpp>
32 
33 #include <boost/scoped_ptr.hpp>
34 
35 using namespace std;
36 using namespace boost;
37 using namespace RTT;
38 using namespace RTT::detail;
39 
40 #define BOOST_CHECK_EQUAL_MESSAGE(v1, v2, M) BOOST_CHECK_MESSAGE( v1==v2, M)
41 #define BOOST_REQUIRE_EQUAL_MESSAGE(v1, v2, M) BOOST_REQUIRE_MESSAGE( v1==v2, M)
42 
44  : public RunnableInterface
45 {
47  bool fini;
48  std::vector<nsecs> wakeup_time; // record wakeup times
49  std::vector<nsecs> additional_sleep_time; // sleep ... additional nsecs in cycle i
50  unsigned int cycle;
51 
53  : sleep_time(Seconds_to_nsecs(0.2)), fini(false), wakeup_time(3), additional_sleep_time(), cycle(0)
54  {
55  }
56 
57  bool initialize() {
58  sleep_time = Seconds_to_nsecs(0.2);
59  fini = false;
60  wakeup_time.assign(wakeup_time.size(), 0);
61  cycle = 0;
62  return true;
63  }
64 
65  void step() {
66  if (cycle < wakeup_time.size())
67  {
68  wakeup_time[cycle] = os::TimeService::Instance()->getNSecs();
69  }
70  if (cycle < additional_sleep_time.size() && additional_sleep_time[cycle] > 0) {
71  usleep(additional_sleep_time[cycle]/1000);
72  }
73  ++cycle;
74 
75  //requires that getPeriod() << sleep_time
76  usleep(sleep_time/1000);
77  // Tried to implement it like this for Xenomai, but the
78  // underlying rt_task_sleep function always returns immediately
79  // and returns zero (success). A plain usleep still works.
80 #if 0
81  TIME_SPEC timevl;
82  timevl = ticks2timespec( nano2ticks(sleep_time) );
83  rtos_nanosleep( &timevl, 0);
84 #endif
85  }
86 
87  void finalize() {
88  fini = true;
89  }
90 };
91 
93  : public RunnableInterface
94 {
95  int overfail, underfail, succ;
96  bool stepped;
97 
99  // LINUX: cpu of last step(), 0 if not yet set
100  // non-LINUX: 0
101  int cpu;
102 
104  : overfail(0), underfail(0), succ(0), stepped(false), cpu(0)
105  {
106  }
107 
108  bool initialize() {
109  this->reset();
110  return true;
111  }
112  void step() {
113  if (stepped == false ) {
114  ts = TimeService::Instance()->getTicks();
115  stepped = true;
116  } else {
117  TimeService::Seconds s = TimeService::Instance()->secondsSince( ts );
118  if ( s < this->getThread()->getPeriod() *0.9 ) { // if elapsed time is smaller than 10% of period, something went wrong
119  ++underfail;
120  //rtos_printf("UnderFailPeriod: %f \n", s);
121  }
122  else if ( s > this->getThread()->getPeriod() *1.1 ) { // if elapsed time is smaller than 10% of period, something went wrong
123  ++overfail;
124  //rtos_printf("OverFailPeriod: %f \n", s);
125  }
126  else {
127  ++succ;
128  //rtos_printf("SuccPeriod: %f \n", s);
129  }
130  ts = TimeService::Instance()->getTicks();
131  }
132 #if defined( OROCOS_TARGET_GNULINUX )
133  cpu = sched_getcpu();
134  BOOST_REQUIRE_NE(ENOSYS, cpu);
135 #endif
136  }
137  void finalize() {
138  if (overfail || underfail)
139  cerr <<"overfail is:"<<overfail<<", underfail is:"<<underfail<< " success is: "<<succ<<endl;
140  }
141 
142  void reset() {
143  overfail = 0;
144  underfail = 0;
145  succ = 0;
146  cpu = 0;
147  stepped = false;
148  }
149 };
150 
152  : public RunnableInterface
153 {
154  bool result, breakl;
155  bool init, stepped, looped, fini;
156 
158  {
159  this->reset(res);
160  }
161 
162  bool initialize() {
163  init = true;
164  return result;
165  }
166  void step() {
167  stepped = true;
168  }
169  void finalize() {
170  fini = true;
171  }
172 
173  void loop() {
174  looped = true;
175  while (breakl == false) {
176  usleep(500*1000);
177  }
178  }
179 
180  bool breakLoop() {
181  return breakl;
182  }
183 
184  void reset(bool res) {
185  result = res;
186  init = false;
187  stepped = false;
188  fini = false;
189  looped = false;
190  breakl = true;
191  }
192 };
193 
195  : public RunnableInterface
196 {
197  std::vector<std::string> v;
198  char* c;
199  std::string s;
200 
201  bool initialize() {
202  c = 0;
203  return true;
204  }
205  void step() {
206  v.resize( 0 );
207  v.resize( 1025, std::string("Goodbye Memory") );
208  delete[] c;
209  c = new char[1025];
210  s = "Hello World ";
211  s += s;
212  s += s;
213  }
214  void finalize() {
215  delete[] c;
216  v.resize(0);
217  }
218 };
219 
224  : public RunnableInterface
225 {
226  int c;
227  bool fini;
228  bool breakl;
229  bool initialize() {
230  c = 0;
231  fini = false;
232  breakl = true;
233  return true;
234  }
235  bool breakLoop() {
236  return breakl;
237  }
238  void loop() {
239  this->getActivity()->stop();
240  }
241  void step() {
242  ++c;
243  if (c == 5)
244  this->getActivity()->stop();
245  }
246  void finalize() {
247  fini = true;
248  }
249 };
250 
251 void
253 {
254  periodic_act = new PeriodicActivity( 15, 0.01 );
255  t_act = new Activity(15, 0.01);
256 
257  t_run_int_prio = new TestRunnableInterface(true);
258  t_run_int_act = new TestRunnableInterface(true);
259  t_run_int_fail = new TestRunnableInterface(false);
260 
261  t_run_allocate = new TestAllocate();
262  t_self_remove = new TestSelfRemove();
263 
264  t_run_allocate_act = new TestAllocate();
265 }
266 
267 
268 void
270 {
271  delete periodic_act;
272  delete t_act;
273 
274  delete t_run_int_prio;
275  delete t_run_int_act;
276  delete t_run_int_fail;
277 
278  delete t_run_allocate;
279  delete t_run_allocate_act;
280 
281  delete t_self_remove;
282 }
283 
284 BOOST_FIXTURE_TEST_SUITE( ActivitiesTestSuite, ActivitiesTest )
285 
286 BOOST_AUTO_TEST_CASE( testFailInit )
287 {
288  periodic_act->run( t_run_int_fail );
289 
290  BOOST_CHECK( !periodic_act->start() );
291  BOOST_CHECK( !periodic_act->stop() );
292 
293  BOOST_CHECK( t_act->run( t_run_int_fail ) );
294  t_run_int_fail->reset(false);
295 
296  BOOST_CHECK( !t_act->start() );
297  BOOST_CHECK( !t_act->stop() );
298 
299 }
300 
301 BOOST_AUTO_TEST_CASE( testMaxOverrun )
302 {
303  // create
304  boost::scoped_ptr<TestOverrun> run( new TestOverrun() );
305  boost::scoped_ptr<Activity> t( new Activity(25, 0.1, 0,"ORThread") );
306  BOOST_REQUIRE_EQUAL(0.1,t->getPeriod() );
307 
308  t->thread()->setMaxOverrun(1);
309 
310  t->run( run.get() );
311 
312  // prints annoying warning messages...
315 
316  t->start();
317  // In Xenomai (2.5), the first usleep returns immediately.
318  // We can 'fix' this by adding a log() statement before usleep() .... crap
319  usleep(100*1000);
320  usleep(400*1000);
321  Logger::log().setLogLevel(ll);
322 
323  BOOST_REQUIRE_MESSAGE( !t->isRunning(), "Failed to detect step overrun in Thread");
324  BOOST_CHECK_MESSAGE( run->fini, "Failed to execute finalize in emergencyStop" );
325 }
326 
328 
329 BOOST_AUTO_TEST_CASE( testDefaultWaitPeriodPolicy )
330 {
331  // create
332  boost::scoped_ptr<TestOverrun> run( new TestOverrun() );
333  boost::scoped_ptr<Activity> t( new Activity(25, 0.3, 0,"ORThread") );
334  t->run( run.get() );
335  run->additional_sleep_time.resize(1);
336  run->additional_sleep_time[0] = Seconds_to_nsecs(0.2);
337  nsecs period = Seconds_to_nsecs(t->getPeriod()); (void) period;
338 
339  // test default wait period policy (== ORO_WAIT_ABS)
340  BOOST_REQUIRE_MESSAGE( t->start(), "start thread");
341  // In Xenomai (2.5), the first usleep returns immediately.
342  // We can 'fix' this by adding a log() statement before usleep() .... crap
343  usleep(100*1000);
344  usleep(1000*1000);
345  BOOST_REQUIRE_MESSAGE( t->stop(), "stop thread");
346  BOOST_CHECK_SMALL( ((run->wakeup_time[1] - run->wakeup_time[0]) - Seconds_to_nsecs(0.4)), WaitPeriodPolicyTolerance ); // Second wakeup: 2 * sleep_time
347  BOOST_CHECK_SMALL( ((run->wakeup_time[2] - run->wakeup_time[1]) - Seconds_to_nsecs(0.2)), WaitPeriodPolicyTolerance ); // Third wakeup right after end of second step (ORO_WAIT_ABS)
348 }
349 
350 BOOST_AUTO_TEST_CASE( testAbsoluteWaitPeriodPolicy )
351 {
352  // create
353  boost::scoped_ptr<TestOverrun> run( new TestOverrun() );
354  boost::scoped_ptr<Activity> t( new Activity(25, 0.3, 0,"ORThread") );
355  t->run( run.get() );
356  run->additional_sleep_time.resize(1);
357  run->additional_sleep_time[0] = Seconds_to_nsecs(0.2);
358  nsecs period = Seconds_to_nsecs(t->getPeriod()); (void) period;
359 
360  // test absolute wait period policy (ORO_WAIT_ABS)
361  t->setWaitPeriodPolicy(ORO_WAIT_ABS);
362  BOOST_REQUIRE_MESSAGE( t->start(), "start thread");
363  // In Xenomai (2.5), the first usleep returns immediately.
364  // We can 'fix' this by adding a log() statement before usleep() .... crap
365  usleep(100*1000);
366  usleep(1000*1000);
367  BOOST_REQUIRE_MESSAGE( t->stop(), "stop thread");
368  BOOST_CHECK_SMALL( ((run->wakeup_time[1] - run->wakeup_time[0]) - Seconds_to_nsecs(0.4)), WaitPeriodPolicyTolerance ); // Second wakeup: 2 * sleep_time (overrun)
369  BOOST_CHECK_SMALL( ((run->wakeup_time[2] - run->wakeup_time[1]) - Seconds_to_nsecs(0.2)), WaitPeriodPolicyTolerance ); // Third wakeup right after end of second step (ORO_WAIT_ABS)
370 }
371 
372 BOOST_AUTO_TEST_CASE( testRelativeWaitPeriodPolicy )
373 {
374  // create
375  boost::scoped_ptr<TestOverrun> run( new TestOverrun() );
376  boost::scoped_ptr<Activity> t( new Activity(25, 0.3, 0,"ORThread") );
377  t->run( run.get() );
378  run->additional_sleep_time.resize(1);
379  run->additional_sleep_time[0] = Seconds_to_nsecs(0.2);
380  nsecs period = Seconds_to_nsecs(t->getPeriod()); (void) period;
381 
382  // test relative wait period policy (ORO_WAIT_REL)
383  t->setWaitPeriodPolicy(ORO_WAIT_REL);
384  BOOST_REQUIRE_MESSAGE( t->start(), "start thread");
385  // In Xenomai (2.5), the first usleep returns immediately.
386  // We can 'fix' this by adding a log() statement before usleep() .... crap
387  usleep(100*1000);
388  usleep(1000*1000);
389  BOOST_REQUIRE_MESSAGE( t->stop(), "stop thread");
390  BOOST_CHECK_SMALL( ((run->wakeup_time[1] - run->wakeup_time[0]) - Seconds_to_nsecs(0.4)), WaitPeriodPolicyTolerance ); // Second wakeup: 2 * sleep_time (overrun)
391  BOOST_CHECK_SMALL( ((run->wakeup_time[2] - run->wakeup_time[1]) - period), WaitPeriodPolicyTolerance ); // Third wakeup after period (ORO_WAIT_REL)
392 }
393 
394 BOOST_AUTO_TEST_CASE( testThread )
395 {
396  bool r = false;
397  // create
398  boost::scoped_ptr<TestPeriodic> run( new TestPeriodic() );
399 
400  boost::scoped_ptr<ActivityInterface> t( new Activity(ORO_SCHED_RT, os::HighestPriority, 0.1, 0, "PThread") );
401  t->run( run.get() );
402 
403  r = t->start();
404  BOOST_CHECK_MESSAGE( r, "Failed to start Thread");
405  usleep(1000*100);
406  r = t->stop();
407  BOOST_CHECK_MESSAGE( r, "Failed to stop Thread" );
408  BOOST_CHECK_MESSAGE( run->stepped == true, "Step not executed" );
409  BOOST_CHECK_EQUAL_MESSAGE(run->overfail, 0, "Periodic Failure: period of step() too long !");
410  BOOST_CHECK_EQUAL_MESSAGE(run->underfail, 0, "Periodic Failure: period of step() too short!");
411 }
412 
413 #if defined( OROCOS_TARGET_GNULINUX )
414 // run on just the target CPU
415 void testAffinity2(boost::scoped_ptr<TestPeriodic>& run,
416  boost::scoped_ptr<Activity>& t,
417  int targetCPU)
418 {
419  bool r = false;
420 
421  t->run( run.get() );
422 
423  BOOST_CHECK(t->setCpuAffinity(1 << targetCPU));
424  BOOST_CHECK_EQUAL((1 << targetCPU), t->getCpuAffinity());
425 
426  BOOST_CHECK_EQUAL(0, run->cpu);
427  r = t->start();
428  BOOST_CHECK_MESSAGE( r, "Failed to start Thread");
429  sleep(1);
430  r = t->stop();
431  BOOST_CHECK_MESSAGE( r, "Failed to stop Thread" );
432  BOOST_CHECK_MESSAGE( run->stepped == true, "Step not executed" );
433  BOOST_CHECK_EQUAL(targetCPU, run->cpu);
434  BOOST_CHECK_LT(0, run->succ);
435 
436  t->run(0);
437 }
438 
439 
440 BOOST_AUTO_TEST_CASE( testAffinity )
441 {
442  if(std::getenv("CI") != NULL) {
443  BOOST_TEST_MESSAGE("Skipping testAffinity because it can fail on integration servers.");
444  return;
445  }
446  // this test is kind of irrelevant with only 1 CPU
447  int numCPU = sysconf( _SC_NPROCESSORS_ONLN );
448  if (1 < numCPU)
449  {
450  boost::scoped_ptr<TestPeriodic> run( new TestPeriodic() );
451  boost::scoped_ptr<Activity> t( new Activity(ORO_SCHED_RT, os::HighestPriority, 0.1, ~0, 0, "PThread") );
452  // returned affinity depends on the number of actual CPUs, and won't be "~0"
453  unsigned mask=0;
454  for (int i=0; i<numCPU; ++i)
455  {
456  mask |= (1 << i);
457  }
458  BOOST_CHECK_EQUAL(mask, t->getCpuAffinity());
459 
460  // test just a couple of cases
461  testAffinity2(run, t, 0);
462  testAffinity2(run, t, numCPU-1);
463  }
464  // else ignore test as insufficient number of CPUs
465 }
466 
467 #endif
468 
469 BOOST_AUTO_TEST_CASE( testNonPeriodic )
470 {
471  scoped_ptr<TestRunnableInterface> t_run_int_nonper
472  ( new TestRunnableInterface(true) );
473  // force ordering of scoped_ptr destruction.
474  {
475  scoped_ptr<Activity> t_task_nonper
476  ( new Activity( 14 ) );
477 
478  BOOST_CHECK( t_task_nonper->run( t_run_int_nonper.get() ) );
479  BOOST_CHECK( t_task_nonper->start() );
480  testPause();
481  BOOST_CHECK( t_run_int_nonper->looped );
482  BOOST_CHECK( !t_run_int_nonper->stepped );
483  BOOST_CHECK( t_run_int_nonper->init );
484  BOOST_CHECK( t_task_nonper->stop() );
485  BOOST_CHECK( t_run_int_nonper->fini );
486  BOOST_CHECK( !t_task_nonper->isRunning() );
487  BOOST_CHECK( t_task_nonper->run( 0 ) );
488  BOOST_CHECK( t_task_nonper->start() );
489  BOOST_CHECK( t_task_nonper->stop() );
490  // stop() should be fully synchronising...
491  BOOST_CHECK( !t_task_nonper->isRunning() );
492  }
493 }
494 
495 BOOST_AUTO_TEST_CASE( testActivityNP )
496 {
497  scoped_ptr<TestRunnableInterface> t_run_int_nonper
498  ( new TestRunnableInterface(true) );
499  // force ordering of scoped_ptr destruction.
500  {
501  scoped_ptr<Activity> t_task_nonper
502  ( new Activity(15) );
503 
504  BOOST_CHECK( t_task_nonper->run( t_run_int_nonper.get() ) );
505  BOOST_CHECK( t_task_nonper->start() );
506  testPause();
507  sleep(1);
508  BOOST_CHECK( t_run_int_nonper->looped );
509  BOOST_CHECK( t_run_int_nonper->init );
510  BOOST_CHECK( t_task_nonper->stop() );
511  BOOST_CHECK( t_run_int_nonper->fini );
512  BOOST_CHECK( !t_task_nonper->isRunning() );
513  BOOST_CHECK( t_task_nonper->run( 0 ) );
514  BOOST_CHECK( t_task_nonper->start() );
515  BOOST_CHECK( t_task_nonper->stop() );
516  // stop() should be fully synchronising...
517  BOOST_CHECK( !t_task_nonper->isRunning() );
518  }
519 }
520 
521 BOOST_AUTO_TEST_CASE( testActivityBreakLoop )
522 {
523  scoped_ptr<TestRunnableInterface> t_run_int_nonper
524  ( new TestRunnableInterface(true) );
525  // force ordering of scoped_ptr destruction.
526  {
527  scoped_ptr<Activity> t_task_nonper
528  ( new Activity(15) );
529 
530  BOOST_CHECK( t_task_nonper->run( t_run_int_nonper.get() ) );
531  BOOST_CHECK( t_task_nonper->start() );
532  testPause();
533 
534  t_run_int_nonper->breakl = false;
535  BOOST_CHECK( t_task_nonper->start() );
536  testPause();
537  BOOST_CHECK( t_task_nonper->stop() == false );
538 
539  t_run_int_nonper->breakl = true;
540  BOOST_CHECK( t_task_nonper->stop() );
541  BOOST_CHECK( t_run_int_nonper->fini );
542  BOOST_CHECK( !t_task_nonper->isRunning() );
543  }
544 }
545 
546 BOOST_AUTO_TEST_CASE( testSelfRemove )
547 {
548  scoped_ptr<TestSelfRemove> t_run_int_nonper
549  ( new TestSelfRemove() );
550  scoped_ptr<Activity> t_task_nonper
551  ( new Activity( 14 ) );
552  BOOST_CHECK( t_task_nonper->run( t_run_int_nonper.get() ) );
553  BOOST_CHECK( t_task_nonper->start() );
554  BOOST_CHECK( periodic_act->run(t_self_remove) );
555  BOOST_CHECK( periodic_act->start() );
556  testPause();
557  BOOST_CHECK( !periodic_act->isRunning() );
558  BOOST_CHECK( t_self_remove->fini );
559  BOOST_CHECK( !t_task_nonper->isRunning() );
560  BOOST_CHECK( t_run_int_nonper->fini );
561 }
562 
563 BOOST_AUTO_TEST_CASE( testActivityNPSelfRemove )
564 {
565  scoped_ptr<TestSelfRemove> t_run_int_nonper
566  ( new TestSelfRemove() );
567  scoped_ptr<Activity> t_task_nonper
568  ( new Activity( 14 ) );
569  BOOST_CHECK( t_task_nonper->run( t_run_int_nonper.get() ) );
570  BOOST_CHECK( t_task_nonper->start() );
571  testPause();
572  BOOST_CHECK( !t_task_nonper->isRunning() );
573  BOOST_CHECK( t_run_int_nonper->fini );
574 }
575 
576 BOOST_AUTO_TEST_CASE( testActivityPSelfRemove )
577 {
578  scoped_ptr<TestSelfRemove> t_run_int_per
579  ( new TestSelfRemove() );
580  scoped_ptr<Activity> t_task_per
581  ( new Activity( 14, 0.01 ) );
582  BOOST_CHECK( t_task_per->run( t_run_int_per.get() ) );
583  BOOST_CHECK( t_task_per->start() );
584  testPause();
585  testPause();
586  BOOST_CHECK( !t_task_per->isRunning() );
587  BOOST_CHECK( t_run_int_per->fini );
588 }
589 
590 
591 BOOST_AUTO_TEST_CASE( testStartStop )
592 {
593  testStart();
594  testPause();
595  testStop();
596 }
597 
598 BOOST_AUTO_TEST_CASE( testRunnableInterface )
599 {
600  testAddRunnableInterface();
601  testStart();
602  testRunnableInterfaceInit();
603  testPause();
604  testRunnableInterfaceExecution();
605  testStop();
606  testRemoveRunnableInterface();
607 }
608 
609 BOOST_AUTO_TEST_CASE( testAllocation )
610 {
611  testAddAllocate();
612  testStart();
613  testPause();
614  testStop();
615  testRemoveAllocate();
616 }
617 
619 
620 #if defined( OROCOS_TARGET_GNULINUX ) && defined( ORO_HAVE_PTHREAD_SETNAME_NP )
621 BOOST_AUTO_TEST_CASE( testThreadName1 )
622 {
623  Activity activity(0, 0, "hello-world");
624  RTT::os::ThreadInterface *thread = activity.thread();
625  char buffer[256];
626  pthread_getname_np(thread->getTask()->thread, buffer, sizeof(buffer));
627  BOOST_CHECK_EQUAL(std::string(buffer), std::string("hello-world"));
628 }
629 BOOST_AUTO_TEST_CASE( testThreadName2 )
630 {
631  Activity activity(0, 0, "abcdefgXXXXX1234567");
632  RTT::os::ThreadInterface *thread = activity.thread();
633  char buffer[256];
634  pthread_getname_np(thread->getTask()->thread, buffer, sizeof(buffer));
635  BOOST_CHECK_EQUAL(std::string(buffer), std::string("abcdefg~1234567"));
636 }
637 #endif
638 
640 {
641  bool adding_prio = periodic_act->run( t_run_int_prio );
642  BOOST_CHECK( adding_prio );
643 
644  bool adding_act = t_act->run( t_run_int_act );
645  BOOST_CHECK( adding_act );
646 }
647 
649 {
650  BOOST_CHECK( t_run_int_prio->fini );
651  BOOST_CHECK( periodic_act->run( 0 ) );
652 
653  BOOST_CHECK( t_run_int_act->fini );
654  BOOST_CHECK( t_act->run( 0 ) );
655 }
656 
658 {
659  BOOST_CHECK( periodic_act->start());
660  BOOST_CHECK( periodic_act->isRunning() );
661 
662  BOOST_CHECK( t_act->start());
663  BOOST_CHECK( t_act->isRunning() );
664 }
665 
667 {
668 #if 0
669  // does not work on Xenomai:
670  int rv = 0;
671  BOOST_CHECK( (rv = usleep(100000)) == 0);
672  if ( rv != 0)
673  BOOST_CHECK_EQUAL_MESSAGE(errno, 0, "Sleep failed. Errno is not zero.");
674 #else
675  TIME_SPEC t;
676  t.tv_sec = 1;
677  t.tv_nsec = 0;
678  BOOST_CHECK( rtos_nanosleep(&t,0) == 0);
679 #endif
680 }
681 
683  BOOST_CHECK( t_run_int_prio->init );
684  BOOST_CHECK( t_run_int_act->init );
685 }
686 
688 
689  BOOST_CHECK( t_run_int_prio->stepped );
690  BOOST_CHECK( t_run_int_act->stepped );
691 }
692 
694 {
695  BOOST_CHECK( periodic_act->stop());
696  BOOST_CHECK( !periodic_act->isRunning() );
697 
698  BOOST_CHECK( t_act->stop());
699  BOOST_CHECK( !t_act->isRunning() );
700 }
701 
703 {
704  BOOST_CHECK( periodic_act->run( t_run_allocate ) );
705 
706  BOOST_CHECK( t_act->run( t_run_allocate_act ) );
707 }
708 
710 {
711  BOOST_CHECK( periodic_act->run( 0 ) );
712 
713  BOOST_CHECK( t_act->run( 0 ) );
714 }
715 
void finalize()
Definition: tasks_test.cpp:137
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
static const nsecs WaitPeriodPolicyTolerance
Definition: tasks_test.cpp:327
std::string s
Definition: tasks_test.cpp:199
#define ORO_WAIT_ABS
Definition: ecos/fosi.h:64
void testAddAllocate()
Definition: tasks_test.cpp:702
LogLevel getLogLevel() const
Definition: Logger.cpp:613
bool initialize()
Definition: tasks_test.cpp:57
virtual os::ThreadInterface * thread()
Definition: Activity.cpp:114
void testRemoveRunnableInterface()
Definition: tasks_test.cpp:648
#define BOOST_AUTO_TEST_SUITE_END()
Definition: mystd.hpp:163
nsecs sleep_time
Definition: tasks_test.cpp:46
TestRunnableInterface(bool res)
Definition: tasks_test.cpp:157
static int rtos_nanosleep(const TIME_SPEC *rqtp, TIME_SPEC *rmtp)
int usleep(unsigned int us)
Definition: fosi.cpp:58
virtual RTOS_TASK * getTask()=0
void finalize()
Definition: tasks_test.cpp:214
cyg_thread thread
Definition: ecos/fosi.h:76
#define BOOST_CHECK_EQUAL_MESSAGE(v1, v2, M)
Definition: tasks_test.cpp:40
std::vector< std::string > v
Definition: tasks_test.cpp:197
void step()
Definition: tasks_test.cpp:65
const int HighestPriority
Definition: ecosthreads.cpp:45
void finalize()
Definition: tasks_test.cpp:87
unsigned int cycle
Definition: tasks_test.cpp:50
TimeService::ticks ts
Definition: tasks_test.cpp:98
A PeriodicActivity is the general implementation of a Activity which has (realtime) periodic constrai...
void testRunnableInterfaceExecution()
Definition: tasks_test.cpp:687
basic_ostreams & endl(basic_ostreams &s)
Definition: rtstreams.cpp:110
static TIME_SPEC ticks2timespec(TICK_TIME hrt)
std::vector< nsecs > wakeup_time
Definition: tasks_test.cpp:48
An Activity executes a RunnableInterface object in a (periodic) thread.
Definition: Activity.hpp:70
unsigned int sleep(unsigned int s)
Definition: fosi.cpp:51
bool initialize()
Definition: tasks_test.cpp:201
bool initialize()
Definition: tasks_test.cpp:108
nsecs Seconds_to_nsecs(const Seconds s)
Definition: os/Time.hpp:107
TICK_TIME nano2ticks(NANO_TIME nano)
Definition: ecos/fosi.h:112
#define ORO_WAIT_REL
Definition: ecos/fosi.h:65
#define ORO_SCHED_RT
Definition: ecos/fosi.h:61
void reset(bool res)
Definition: tasks_test.cpp:184
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
long long nsecs
Definition: os/Time.hpp:69
void testRemoveAllocate()
Definition: tasks_test.cpp:709
struct timespec TIME_SPEC
Definition: ecos/fosi.h:109
static Logger & log()
Definition: Logger.hpp:350
std::vector< nsecs > additional_sleep_time
Definition: tasks_test.cpp:49
void testRunnableInterfaceInit()
Definition: tasks_test.cpp:682
void testAddRunnableInterface()
Definition: tasks_test.cpp:639
void setLogLevel(LogLevel ll)
Definition: Logger.cpp:606
BOOST_AUTO_TEST_CASE(testFailInit)
Definition: tasks_test.cpp:286


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:37