31 #include <rtt-config.h> 46 TestActivity(
int prio,
double per,
bool fail,
bool dothrow =
false)
47 :T(prio,per), _dothrow(dothrow)
59 wasrunning = this->isRunning();
60 wasactive = this->isActive();
111 BOOST_CHECK(getActivity()->isActive());
112 BOOST_CHECK(!getActivity()->isRunning());
118 wasrunning=getActivity()->isRunning();
119 wasactive=getActivity()->isActive();
129 wasrunning=getActivity()->isRunning();
130 wasactive=getActivity()->isActive();
140 BOOST_CHECK(getActivity()->isActive());
141 BOOST_CHECK(!getActivity()->isRunning());
173 delete t_task_np_bad;
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() );
195 BOOST_CHECK_EQUAL( bprio, mtask.thread()->getPriority() );
196 BOOST_CHECK_EQUAL( rtsched, mtask.thread()->getScheduler() );
199 BOOST_CHECK( mtask.thread() == m2task.thread() );
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 );
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 );
219 BOOST_CHECK( mtask.
looped ==
false );
220 BOOST_CHECK( mtask.
stepped ==
true );
221 BOOST_CHECK( m2task.looped ==
false );
222 BOOST_CHECK( m2task.stepped ==
true );
232 BOOST_CHECK( mtask.thread() != m3task.
thread() );
238 unsigned cpu_affinity = 1;
239 if ( mtask.thread()->getCpuAffinity() != (unsigned) ~0 &&
240 mtask.thread()->getCpuAffinity() != cpu_affinity ) {
242 BOOST_CHECK( mtask.thread() != m4task.
thread() );
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);
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() );
271 BOOST_CHECK( mtask.thread() != m2task.thread() );
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 );
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 );
290 BOOST_CHECK( mtask.
looped ==
true );
291 BOOST_CHECK( mtask.
stepped ==
true );
292 BOOST_CHECK( m2task.looped ==
true );
293 BOOST_CHECK( m2task.stepped ==
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() );
310 BOOST_CHECK_EQUAL( bprio, mtask.thread()->getPriority() );
311 BOOST_CHECK_EQUAL( rtsched, mtask.thread()->getScheduler() );
314 BOOST_CHECK( mtask.thread() != m2task.thread() );
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 );
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 );
335 BOOST_CHECK( mtask.
stepped ==
true );
337 BOOST_CHECK( m2task.stepped ==
true );
347 BOOST_CHECK( mtask.
isActive() == false );
348 BOOST_CHECK( mtask.
isRunning() == false );
351 BOOST_CHECK( mtask.
execute() == false );
352 BOOST_CHECK( mtask.
thread() == os::MainThread::Instance() );
355 BOOST_CHECK( mtask.
start() == true );
356 BOOST_CHECK( r.
init ==
true );
358 BOOST_CHECK( mtask.
isActive() == true );
359 BOOST_CHECK( mtask.
isRunning() == false );
360 BOOST_CHECK( mtask.
start() == false );
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() );
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 );
378 BOOST_CHECK( mtask.
execute() == false );
384 BOOST_CHECK( mslave.
isActive() == false );
385 BOOST_CHECK( mslave.
isRunning() == false );
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() );
391 BOOST_CHECK( !mslave.
start() );
392 BOOST_CHECK( t_task_np->start() );
393 BOOST_CHECK( mslave.
start() );
394 BOOST_CHECK( r.
init ==
true );
399 BOOST_CHECK( mslave.
execute() );
400 BOOST_CHECK( r.
stepped ==
true );
403 BOOST_CHECK( r.
worked ==
true );
404 BOOST_CHECK( r.
wreason == RunnableInterface::TimeOut );
405 BOOST_CHECK( mslave.
execute() );
406 BOOST_CHECK( !mslave.
start() );
409 BOOST_CHECK( mslave.
stop() );
410 BOOST_CHECK( r.
fini ==
true );
418 BOOST_CHECK( mslave_p.
isActive() == false );
419 BOOST_CHECK( mslave_p.
isRunning() == false );
421 BOOST_CHECK( mslave_p.
getPeriod() == 0.001 );
422 BOOST_CHECK( mslave_p.
execute() == false );
423 BOOST_CHECK( mslave_p.
thread() == os::MainThread::Instance() );
425 BOOST_CHECK( mslave_p.
start() );
426 BOOST_CHECK( r.
init ==
true );
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 );
435 BOOST_CHECK( !mslave_p.
start() );
438 BOOST_CHECK( mslave_p.
stop() );
439 BOOST_CHECK( r.
fini ==
true );
440 BOOST_CHECK( !mslave_p.
isActive() );
442 BOOST_CHECK( !mslave_p.
execute() );
451 BOOST_CHECK( mtask.
isActive() == false );
452 BOOST_CHECK( mtask.
isRunning() == false );
455 BOOST_CHECK( mtask.
execute() == false );
456 BOOST_CHECK( mtask.
trigger() == false );
457 BOOST_CHECK( mtask.
thread() == os::MainThread::Instance() );
460 BOOST_CHECK( mtask.
start() == true );
461 BOOST_CHECK( r.
init ==
true );
463 BOOST_CHECK( mtask.
isActive() == true );
464 BOOST_CHECK( mtask.
isRunning() == false );
465 BOOST_CHECK( mtask.
start() == false );
468 BOOST_CHECK( mtask.
trigger() );
469 BOOST_CHECK( r.
stepped ==
true );
470 BOOST_CHECK( r.
worked ==
true );
471 BOOST_CHECK( r.
wreason == RunnableInterface::TimeOut );
474 BOOST_CHECK( mtask.
execute() == false );
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 );
483 BOOST_CHECK( mtask.
execute() == false );
484 BOOST_CHECK( mtask.
trigger() == false );
487 BOOST_CHECK( mtask.
start() == false );
488 BOOST_CHECK( r.
init ==
true );
490 BOOST_CHECK( mtask.
isActive() == false );
491 BOOST_CHECK( mtask.
isRunning() == false );
492 BOOST_CHECK( mtask.
start() == false );
502 BOOST_CHECK( tt != 0 );
504 BOOST_CHECK( tt->isRunning() == false );
506 BOOST_CHECK_EQUAL( 0.0123, tt->getPeriod());
508 BOOST_CHECK_EQUAL( bprio, tt->getPriority());
509 BOOST_CHECK_EQUAL( rtsched, tt->getScheduler());
515 TimerThreadPtr tt2 = TimerThread::Instance(rtsched, bprio, 0.0123);
516 BOOST_CHECK( tt2 != 0 );
517 BOOST_CHECK( tt2 != tt );
519 BOOST_CHECK_EQUAL( rtsched, tt2->getScheduler());
521 tt = TimerThread::Instance(bprio, 0.0123);
522 BOOST_CHECK( tt == tt2 );
526 #if !defined( OROCOS_TARGET_MACOSX ) 527 #if !defined( OROCOS_TARGET_XENOMAI ) 533 unsigned int tid = t_task_a->getPid();
535 unsigned int mpid = MainThread::Instance()->getPid();
537 BOOST_CHECK_NE( mpid, tid );
544 #if !defined( OROCOS_TARGET_WIN32 ) 552 BOOST_CHECK( tt->isRunning() == false );
554 BOOST_CHECK_EQUAL( 0.0123, tt->getPeriod());
559 BOOST_CHECK_EQUAL( bprio, tt->getPriority());
563 BOOST_CHECK( tt2 != 0 );
564 BOOST_CHECK( tt2 != tt );
568 BOOST_CHECK( tt3 != 0 );
569 BOOST_CHECK( tt3 != tt );
570 BOOST_CHECK( tt3 != tt2 );
573 tt = TimerThread::Instance(bprio, 0.0123);
574 BOOST_CHECK( tt != 0 );
575 BOOST_CHECK( tt == TimerThread::Instance(bprio,0.0123) );
591 if ( tt->setPriority( 4 ) ) {
592 BOOST_CHECK_EQUAL( tt->getPriority(), 4 );
596 BOOST_CHECK( tt == TimerThread::Instance(4,0.0123) );
599 BOOST_CHECK( tt->start() );
602 BOOST_CHECK( tt->isRunning() == true );
607 #ifndef OROCOS_TARGET_XENOMAI // disabled until 'persistent' scheduler switching is implemented for Xenomai. 620 BOOST_CHECK( tt->setPeriod(0.5) == true );
623 BOOST_CHECK( tt->stop() );
624 BOOST_CHECK( tt->setPeriod(0.3) );
628 BOOST_CHECK( tt->start() );
629 BOOST_CHECK( tt->stop() );
630 BOOST_CHECK( tt->start() );
635 #if !defined( ORO_EMBEDDED ) && !defined( OROCOS_TARGET_WIN32 ) 640 BOOST_CHECK(t_task_np->start());
641 BOOST_CHECK(t_task_np_bad->start());
642 BOOST_CHECK(t_task_p->start());
643 BOOST_CHECK(t_task_a->start());
649 BOOST_CHECK( !t_task_np_bad->thread()->isRunning() );
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() );
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 );
664 BOOST_CHECK( t_task_np->stepped );
665 BOOST_CHECK( t_task_np->wasrunning );
666 BOOST_CHECK( t_task_np->wasactive );
668 BOOST_CHECK( t_task_np_bad->stepped );
669 BOOST_CHECK( t_task_np_bad->wasrunning );
670 BOOST_CHECK( t_task_np_bad->wasactive );
672 BOOST_CHECK( t_task_p->stepped );
673 BOOST_CHECK( t_task_p->wasrunning );
674 BOOST_CHECK( t_task_p->wasactive );
676 BOOST_CHECK( t_task_a->stepped );
677 BOOST_CHECK( t_task_a->wasrunning );
678 BOOST_CHECK( t_task_a->wasactive );
681 BOOST_CHECK( t_task_np->fini );
682 BOOST_CHECK( t_task_np_bad->fini );
683 BOOST_CHECK( t_task_a->fini );
690 BOOST_CHECK(t_task_np->start());
691 BOOST_CHECK(t_task_a->start());
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 );
702 BOOST_CHECK(t_task_np->stop());
703 BOOST_CHECK( t_task_np->fini );
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
virtual int getScheduler() const =0
void work(RunnableInterface::WorkReason reason)
LogLevel getLogLevel() const
#define BOOST_AUTO_TEST_SUITE_END()
A class for running a certain piece of code in a thread.
int usleep(unsigned int us)
bool CheckPriority(int &sched_type, int &priority)
BOOST_AUTO_TEST_CASE(testPeriodicActivity)
virtual unsigned getCpuAffinity() const =0
TestActivity(int prio, double per, bool fail, bool dothrow=false)
nsecs Seconds_to_nsecs(const Seconds s)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
void setLogLevel(LogLevel ll)