tasks_multiple_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 10 15:59:50 CET 2005 tasks_multiple_test.cpp
3 
4  tasks_multiple_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 #include "unit.hpp"
20 
21 #include "tasks_multiple_test.hpp"
22 #include <os/threads.hpp>
23 #include <Logger.hpp>
24 
25 #include <iostream>
26 using namespace std;
27 using namespace RTT;
28 
29 
31  {
32  nr_of_p = TimerThread::MAX_ACTIVITIES/2;
33  nr_of_np = TimerThread::MAX_ACTIVITIES/2;
34  runningP = 1;
35  runningNp = 1; // see step() why it's 1 and not 0
36  errInitNP = "Not all NonPreemptibleActivity::init() or finalize() functions were called.";
37  errStepNP = "Not all NonPreemptibleActivity::step() functions were called.";
38  errFinNP = "Not all NonPreemptibleActivity::finalize() or finalize() functions were called.";
39  errInitP ="Not all PreemptibleActivity::init() functions were called.";
40  errStepP ="Not all PreemptibleActivity::step() functions were called.";
41  errFinP ="Not all PreemptibleActivity::finalize() functions were called.";
42 
43  log(Info) << "Creating "<< nr_of_np << " High priority and "<< nr_of_p << " Low priority activities."<<endlog();
44 
45  np_tasks.reserve(nr_of_np);
46  p_tasks.reserve(nr_of_p);
47  for (unsigned int i=0; i< nr_of_np/2; ++i)
48  np_tasks.push_back( new DummyNPTask( os::HighestPriority, 0.004 ) );
49  for (unsigned int i=0; i< nr_of_np/2; ++i)
50  np_tasks.push_back( new DummyNPTask( os::HighestPriority, 0.004*2) );
51  for (unsigned int i=0; i< nr_of_p/3; ++i)
52  p_tasks.push_back( new DummyPTask( os::HighestPriority - os::IncreasePriority, 0.032 ) );
53  for (unsigned int i=0; i< nr_of_p/3; ++i)
54  p_tasks.push_back( new DummyPTask( os::HighestPriority - os::IncreasePriority, 0.032*2) );
55  for (unsigned int i=0; i< nr_of_p/3; ++i)
56  p_tasks.push_back( new DummyPTask( os::HighestPriority - os::IncreasePriority, 0.032*7) );
57 
58  log(Info) << "Done."<<endlog();
59 
60  nr_of_p = p_tasks.size();
61  nr_of_np = np_tasks.size();
62  }
63 
65  {
66  // stop to be sure that task does not access memory during destruction.
67  for (NPI i=np_tasks.begin(); i != np_tasks.end(); ++i)
68  {
69  (*i)->stop();
70  delete *i;
71  }
72  for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i)
73  {
74  (*i)->stop();
75  delete *i;
76  }
77  }
78 
79 
80 // Registers the fixture into the 'registry'
81 BOOST_FIXTURE_TEST_SUITE( ActivitiesMultipleTestSuite, ActivitiesMultipleTest )
82 
83  BOOST_AUTO_TEST_CASE( testMultiple )
84  {
85  for (NPI i=np_tasks.begin(); i != np_tasks.end(); ++i)
86  {
87  BOOST_CHECK( (*i)->start() );
88  }
89  for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i)
90  {
91  BOOST_CHECK( (*i)->start() );
92  }
93 
94  int runs = 0;
95 
96  // we lower the 'load' if the period is too short.
97  // this is a bit arbitrary.
98  int correction = 1;
99 
100  while ( runs++ != 100/correction ) {
101  if ( np_tasks[runningNp]->isRunning() )
102  BOOST_CHECK( np_tasks[runningNp]->stop() );
103  if ( !np_tasks[runningNp - 1]->isRunning() )
104  BOOST_CHECK( np_tasks[runningNp - 1]->start() );
105 
106  if ( p_tasks[runningP]->isRunning() )
107  BOOST_CHECK( p_tasks[runningP]->stop() );
108  if ( !p_tasks[runningP - 1]->isRunning() )
109  BOOST_CHECK( p_tasks[runningP - 1]->start() );
110 
111  if ( ++runningP == nr_of_p) runningP = 1;
112  if ( ++runningNp == nr_of_np) runningNp = 1;
113  if ( runs % (20/correction) == 0 )
114  sleep(1);
115  }
116 
117  for (NPI i=np_tasks.begin(); i != np_tasks.end(); ++i)
118  {
119  if ( (*i)->isRunning() )
120  BOOST_CHECK( (*i)->stop() );
121  }
122  for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i)
123  {
124  if ( (*i)->isRunning() )
125  BOOST_CHECK( (*i)->stop() );
126  }
127 
128  for (unsigned int i=0; i < nr_of_np; ++i)
129  {
130  BOOST_CHECK_EQUAL( np_tasks[i]->nrOfOKStarts(), np_tasks[i]->nrOfInits() );
131  //BOOST_CHECK_EQUAL( np_tasks[i]->nrOfOKStarts() , np_tasks[i]->nrOfStarts() );
132 
133  BOOST_CHECK_EQUAL( np_tasks[i]->nrOfOKStops(), np_tasks[i]->nrOfFinals() );
134  //BOOST_CHECK_EQUAL( np_tasks[i]->nrOfOKStops() , np_tasks[i]->nrOfStops() );
135  }
136  for (unsigned int i=0; i < nr_of_p; ++i)
137  {
138  BOOST_CHECK_EQUAL( p_tasks[i]->nrOfOKStarts(), p_tasks[i]->nrOfInits() );
139  //BOOST_CHECK_EQUAL( p_tasks[i]->nrOfOKStarts(), p_tasks[i]->nrOfStarts() );
140  BOOST_CHECK_EQUAL( p_tasks[i]->nrOfOKStops(), p_tasks[i]->nrOfFinals() );
141  //BOOST_CHECK_EQUAL( p_tasks[i]->nrOfOKStops(), p_tasks[i]->nrOfStops() );
142  }
143 
144  int totInit=0, totSteps=0, totFins=0;
145 
146  // exclude first and last one from checking
147  for (unsigned int i=1; i < nr_of_np-1; ++i)
148  {
149  totInit += np_tasks[i]->nrOfInits();
150  totSteps += np_tasks[i]->nrOfSteps();
151  totFins += np_tasks[i]->nrOfFinals();
152  }
153  BOOST_CHECK_MESSAGE( totInit == totFins, errInitNP);
154  BOOST_CHECK_MESSAGE( totSteps >= totInit, errStepNP );
155  //BOOST_CHECK_MESSAGE(errFinNP, totFins == (nr_of_np-2) * 10 );
156 
157  totInit = totSteps = totFins = 0;
158 
159  for (unsigned int i=1; i < nr_of_p-1; ++i)
160  {
161  totInit += p_tasks[i]->nrOfInits();
162  totSteps += p_tasks[i]->nrOfSteps();
163  totFins += p_tasks[i]->nrOfFinals();
164  }
165  BOOST_CHECK_MESSAGE(totInit == totFins, errInitP );
166  BOOST_CHECK_MESSAGE(totSteps >= totInit, errStepP );
167  //BOOST_CHECK_MESSAGE(errFinP, totFins == (nr_of_p-2) * 10 );
168  }
169 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
std::vector< DummyNPTask * >::iterator NPI
std::vector< DummyPTask * >::iterator PI
#define BOOST_AUTO_TEST_SUITE_END()
Definition: mystd.hpp:163
BOOST_AUTO_TEST_CASE(testMultiple)
const int HighestPriority
Definition: ecosthreads.cpp:45
unsigned int sleep(unsigned int s)
Definition: fosi.cpp:51
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
static Logger & log()
Definition: Logger.hpp:350
const int IncreasePriority
Definition: ecosthreads.cpp:46
static Logger::LogFunction endlog()
Definition: Logger.hpp:362


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