taskstates_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp
3 
4  generictask_test_3.cpp - description
5  -------------------
6  begin : Mon June 26 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@fmtc.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 #include "unit.hpp"
20 
21 #include <iostream>
22 
23 #include <TaskContext.hpp>
24 #include <extras/SlaveActivity.hpp>
28 #include <os/fosi.h>
29 
30 #include <boost/function_types/function_type.hpp>
31 #include <OperationCaller.hpp>
32 
33 using namespace std;
34 using namespace RTT;
35 using namespace RTT::detail;
36 
37 struct A {};
38 
39 
40 // Test TaskContext states.
41 class StatesTC
42  : public RTT::TaskContext
43 {
44 public:
46  : TaskContext("TC", PreOperational)
47  {
48  BOOST_CHECK( this->getTaskState() == TaskContext::PreOperational );
49  BOOST_CHECK( this->getTargetState() == TaskContext::PreOperational );
50 
51  this->resetFlags();
52  validconfig = true;
53  validstart = true;
54  do_error = false;
55  do_fatal = false;
56  do_throw=false;
57  do_throw2=false;
58  do_throw3=false;
59  do_trigger=false;
60  do_breakUH=false;
61  do_block=false;
62  do_checks=true;
63  do_stop=false;
64  }
65 
66  void resetFlags()
67  {
68  didconfig = false;
69  didstart = false;
70  didstop = false;
71  didcleanup = false;
72  didupdate = false;
73  diderror = false;
74  didexcept = false;
75  didbreakUH = false;
76  updatecount=0;
77  do_stop=false;
78  }
79 
80  bool configureHook() {
81  if (do_checks) {
82  BOOST_CHECK( mTaskState <= Stopped );
83  BOOST_CHECK( getTargetState() == Stopped );
84  }
85  didconfig = true;
86  return validconfig;
87  }
88 
89  bool startHook() {
90  if (do_checks) {
91  BOOST_CHECK( mTaskState == Stopped);
92  BOOST_CHECK( getTargetState() == Running );
93  }
94  didstart = true;
95  return validstart;
96  }
97 
98  void stopHook() {
99  if (do_checks) {
100  BOOST_CHECK( mTaskState >= Running || mTaskState == Exception);
101  BOOST_CHECK( getTargetState() == Stopped || getTargetState() == Exception );
102  }
103  didstop = true;
104  }
105 
106  void cleanupHook() {
107  if (do_checks) {
108  BOOST_CHECK( mTaskState == Stopped || mTaskState == Exception);
109  BOOST_CHECK( getTargetState() == PreOperational || getTargetState() == Exception );
110  }
111  didcleanup = true;
112  }
113 
114  void exceptionHook() {
115  if (do_checks) {
116  BOOST_CHECK( mTaskState == Exception);
117  BOOST_CHECK( getTargetState() == Exception );
118  }
119  didexcept = true;
120  if (do_throw3)
121  throw A();
122  }
123 
124  void updateHook() {
125  if (do_checks) {
126  BOOST_CHECK( mTaskState == Running );
127  BOOST_CHECK( getTargetState() == Running );
128  }
129  didupdate = true;
130  updatecount++;
131  if (do_fatal)
132  this->fatal();
133  if (do_error)
134  this->error();
135  if (do_throw)
136  throw A();
137  if (do_trigger) {
138  this->trigger();
139  do_trigger = false; //avoid endless loop
140  }
141  if (do_block)
142  usleep(1*1000*1000);
143  if (do_stop)
144  this->stop();
145  }
146 
148  didbreakUH = true;
149  return do_breakUH;
150  }
151 
152  void errorHook() {
153  if (do_checks) {
154  BOOST_CHECK( mTaskState == RunTimeError );
155  BOOST_CHECK( getTargetState() == RunTimeError );
156  }
157  diderror = true;
158  if (do_fatal)
159  this->fatal();
160  if (do_throw2)
161  throw A();
162  }
163 
164  bool validconfig, didconfig;
165  bool validstart, didstart;
166  bool didstop;
168  bool didupdate,diderror,didexcept, didbreakUH;
169  bool do_fatal, do_error, do_throw,do_throw2,do_throw3, do_trigger, do_breakUH, do_block, do_checks, do_stop;
171 };
172 
177 {
178 public:
181  ActivityInterface* tsim;
182  ActivityInterface* stsim;
183 
184 public:
186  {
187  tc = new TaskContext( "root", TaskContext::Stopped );
188  stc = new StatesTC();
189  tc->setActivity( new SimulationActivity(0.001) );
190  stc->setActivity( new SimulationActivity(0.001) );
191  tsim = tc->getActivity();
192  stsim = stc->getActivity();
193  SimulationThread::Instance()->stop();
194  }
195 
197  {
198  tsim->stop();
199  stsim->stop();
200  delete tc;
201  delete stc;
202  }
203 };
204 
205 
206 // Registers the fixture into the 'registry'
207 BOOST_FIXTURE_TEST_SUITE( TaskStatesSuite, TaskStates_Test )
208 
209 
210 
214 {
215  // check unconfigured TC
216  TaskContext pertc("PerTC");
217  BOOST_CHECK( pertc.getPeriod() == 0.0 );
218  BOOST_CHECK( pertc.isActive() );
219 
220  // check periodic TC
221  BOOST_REQUIRE( pertc.getActivity()->stop() );
222  BOOST_REQUIRE( pertc.setActivity( new SlaveActivity(1.0) ) );
223  BOOST_CHECK( pertc.engine()->getActivity()->getPeriod() == 1.0 );
224  BOOST_CHECK( pertc.getPeriod() == 1.0 );
225 
226  // check non periodic TC
227  BOOST_REQUIRE( pertc.getActivity()->stop() );
228  BOOST_REQUIRE( pertc.setActivity( new SlaveActivity(0.0) ) );
229  BOOST_CHECK( pertc.engine()->getActivity()->getPeriod() == 0.0 );
230  BOOST_CHECK( pertc.getPeriod() == 0.0 );
231 }
232 
236 BOOST_AUTO_TEST_CASE( testTrigger )
237 {
238  // Check default TC
239  StatesTC trigtc;
240  trigtc.do_checks = false;
241  BOOST_CHECK( trigtc.getPeriod() == 0.0 );
242  BOOST_CHECK( trigtc.isActive() );
243  BOOST_CHECK( trigtc.trigger() == true );
244  usleep(100*1000);
245  // don't call updatehook when not running:
246  BOOST_CHECK_EQUAL( trigtc.updatecount, 0 );
247 
248  BOOST_CHECK( trigtc.configure() );
249  BOOST_CHECK( trigtc.trigger() == true );
250  usleep(100*1000);
251  // don't call updatehook when not running:
252  BOOST_CHECK_EQUAL( trigtc.updatecount, 0 );
253  BOOST_CHECK( trigtc.start() );
254  BOOST_CHECK( trigtc.didstart == true );
255  usleep(100*1000);
256 
257  // test updateHook() after start():
258  BOOST_CHECK_EQUAL( trigtc.updatecount, 1 );
259 
260  trigtc.resetFlags();
261 
262  // trigger() after start():
263  BOOST_CHECK( trigtc.trigger() );
264  usleep(100*1000);
265  BOOST_CHECK( trigtc.didstart == false );
266  BOOST_CHECK_EQUAL( trigtc.updatecount, 1 );
267 
268  // again:
269  BOOST_CHECK( trigtc.trigger() );
270  usleep(100*1000);
271  BOOST_CHECK_EQUAL( trigtc.updatecount, 2 );
272 
273  // this calls trigger() twice: once ourselves,
274  // and once from updateHook().
275  trigtc.do_trigger = true;
276  BOOST_CHECK( trigtc.trigger() );
277  usleep(100*1000);
278  BOOST_CHECK_EQUAL( trigtc.updatecount, 4 );
279  BOOST_CHECK( trigtc.do_trigger == false );
280 
281  // Check periodic TC ( rejects trigger() ):
282  TaskContext pertc("test");
283  pertc.setPeriod( 0.1 );
284  BOOST_CHECK_EQUAL( pertc.getPeriod(), 0.1 );
285  BOOST_CHECK( pertc.trigger() == false );
286  BOOST_CHECK( pertc.configure() == true );
287  BOOST_CHECK( pertc.trigger() == false );
288  BOOST_CHECK( pertc.start() == true );
289  BOOST_CHECK( pertc.trigger() == false );
290 }
291 
295 BOOST_AUTO_TEST_CASE( testBreakUpdateHook )
296 {
297  // Check default TC + blocking updateHook
298  StatesTC breaktc;
299  breaktc.do_checks = false;
300  BOOST_CHECK( breaktc.getPeriod() == 0.0 );
301  BOOST_CHECK( breaktc.isActive() );
302  breaktc.do_block = true;
303  BOOST_CHECK( breaktc.configure() );
304  BOOST_CHECK( breaktc.start() );
305  usleep(100*1000);
306  // we're blocking + breakUpdateHook() == false, so stop() fails:
307  BOOST_CHECK_EQUAL( breaktc.didupdate, true );
308  BOOST_CHECK_EQUAL( breaktc.stop(), false );
309  BOOST_CHECK_EQUAL( breaktc.didbreakUH, true);
310  BOOST_CHECK_EQUAL( breaktc.didstop, false);
311  breaktc.didbreakUH = false;
312  breaktc.do_breakUH = true;
313  breaktc.do_trigger = true;
314  // we're blocking *and* implementing breakUpdateHook():
315  BOOST_CHECK_EQUAL( breaktc.stop(), true );
316  BOOST_CHECK_EQUAL( breaktc.didbreakUH, true);
317  BOOST_CHECK_EQUAL( breaktc.didstop, true);
318 }
319 
323 BOOST_AUTO_TEST_CASE( testStopInUpdateHook )
324 {
325  // Check default TC + stop in UH
326  StatesTC breaktc;
327  breaktc.do_checks = false;
328  breaktc.do_stop = true;
329  BOOST_CHECK( breaktc.getPeriod() == 0.0 );
330  BOOST_CHECK( breaktc.isActive() );
331  BOOST_CHECK( breaktc.configure() );
332  BOOST_CHECK( breaktc.start() );
333  usleep(100*1000);
334  // check a failed stop() from UH:
335  breaktc.do_breakUH = false;
336  BOOST_CHECK_EQUAL( breaktc.didupdate, true );
337  BOOST_CHECK_EQUAL( breaktc.didbreakUH, true);
338  BOOST_CHECK_EQUAL( breaktc.didstop, false);
339  BOOST_CHECK_EQUAL( breaktc.isRunning(), true);
340 
341  // check a succesful stop() from UH:
342  breaktc.do_breakUH = true;
343  breaktc.didbreakUH = false;
344  breaktc.didstop = false;
345  breaktc.didupdate = false;
346  BOOST_CHECK( breaktc.trigger() );
347  usleep(100*1000);
348  BOOST_CHECK_EQUAL( breaktc.didupdate, true );
349  BOOST_CHECK_EQUAL( breaktc.didbreakUH, true);
350  BOOST_CHECK_EQUAL( breaktc.didstop, true);
351  BOOST_CHECK_EQUAL( breaktc.isRunning(), false);
352 }
353 
357 BOOST_AUTO_TEST_CASE( testSetPeriod )
358 {
359  TaskContext pertc("test");
360  BOOST_CHECK( pertc.setPeriod( 0.1 ) );
361  BOOST_CHECK_EQUAL( pertc.getPeriod(), 0.1 );
362  BOOST_CHECK( pertc.configure() == true);
363  BOOST_CHECK( pertc.setPeriod( 0.2 ) );
364  BOOST_CHECK_EQUAL( pertc.getPeriod(), 0.2 );
365  BOOST_CHECK( pertc.start() == true );
366 
367  BOOST_CHECK( pertc.setPeriod( 0.5 ) );
368  BOOST_CHECK_EQUAL( pertc.getPeriod(), 0.5 );
369 }
370 
374 BOOST_AUTO_TEST_CASE( testTCStates)
375 {
376  // Test the states of a Default TC, no user methods.
377  BOOST_CHECK( tc->getTaskState() == TaskContext::Stopped );
378 
379  // Configure in Stop
380  BOOST_CHECK( tc->isConfigured() == true );
381  BOOST_CHECK( tc->isRunning() == false );
382  BOOST_CHECK( tc->isActive() == true );
383  BOOST_CHECK( tc->configure() == true );
384 
385  // Stop to Running
386  BOOST_CHECK( tc->start() == true );
387  BOOST_CHECK( tc->isRunning() == true );
388  BOOST_CHECK( tc->isActive() == true );
389  BOOST_CHECK( tc->configure() == false );
390  BOOST_CHECK( tc->start() == false );
391  BOOST_CHECK( tc->cleanup() == false );
392 
393  // Running to Stop
394  BOOST_CHECK( tc->stop() == true );
395  BOOST_CHECK( tc->isRunning() == false);
396  BOOST_CHECK( tc->isActive() == true );
397  BOOST_CHECK( tc->stop() == false );
398  BOOST_CHECK( tc->configure() == true );
399  BOOST_CHECK( tc->isConfigured() == true );
400 
401  // Engine Stop to Active to Stop
402  BOOST_CHECK( tc->engine()->getActivity()->stop() == true);
403  BOOST_CHECK( tc->isActive() == false);
404  BOOST_CHECK( tc->activate() == true );
405  BOOST_CHECK( tc->isActive() == true);
406  BOOST_CHECK( tc->isRunning() == false );
407  BOOST_CHECK( tc->configure() == true );
408  BOOST_CHECK( tc->isConfigured() == true );
409 
410  // Stop to PreOp
411  BOOST_CHECK( tc->cleanup() == true );
412  BOOST_CHECK( tc->isConfigured() == false);
413  BOOST_CHECK( tc->isRunning() == false);
414 
415  // PreOp to stop
416  BOOST_CHECK( tc->configure() == true );
417  BOOST_CHECK( tc->isConfigured() == true);
418  BOOST_CHECK( tc->isRunning() == false);
419  BOOST_CHECK( tc->isActive() == true );
420 
421 }
422 
426 BOOST_AUTO_TEST_CASE( testSpecialTCStates)
427 {
428  // Test the states of a Specially crafted TC, requiring configure etc.
429  BOOST_CHECK( stc->getTaskState() == TaskContext::PreOperational );
430 
431  // PreOperational state:
432  BOOST_CHECK( stc->configure() == true );
433  BOOST_CHECK( stc->didconfig == true );
434  BOOST_CHECK( stc->isConfigured() == true );
435  // test flags
436  BOOST_CHECK( stc->didstart == false );
437  BOOST_CHECK( stc->didupdate == false );
438  BOOST_CHECK( stc->diderror == false );
439  BOOST_CHECK( stc->didexcept == false );
440  BOOST_CHECK( stc->didstop == false );
441  BOOST_CHECK( stc->didcleanup == false );
442  stc->resetFlags();
443 
444  // Stopped state:
445  BOOST_CHECK( stc->start() == true );
446  BOOST_CHECK( stc->didstart == true );
447  BOOST_CHECK( stc->isRunning() == true );
448  // test flags
449  BOOST_CHECK( stc->didconfig == false );
450  BOOST_CHECK( stc->didupdate == false );
451  BOOST_CHECK( stc->diderror == false );
452  BOOST_CHECK( stc->didexcept == false );
453  BOOST_CHECK( stc->didstop == false );
454  BOOST_CHECK( stc->didcleanup == false );
455  stc->resetFlags();
456 
457 
458  // Running state / updateHook :
459  SimulationThread::Instance()->run(1);
460  // test flags
461  BOOST_CHECK( stc->didconfig == false );
462  BOOST_CHECK( stc->didstart == false );
463  BOOST_CHECK( stc->didupdate == true );
464  BOOST_CHECK( stc->diderror == false );
465  BOOST_CHECK( stc->didexcept == false );
466  BOOST_CHECK( stc->didstop == false );
467  BOOST_CHECK( stc->didcleanup == false );
468  stc->resetFlags();
469 
470  // Back to stopped
471  BOOST_CHECK( stc->stop() == true );
472  BOOST_CHECK( stc->didstop == true );
473  BOOST_CHECK( stc->isRunning() == false );
474  // test flags
475  BOOST_CHECK( stc->didconfig == false );
476  BOOST_CHECK( stc->didstart == false );
477  BOOST_CHECK( stc->didupdate == false );
478  BOOST_CHECK( stc->diderror == false );
479  BOOST_CHECK( stc->didexcept == false );
480  BOOST_CHECK( stc->didcleanup == false );
481  stc->resetFlags();
482 
483  // Reconfigure in stopped
484  BOOST_CHECK( stc->configure() == true );
485  BOOST_CHECK( stc->didconfig == true );
486  BOOST_CHECK( stc->isConfigured() == true );
487  // test flags
488  BOOST_CHECK( stc->didstart == false );
489  BOOST_CHECK( stc->didupdate == false );
490  BOOST_CHECK( stc->diderror == false );
491  BOOST_CHECK( stc->didexcept == false );
492  BOOST_CHECK( stc->didstop == false );
493  BOOST_CHECK( stc->didcleanup == false );
494  stc->resetFlags();
495 
496  // Stopped to PreOp state:
497  BOOST_CHECK( stc->cleanup() == true );
498  BOOST_CHECK( stc->didcleanup == true );
499  BOOST_CHECK( stc->isConfigured() == false);
500  // test flags
501  BOOST_CHECK( stc->didconfig == false );
502  BOOST_CHECK( stc->didstart == false );
503  BOOST_CHECK( stc->didupdate == false );
504  BOOST_CHECK( stc->diderror == false );
505  BOOST_CHECK( stc->didexcept == false );
506  BOOST_CHECK( stc->didstop == false );
507  stc->resetFlags();
508 }
509 
513 BOOST_AUTO_TEST_CASE( testFailingTCStates)
514 {
515  // Test the states of a TC failing in transitions
516  stc->validconfig = false;
517  stc->validstart = false;
518 
519  // Failed configure() in PreOperational state:
520  BOOST_CHECK( stc->isConfigured() == false );
521  BOOST_CHECK( stc->isRunning() == false );
522  BOOST_CHECK( stc->configure() == false );
523  BOOST_CHECK( stc->didconfig == true );
524  BOOST_CHECK( stc->isConfigured() == false );
525  BOOST_CHECK( stc->isRunning() == false );
526  BOOST_CHECK( stc->isActive() == true );
527  stc->resetFlags();
528 
529  // Retry:
530  stc->validconfig = true;
531  BOOST_CHECK( stc->configure() == true );
532  BOOST_CHECK( stc->didconfig == true );
533  BOOST_CHECK( stc->isConfigured() == true );
534  BOOST_CHECK( stc->isRunning() == false );
535  BOOST_CHECK( stc->isActive() == true );
536  stc->resetFlags();
537 
538  // Failed start() in Stopped state:
539  BOOST_CHECK( stc->start() == false );
540  BOOST_CHECK( stc->didstart == true );
541  BOOST_CHECK( stc->isRunning() == false );
542  BOOST_CHECK( stc->isActive() == true );
543  BOOST_CHECK( stc->isConfigured() == true );
544  stc->resetFlags();
545 
546  // Retry:
547  stc->validstart = true;
548  BOOST_CHECK( stc->start() == true );
549  BOOST_CHECK( stc->didstart == true );
550  BOOST_CHECK( stc->isConfigured() == true );
551  BOOST_CHECK( stc->isRunning() == true );
552  BOOST_CHECK( stc->isActive() == true );
553  stc->resetFlags();
554 
555  // Error state by calling error().
556  stc->do_error = true;
557  // Running state / updateHook :
558  SimulationThread::Instance()->run(1);
559  BOOST_CHECK( stc->inRunTimeError() == true );
560  BOOST_CHECK( stc->diderror == true );
561  BOOST_CHECK( stc->didexcept == false );
562  BOOST_CHECK( stc->isActive() == true ); // still active
563  stc->resetFlags();
564  stc->do_error = false;
565  stc->recover();
566  SimulationThread::Instance()->run(1);
567  BOOST_CHECK( stc->isRunning() == true );
568  BOOST_CHECK( stc->diderror == false );
569  BOOST_CHECK( stc->didupdate == true );
570 
571  // Error state by throwing in updateHook()
572  stc->do_throw = true;
573  // Running state / updateHook :
574  SimulationThread::Instance()->run(1);
575  BOOST_CHECK( stc->inRunTimeError() == false );
576  BOOST_CHECK( stc->inException() == true );
577  BOOST_CHECK( stc->didexcept == true );
578  BOOST_CHECK( stc->isActive() == true ); // still active
579  stc->resetFlags();
580  stc->do_throw = false;
581  stc->recover();
582  SimulationThread::Instance()->run(1);
583  BOOST_CHECK( stc->isConfigured() == false );
584  BOOST_CHECK( stc->diderror == false );
585  BOOST_CHECK( stc->didupdate == false );
586  stc->resetFlags();
587  stc->configure();
588  stc->start();
589 
590  // Fatal Error state by throwing in exceptionHook()
591  stc->do_error = false;
592  stc->do_throw = true;
593  stc->do_throw3 = true;
594  // Running state / updateHook :
595  SimulationThread::Instance()->run(1);
596  BOOST_CHECK( stc->inRunTimeError() == false );
597  BOOST_CHECK( stc->inFatalError() == true );
598  BOOST_CHECK( stc->diderror == false );
599  BOOST_CHECK( stc->didexcept == true );
600  BOOST_CHECK( stc->didstop == true );
601  BOOST_CHECK( stc->didcleanup == true );
602  BOOST_CHECK( stc->isActive() == false );
603  BOOST_CHECK( stc->isRunning() == false );
604  BOOST_CHECK( stc->isConfigured() == false );
605  stc->resetFlags();
606 
607  // Component stuck in fatal error state.
608  BOOST_CHECK( stc->configure() == false );
609  BOOST_CHECK( stc->start() == false );
610 }
611 
613 {
614 public:
616  : TaskContext("test") {}
617  void updateHook() { error(); }
618  void errorHook() {
619  while(getTargetState() != Stopped) {
620  TIME_SPEC t = ticks2timespec(nano2ticks(100000000LL));
621  rtos_nanosleep(&t, 0);
622  }
623  error();
624  trigger();
625  }
626 };
627 BOOST_AUTO_TEST_CASE(calling_error_does_not_override_a_stop_transition)
628 {
629  for (int i = 0; i < 100; ++i)
630  {
632  task.start();
633  while(!task.inRunTimeError()) {
634  usleep(100);
635  }
636  task.stop();
637  BOOST_REQUIRE_EQUAL(RTT::TaskContext::Stopped, task.getTaskState());
638  BOOST_REQUIRE_EQUAL(RTT::TaskContext::Stopped, task.getTargetState());
639  }
640 }
641 
643 {
644 public:
648  : TaskContext("test"), mRecovered(true) {} // true is an error
649  void updateHook() { error(); }
650  void errorHook() {
651  while(getTargetState() != Stopped) {
652  TIME_SPEC t = ticks2timespec(nano2ticks(100000000LL));
653  rtos_nanosleep(&t, 0);
654  }
655  mRecovered = recover();
656  trigger();
657  }
658 };
659 BOOST_AUTO_TEST_CASE(calling_recover_does_not_override_a_stop_transition)
660 {
661  for (int i = 0; i < 100; ++i)
662  {
664  task.start();
665  while(!task.inRunTimeError()) {
666  usleep(100);
667  }
668  task.stop();
669  BOOST_REQUIRE_EQUAL(RTT::TaskContext::Stopped, task.getTaskState());
670  BOOST_REQUIRE_EQUAL(RTT::TaskContext::Stopped, task.getTargetState());
671  BOOST_REQUIRE(!task.mRecovered);
672  }
673 }
674 
676 {
677 public:
680 
682  : TaskContext("test") {}
683  void updateHook() { error(); }
684  void errorHook() {
685  TIME_SPEC t = ticks2timespec(nano2ticks(100000000LL));
686  rtos_nanosleep(&t, 0);
687  lastErrorHook = TimeService::Instance()->getTicks();
688  trigger();
689  }
690  void stopHook() {
691  lastStopHook = TimeService::Instance()->getTicks();
692  usleep(100);
693  }
694 };
695 BOOST_AUTO_TEST_CASE(testErrorHook_is_not_called_during_stop)
696 {
697  for (int i = 0; i < 100; ++i)
698  {
700  task.start();
701  while(!task.inRunTimeError()) {
702  usleep(100);
703  }
704  task.stop();
705  BOOST_REQUIRE(task.lastErrorHook < task.lastStopHook);
706  }
707 }
708 
710  public RTT::TaskContext
711 {
713  : RTT::TaskContext("test", RTT::TaskContext::PreOperational) {}
715  {
716  exception();
717  return true;
718  }
719 };
720 BOOST_AUTO_TEST_CASE(testTaskCore_bails_out_if_configureHook_returns_true_but_exception_was_called) {
722  task.configure();
723  BOOST_REQUIRE(task.inException());
724 }
725 
727  public RTT::TaskContext
728 {
730  : RTT::TaskContext("test", RTT::TaskContext::PreOperational) {}
731  bool startHook()
732  {
733  exception();
734  return true;
735  }
736 };
737 BOOST_AUTO_TEST_CASE(testTaskCore_bails_out_if_startHook_returns_true_but_exception_was_called) {
739  task.configure();
740  task.start();
741  BOOST_REQUIRE(task.inException());
742 }
743 
745 
void exceptionHook()
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
bool configureHook()
ActivityInterface * getActivity() const
Query for the task this interface is run in.
virtual bool trigger()
Definition: TaskCore.cpp:91
virtual bool stop()
void errorHook()
#define BOOST_AUTO_TEST_SUITE_END()
void stopHook()
Definition: mystd.hpp:163
virtual TaskState getTargetState() const
Definition: TaskCore.cpp:82
static int rtos_nanosleep(const TIME_SPEC *rqtp, TIME_SPEC *rmtp)
int usleep(unsigned int us)
Definition: fosi.cpp:58
virtual bool isRunning() const
Definition: TaskCore.cpp:266
virtual bool configure()
Definition: TaskCore.cpp:96
bool setActivity(base::ActivityInterface *new_act)
ActivityInterface * tsim
virtual Seconds getPeriod() const
Definition: TaskCore.cpp:291
virtual bool inException() const
Definition: TaskCore.cpp:278
void updateHook()
virtual Seconds getPeriod() const =0
static TIME_SPEC ticks2timespec(TICK_TIME hrt)
bool breakUpdateHook()
virtual TaskState getTaskState() const
Definition: TaskCore.cpp:78
virtual bool isActive() const
Definition: TaskCore.cpp:286
virtual bool inRunTimeError() const
Definition: TaskCore.cpp:282
void resetFlags()
TaskContext * tc
TICK_TIME nano2ticks(NANO_TIME nano)
Definition: ecos/fosi.h:112
void cleanupHook()
bool startHook()
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
ActivityInterface * stsim
The state indicating the component is ready to run.
Definition: TaskCore.hpp:104
A SimulationActivity is a PeriodicActivity which is used for simulation.
BOOST_AUTO_TEST_CASE(testPeriod)
An base::ActivityInterface implementation which executes &#39;step&#39; upon the invocation of &#39;execute()&#39;...
struct timespec TIME_SPEC
Definition: ecos/fosi.h:109
virtual bool setPeriod(Seconds s)
Definition: TaskCore.cpp:296
const ExecutionEngine * engine() const
Definition: TaskCore.hpp:306
virtual bool start()
base::ActivityInterface * getActivity()
static bool trigger(TaskContext *tc)


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:44