taskthread_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Tue Apr 5 16:53:26 CEST 2005 taskthread_test.cpp
3 
4  taskthread_test.cpp - description
5  -------------------
6  begin : Tue April 05 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 "taskthread_test.hpp"
23 
24 #include <iostream>
25 
26 #include <extras/Activities.hpp>
27 #include <extras/TimerThread.hpp>
29 #include <os/MainThread.hpp>
30 #include <Logger.hpp>
31 #include <rtt-config.h>
32 
33 using namespace std;
34 using namespace RTT;
35 
36 struct A {};
37 
38 template<class T>
40  : public T
41 {
42  bool result, _dothrow;
43  bool init, stepped, looped, fini;
44  bool wasrunning, wasactive;
45 
46  TestActivity(int prio, double per, bool fail, bool dothrow = false)
47  :T(prio,per), _dothrow(dothrow)
48  {
49  this->reset(fail);
50  }
51 
52  bool initialize() {
53  init = true;
54  return result;
55  }
56 
57  void step() {
58  stepped = true;
59  wasrunning = this->isRunning();
60  wasactive = this->isActive();
61 #ifndef ORO_EMBEDDED
62  if ( _dothrow )
63  throw A();
64 #endif
65  }
66 
67  void loop();
68 
69  void finalize() {
70  fini = true;
71  }
72 
73  void reset(bool fail) {
74  result = fail;
75  init = false;
76  stepped = false;
77  looped = false;
78  fini = false;
79  wasrunning=false;
80  wasactive=false;
81  }
82 };
83 
84 template <class T>
86  looped = true;
87  T::loop();
88 }
89 
90 template <>
92  looped = true;
93 }
94 
95 struct TestRunner
96  : public RunnableInterface
97 {
98  bool result;
99  bool init, stepped, fini;
100  bool looped, broke;
101  bool wasrunning, wasactive;
102  bool worked, wreason;
103 
104  TestRunner(bool fail)
105  {
106  this->reset(fail);
107  }
108 
109  bool initialize() {
110  init = true;
111  BOOST_CHECK(getActivity()->isActive());
112  BOOST_CHECK(!getActivity()->isRunning());
113  return result;
114  }
115 
116  void step() {
117  stepped = true;
118  wasrunning=getActivity()->isRunning();
119  wasactive=getActivity()->isActive();
120  }
121 
123  worked = true;
124  wreason = reason;
125  }
126 
127  void loop() {
128  looped = true;
129  wasrunning=getActivity()->isRunning();
130  wasactive=getActivity()->isActive();
131  }
132 
133  bool breakLoop() {
134  broke = true;
135  return true;
136  }
137 
138  void finalize() {
139  fini = true;
140  BOOST_CHECK(getActivity()->isActive());
141  BOOST_CHECK(!getActivity()->isRunning());
142  }
143 
144  void reset(bool fail) {
145  result = fail;
146  init = false;
147  stepped = false;
148  fini = false;
149  looped = false;
150  broke = false;
151  wasrunning = false;
152  wasactive = false;
153  worked = false;
154  wreason = false;
155  }
156 };
157 
158 
159 void
161 {
162  t_task_np = new TestActivity<PeriodicActivity>(3, 0.01, true ); // will be stopped if np_bad throws
163  t_task_np_bad = new TestActivity<PeriodicActivity>(3, 0.01, true, true ); // throws
164  t_task_p = new TestActivity<PeriodicActivity>(3, 0.032, true ); // does not throw
165  t_task_a = new TestActivity<Activity>(3, 0.01, true, true ); // throws
166 }
167 
168 
169 void
171 {
172  delete t_task_np;
173  delete t_task_np_bad;
174  delete t_task_p;
175  delete t_task_a;
176 }
177 
178 // Registers the fixture into the 'registry'
179 BOOST_FIXTURE_TEST_SUITE( ActivitiesThreadTestSuite, ActivitiesThreadTest )
180 
181 BOOST_AUTO_TEST_CASE( testPeriodicActivity )
182 {
183  // Test periodic task sequencing...
184 
185  TestActivity<PeriodicActivity> mtask( 15, 0.01, true );
186  BOOST_CHECK( mtask.isActive() == false );
187  BOOST_CHECK( mtask.isRunning() == false );
188  BOOST_CHECK( mtask.thread()->isRunning() == false );
189  BOOST_CHECK_EQUAL( 0.01, mtask.thread()->getPeriod() );
190 
191  // Adapt priority levels to OS.
192  int bprio = 15, rtsched = ORO_SCHED_RT;
193  os::CheckPriority( rtsched, bprio );
194 
195  BOOST_CHECK_EQUAL( bprio, mtask.thread()->getPriority() );
196  BOOST_CHECK_EQUAL( rtsched, mtask.thread()->getScheduler() );
197 
198  TestActivity<PeriodicActivity> m2task( 15, 0.01, true );
199  BOOST_CHECK( mtask.thread() == m2task.thread() );
200 
201  // starting...
202  BOOST_CHECK( mtask.start() == true );
203  BOOST_CHECK( mtask.isRunning() == true );
204  BOOST_CHECK( mtask.thread()->isRunning() == true );
205  BOOST_CHECK( m2task.isRunning() == false );
206  BOOST_CHECK( m2task.start() == true );
207  BOOST_CHECK( m2task.isRunning() == true );
208 
209  usleep(100000);
210 
211  // stopping...
212  BOOST_CHECK( mtask.stop() == true );
213  BOOST_CHECK( mtask.isRunning() == false );
214  BOOST_CHECK( m2task.isRunning() == true );
215  BOOST_CHECK( m2task.stop() == true );
216  BOOST_CHECK( m2task.isRunning() == false );
217 
218  // check if the activity actually ran
219  BOOST_CHECK( mtask.looped == false );
220  BOOST_CHECK( mtask.stepped == true );
221  BOOST_CHECK( m2task.looped == false );
222  BOOST_CHECK( m2task.stepped == true );
223 
224  // Different Scheduler (don't test if invalid priorities)
225  bprio = 15;
226  rtsched = ORO_SCHED_RT;
227  if ( os::CheckPriority( rtsched, bprio ) ) {
228  PeriodicActivity m3task(ORO_SCHED_OTHER, 15, 0.01);
229  bprio = 15;
230  rtsched = ORO_SCHED_OTHER;
231  if ( os::CheckPriority( rtsched, bprio ) ) {
232  BOOST_CHECK( mtask.thread() != m3task.thread() );
233  BOOST_CHECK_EQUAL( ORO_SCHED_OTHER, m3task.thread()->getScheduler() );
234  }
235  }
236 
237  // Different CPU affinity
238  unsigned cpu_affinity = 1; // first CPU only
239  if ( mtask.thread()->getCpuAffinity() != (unsigned) ~0 &&
240  mtask.thread()->getCpuAffinity() != cpu_affinity ) {
241  PeriodicActivity m4task(ORO_SCHED_OTHER, 15, 0.01, cpu_affinity);
242  BOOST_CHECK( mtask.thread() != m4task.thread() );
243  BOOST_CHECK_EQUAL( cpu_affinity, m4task.thread()->getCpuAffinity() );
244  }
245 
246  // Starting thread if thread not running
247  BOOST_CHECK( mtask.thread()->stop() );
248  BOOST_CHECK( mtask.thread()->isRunning() == false );
249  BOOST_CHECK( mtask.start() );
250  BOOST_CHECK( mtask.isRunning() == true );
251  BOOST_CHECK( mtask.thread()->isRunning() == true);
252 }
253 
254 BOOST_AUTO_TEST_CASE( testActivityNonPeriodic )
255 {
256  // Test non-periodic task sequencing...
257 
258  TestActivity<Activity> mtask( 15, 0.0, true );
259  usleep(100000);
260  // Adapt priority levels to OS.
261  int bprio = 15, rtsched = ORO_SCHED_RT;
262  os::CheckPriority( rtsched, bprio );
263 
264  BOOST_CHECK( mtask.isActive() == false );
265  BOOST_CHECK( mtask.isRunning() == false );
266  BOOST_CHECK( mtask.thread()->isRunning() == false );
267  BOOST_CHECK_EQUAL( bprio, mtask.thread()->getPriority() );
268  BOOST_CHECK_EQUAL( rtsched, mtask.thread()->getScheduler() );
269 
270  TestActivity<Activity> m2task( 15, 0.0, true );
271  BOOST_CHECK( mtask.thread() != m2task.thread() );
272 
273  // starting...
274  BOOST_CHECK( mtask.start() == true );
275  BOOST_CHECK( mtask.isActive() == true );
276  BOOST_CHECK( m2task.isActive() == false );
277  BOOST_CHECK( m2task.start() == true );
278  BOOST_CHECK( m2task.isActive() == true );
279 
280  usleep(100000);
281 
282  // stopping...
283  BOOST_CHECK( mtask.stop() == true );
284  BOOST_CHECK( mtask.isActive() == false );
285  BOOST_CHECK( m2task.isActive() == true );
286  BOOST_CHECK( m2task.stop() == true );
287  BOOST_CHECK( m2task.isActive() == false );
288 
289  // check if the activity actually ran
290  BOOST_CHECK( mtask.looped == true );
291  BOOST_CHECK( mtask.stepped == true );
292  BOOST_CHECK( m2task.looped == true );
293  BOOST_CHECK( m2task.stepped == true );
294 }
295 
296 BOOST_AUTO_TEST_CASE( testActivityPeriodic )
297 {
298  // Test periodic task sequencing...
299 
300  TestActivity<Activity> mtask( 15, 0.01, true );
301  BOOST_CHECK( mtask.isActive() == false );
302  BOOST_CHECK( mtask.isRunning() == false );
303  BOOST_CHECK( mtask.thread()->isRunning() == false );
304  BOOST_CHECK_EQUAL( 0.01, mtask.thread()->getPeriod() );
305 
306  // Adapt priority levels to OS.
307  int bprio = 15, rtsched = ORO_SCHED_RT;
308  os::CheckPriority( rtsched, bprio );
309 
310  BOOST_CHECK_EQUAL( bprio, mtask.thread()->getPriority() );
311  BOOST_CHECK_EQUAL( rtsched, mtask.thread()->getScheduler() );
312 
313  TestActivity<Activity> m2task( 15, 0.01, true );
314  BOOST_CHECK( mtask.thread() != m2task.thread() );
315 
316  // starting...
317  BOOST_CHECK( mtask.start() == true );
318  BOOST_CHECK( mtask.isRunning() == true );
319  BOOST_CHECK( mtask.thread()->isRunning() == true );
320  BOOST_CHECK( m2task.isRunning() == false );
321  BOOST_CHECK( m2task.start() == true );
322  BOOST_CHECK( m2task.isRunning() == true );
323 
324  usleep(100000);
325 
326  // stopping...
327  BOOST_CHECK( mtask.stop() == true );
328  BOOST_CHECK( mtask.isRunning() == false );
329  BOOST_CHECK( m2task.isRunning() == true );
330  BOOST_CHECK( m2task.stop() == true );
331  BOOST_CHECK( m2task.isRunning() == false );
332 
333  // check if the activity actually ran
334  //BOOST_CHECK( mtask.looped == false );
335  BOOST_CHECK( mtask.stepped == true );
336  //BOOST_CHECK( m2task.looped == false );
337  BOOST_CHECK( m2task.stepped == true );
338 }
339 
341 {
342  // Test slave activities
343  TestRunner r(true);
344 
345  // without master, NP.
346  SlaveActivity mtask(&r);
347  BOOST_CHECK( mtask.isActive() == false );
348  BOOST_CHECK( mtask.isRunning() == false );
349  BOOST_CHECK( mtask.isPeriodic() == false );
350  BOOST_CHECK( mtask.getPeriod() == 0.0 );
351  BOOST_CHECK( mtask.execute() == false );
352  BOOST_CHECK( mtask.thread() == os::MainThread::Instance() );
353 
354  // starting...
355  BOOST_CHECK( mtask.start() == true );
356  BOOST_CHECK( r.init == true );
357 
358  BOOST_CHECK( mtask.isActive() == true );
359  BOOST_CHECK( mtask.isRunning() == false );
360  BOOST_CHECK( mtask.start() == false );
361 
362  // calls loop()
363  BOOST_CHECK( mtask.execute() );
364  BOOST_CHECK( r.looped == true );
365  BOOST_CHECK( r.worked == true );
366  BOOST_CHECK( r.wreason == RunnableInterface::TimeOut );
367  BOOST_CHECK( mtask.execute() );
368  BOOST_CHECK( r.wasrunning );
369  BOOST_CHECK( r.wasactive );
370 
371  // stopping...
372  BOOST_CHECK( mtask.stop() == true );
373  BOOST_CHECK( r.fini == true );
374  BOOST_CHECK( mtask.isRunning() == false );
375  BOOST_CHECK( mtask.isActive() == false );
376  BOOST_CHECK( mtask.stop() == false );
377 
378  BOOST_CHECK( mtask.execute() == false );
379 
380  r.reset(true);
381 
382  // with periodic master:
383  SlaveActivity mslave( t_task_np, &r );
384  BOOST_CHECK( mslave.isActive() == false );
385  BOOST_CHECK( mslave.isRunning() == false );
386  BOOST_CHECK( mslave.isPeriodic() == true );
387  BOOST_CHECK_EQUAL( mslave.getPeriod(), t_task_np->getPeriod() );
388  BOOST_CHECK( mslave.execute() == false );
389  BOOST_CHECK( mslave.thread() == t_task_np->thread() );
390 
391  BOOST_CHECK( !mslave.start() );
392  BOOST_CHECK( t_task_np->start() );
393  BOOST_CHECK( mslave.start() );
394  BOOST_CHECK( r.init == true );
395  BOOST_CHECK( mslave.isActive() );
396  BOOST_CHECK( mslave.isRunning() );
397 
398  // calls step()
399  BOOST_CHECK( mslave.execute() );
400  BOOST_CHECK( r.stepped == true );
401  BOOST_CHECK( r.wasrunning );
402  BOOST_CHECK( r.wasactive );
403  BOOST_CHECK( r.worked == true );
404  BOOST_CHECK( r.wreason == RunnableInterface::TimeOut );
405  BOOST_CHECK( mslave.execute() );
406  BOOST_CHECK( !mslave.start() );
407 
408  // stopping...
409  BOOST_CHECK( mslave.stop() );
410  BOOST_CHECK( r.fini == true );
411  BOOST_CHECK( !mslave.isActive() );
412  BOOST_CHECK( !mslave.isRunning() );
413 
414  r.reset(true);
415 
416  // periodic:
417  SlaveActivity mslave_p(0.001, &r);
418  BOOST_CHECK( mslave_p.isActive() == false );
419  BOOST_CHECK( mslave_p.isRunning() == false );
420  BOOST_CHECK( mslave_p.isPeriodic() == true );
421  BOOST_CHECK( mslave_p.getPeriod() == 0.001 );
422  BOOST_CHECK( mslave_p.execute() == false );
423  BOOST_CHECK( mslave_p.thread() == os::MainThread::Instance() );
424 
425  BOOST_CHECK( mslave_p.start() );
426  BOOST_CHECK( r.init == true );
427  BOOST_CHECK( mslave_p.isActive() );
428  BOOST_CHECK( mslave_p.isRunning() );
429  BOOST_CHECK( mslave_p.execute() );
430  BOOST_CHECK( r.stepped == true );
431  BOOST_CHECK( r.worked == true );
432  BOOST_CHECK( r.wreason == RunnableInterface::TimeOut );
433  BOOST_CHECK( r.wasrunning );
434  BOOST_CHECK( r.wasactive );
435  BOOST_CHECK( !mslave_p.start() );
436 
437  // stopping...
438  BOOST_CHECK( mslave_p.stop() );
439  BOOST_CHECK( r.fini == true );
440  BOOST_CHECK( !mslave_p.isActive() );
441  BOOST_CHECK( !mslave_p.isRunning() );
442  BOOST_CHECK( !mslave_p.execute() );
443 }
444 
445 BOOST_AUTO_TEST_CASE( testSequential )
446 {
447  // Test sequential activities
448  TestRunner r(true);
449 
450  SequentialActivity mtask(&r);
451  BOOST_CHECK( mtask.isActive() == false );
452  BOOST_CHECK( mtask.isRunning() == false );
453  BOOST_CHECK( mtask.isPeriodic() == false );
454  BOOST_CHECK( mtask.getPeriod() == 0.0 );
455  BOOST_CHECK( mtask.execute() == false );
456  BOOST_CHECK( mtask.trigger() == false );
457  BOOST_CHECK( mtask.thread() == os::MainThread::Instance() );
458 
459  // starting...
460  BOOST_CHECK( mtask.start() == true );
461  BOOST_CHECK( r.init == true );
462 
463  BOOST_CHECK( mtask.isActive() == true );
464  BOOST_CHECK( mtask.isRunning() == false );
465  BOOST_CHECK( mtask.start() == false );
466 
467  // calls step()
468  BOOST_CHECK( mtask.trigger() );
469  BOOST_CHECK( r.stepped == true );
470  BOOST_CHECK( r.worked == true );
471  BOOST_CHECK( r.wreason == RunnableInterface::TimeOut );
472  BOOST_CHECK( r.wasrunning );
473  BOOST_CHECK( r.wasactive );
474  BOOST_CHECK( mtask.execute() == false );
475 
476  // stopping...
477  BOOST_CHECK( mtask.stop() == true );
478  BOOST_CHECK( r.fini == true );
479  BOOST_CHECK( mtask.isRunning() == false );
480  BOOST_CHECK( mtask.isActive() == false );
481  BOOST_CHECK( mtask.stop() == false );
482 
483  BOOST_CHECK( mtask.execute() == false );
484  BOOST_CHECK( mtask.trigger() == false );
485 
486  r.reset(false);
487  BOOST_CHECK( mtask.start() == false );
488  BOOST_CHECK( r.init == true );
489 
490  BOOST_CHECK( mtask.isActive() == false );
491  BOOST_CHECK( mtask.isRunning() == false );
492  BOOST_CHECK( mtask.start() == false );
493 }
494 
495 BOOST_AUTO_TEST_CASE( testScheduler )
496 {
497  int rtsched = ORO_SCHED_OTHER;
498  int bprio = 15;
499 
500  os::CheckPriority( rtsched, bprio );
501  TimerThreadPtr tt = TimerThread::Instance(rtsched, bprio, 0.0123);
502  BOOST_CHECK( tt != 0 );
503 
504  BOOST_CHECK( tt->isRunning() == false );
505 
506  BOOST_CHECK_EQUAL( 0.0123, tt->getPeriod());
507 
508  BOOST_CHECK_EQUAL( bprio, tt->getPriority());
509  BOOST_CHECK_EQUAL( rtsched, tt->getScheduler());
510 
511  // different scheduler, different thread.
512  rtsched = ORO_SCHED_RT;
513  bprio = 15;
514  if ( os::CheckPriority( rtsched, bprio ) ) {
515  TimerThreadPtr tt2 = TimerThread::Instance(rtsched, bprio, 0.0123);
516  BOOST_CHECK( tt2 != 0 );
517  BOOST_CHECK( tt2 != tt );
518  usleep(100000);
519  BOOST_CHECK_EQUAL( rtsched, tt2->getScheduler());
520 
521  tt = TimerThread::Instance(bprio, 0.0123); // ORO_SCHED_RT is the default.
522  BOOST_CHECK( tt == tt2 );
523  }
524 }
525 
526 #if !defined( OROCOS_TARGET_MACOSX )
527 #if !defined( OROCOS_TARGET_XENOMAI )
528 
531 BOOST_AUTO_TEST_CASE( testThreadPID )
532 {
533  unsigned int tid = t_task_a->getPid();
534  BOOST_CHECK( tid );
535  unsigned int mpid = MainThread::Instance()->getPid();
536  BOOST_CHECK( mpid );
537  BOOST_CHECK_NE( mpid, tid );
538 // cout << "PID:" << mpid <<endl;
539 // cout << "TID:" << tid << endl;
540 }
541 #endif
542 #endif
543 
544 #if !defined( OROCOS_TARGET_WIN32 )
545 BOOST_AUTO_TEST_CASE( testThreadConfig )
546 {
547  int rtsched = ORO_SCHED_RT;
548  int bprio = 15;
549  TimerThreadPtr tt = TimerThread::Instance(bprio, 0.0123);
550 
551  // Test creation of new thread, check functions when not running.
552  BOOST_CHECK( tt->isRunning() == false );
553 
554  BOOST_CHECK_EQUAL( 0.0123, tt->getPeriod());
555 
556  // only do this if valid priority/scheduler range:
557  if ( os::CheckPriority( rtsched, bprio ) == true)
558  {
559  BOOST_CHECK_EQUAL( bprio, tt->getPriority());
560 
561  // different priority, different thread.
562  TimerThreadPtr tt2 = TimerThread::Instance(bprio - 1, 0.0123);
563  BOOST_CHECK( tt2 != 0 );
564  BOOST_CHECK( tt2 != tt );
565 
566  // different period, different thread.
567  TimerThreadPtr tt3 = TimerThread::Instance(bprio, 0.123);
568  BOOST_CHECK( tt3 != 0 );
569  BOOST_CHECK( tt3 != tt );
570  BOOST_CHECK( tt3 != tt2 );
571  }
572 
573  tt = TimerThread::Instance(bprio, 0.0123);
574  BOOST_CHECK( tt != 0 );
575  BOOST_CHECK( tt == TimerThread::Instance(bprio,0.0123) );
576 
577  // switching hard/soft
578  // do not ASSERT since the ret-value may be false...
579  if ( tt->setScheduler(ORO_SCHED_OTHER) ) {
580  usleep(100000);
581  BOOST_CHECK( tt->getScheduler() == ORO_SCHED_OTHER );
582  }
583  if ( tt->setScheduler(ORO_SCHED_RT) ) {
584  usleep(100000);
585  BOOST_CHECK( tt->getScheduler() == ORO_SCHED_RT );
586  }
587  tt->setScheduler(ORO_SCHED_OTHER);
588  tt->setScheduler(ORO_SCHED_RT);
589  tt->setScheduler(ORO_SCHED_OTHER);
590  tt->setScheduler(ORO_SCHED_RT);
591  if ( tt->setPriority( 4 ) ) {
592  BOOST_CHECK_EQUAL( tt->getPriority(), 4 );
593 
594  // even if the priority was changed after construction,
595  // the thread can be found:
596  BOOST_CHECK( tt == TimerThread::Instance(4,0.0123) );
597  }
598 
599  BOOST_CHECK( tt->start() );
600 
601  // Check functions when running:
602  BOOST_CHECK( tt->isRunning() == true );
603 
604  // prints annoying warning messages...
607 #ifndef OROCOS_TARGET_XENOMAI // disabled until 'persistent' scheduler switching is implemented for Xenomai.
608  if ( tt->setScheduler(ORO_SCHED_RT) ) {
609  usleep(100000);
610  BOOST_CHECK( tt->getScheduler() == ORO_SCHED_RT );
611  }
612  if ( tt->setScheduler(ORO_SCHED_OTHER) ) {
613  usleep(100000);
614  BOOST_CHECK( tt->getScheduler() == ORO_SCHED_OTHER );
615  }
616 #endif
617  Logger::log().setLogLevel( ll );
618 
619  // reconfigure periodicity when running.
620  BOOST_CHECK( tt->setPeriod(0.5) == true );
621 
622  // reconfigure periodicity when stopped.
623  BOOST_CHECK( tt->stop() );
624  BOOST_CHECK( tt->setPeriod(0.3) );
625  BOOST_CHECK_EQUAL( Seconds_to_nsecs(0.3), tt->getPeriodNS() );
626 
627  // some quick start/stops.
628  BOOST_CHECK( tt->start() );
629  BOOST_CHECK( tt->stop() );
630  BOOST_CHECK( tt->start() );
631 
632 }
633 #endif
634 
635 #if !defined( ORO_EMBEDDED ) && !defined( OROCOS_TARGET_WIN32 )
636 BOOST_AUTO_TEST_CASE( testExceptionRecovery )
637 {
640  BOOST_CHECK(t_task_np->start());
641  BOOST_CHECK(t_task_np_bad->start()); // must stop t_task_np too.
642  BOOST_CHECK(t_task_p->start());
643  BOOST_CHECK(t_task_a->start());
644 
645  usleep(100000);
646 
647  // thread should stop :
648  Logger::log().setLogLevel( ll );
649  BOOST_CHECK( !t_task_np_bad->thread()->isRunning() );
650 
651  // This sometimes fails because of a bug in gnulinux Thread/fosi:
652  // two TimerThreads are created because the first one is not yet
653  // running, hence np_bad runs in a different thread than np...
654  BOOST_CHECK( !t_task_np->isRunning() );
655  BOOST_CHECK( !t_task_np_bad->isRunning() );
656  BOOST_CHECK( t_task_p->isRunning() );
657  BOOST_CHECK( !t_task_a->isRunning() );
658 
659  BOOST_CHECK( t_task_np->init );
660  BOOST_CHECK( t_task_np_bad->init );
661  BOOST_CHECK( t_task_p->init );
662  BOOST_CHECK( t_task_a->init );
663 
664  BOOST_CHECK( t_task_np->stepped );
665  BOOST_CHECK( t_task_np->wasrunning );
666  BOOST_CHECK( t_task_np->wasactive );
667 
668  BOOST_CHECK( t_task_np_bad->stepped );
669  BOOST_CHECK( t_task_np_bad->wasrunning );
670  BOOST_CHECK( t_task_np_bad->wasactive );
671 
672  BOOST_CHECK( t_task_p->stepped );
673  BOOST_CHECK( t_task_p->wasrunning );
674  BOOST_CHECK( t_task_p->wasactive );
675 
676  BOOST_CHECK( t_task_a->stepped );
677  BOOST_CHECK( t_task_a->wasrunning );
678  BOOST_CHECK( t_task_a->wasactive );
679 
680  // must be stopped since bad throwed an exception
681  BOOST_CHECK( t_task_np->fini );
682  BOOST_CHECK( t_task_np_bad->fini );
683  BOOST_CHECK( t_task_a->fini );
684 
685  t_task_p->stop();
686 
687  // see if we recovered ok :
689  // do not start np_bad
690  BOOST_CHECK(t_task_np->start());
691  BOOST_CHECK(t_task_a->start());
692 
693  usleep(100000);
694  Logger::log().setLogLevel( ll );
695  t_task_p->reset(true);
696  BOOST_CHECK( t_task_np->isRunning() );
697  BOOST_CHECK( t_task_np->init );
698  BOOST_CHECK( t_task_np->stepped );
699  BOOST_CHECK( t_task_np->wasrunning );
700  BOOST_CHECK( t_task_np->wasactive );
701 
702  BOOST_CHECK(t_task_np->stop());
703  BOOST_CHECK( t_task_np->fini );
704 }
705 #endif
706 
708 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
virtual int getScheduler() const =0
void work(RunnableInterface::WorkReason reason)
The default, thread-less activity for any newly created TaskContext.
virtual os::ThreadInterface * thread()
LogLevel getLogLevel() const
Definition: Logger.cpp:613
#define BOOST_AUTO_TEST_SUITE_END()
os::ThreadInterface * thread()
Definition: mystd.hpp:163
A class for running a certain piece of code in a thread.
int usleep(unsigned int us)
Definition: fosi.cpp:58
void reset(bool fail)
bool CheckPriority(int &sched_type, int &priority)
Definition: threads.cpp:51
boost::shared_ptr< TimerThread > TimerThreadPtr
Definition: TimerThread.hpp:61
BOOST_AUTO_TEST_CASE(testPeriodicActivity)
void reset(bool fail)
A PeriodicActivity is the general implementation of a Activity which has (realtime) periodic constrai...
virtual unsigned getCpuAffinity() const =0
TestActivity(int prio, double per, bool fail, bool dothrow=false)
nsecs Seconds_to_nsecs(const Seconds s)
Definition: os/Time.hpp:107
TestRunner(bool fail)
#define ORO_SCHED_RT
Definition: ecos/fosi.h:61
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
An base::ActivityInterface implementation which executes &#39;step&#39; upon the invocation of &#39;execute()&#39;...
static Logger & log()
Definition: Logger.hpp:350
#define ORO_SCHED_OTHER
Definition: ecos/fosi.h:62
Seconds getPeriod() const
void setLogLevel(LogLevel ll)
Definition: Logger.cpp:606


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