tasks_multiple_test.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 10 15:59:50 CET 2005  tasks_multiple_test.cpp
00003 
00004                         tasks_multiple_test.cpp -  description
00005                            -------------------
00006     begin                : Mon January 10 2005
00007     copyright            : (C) 2005 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "unit.hpp"
00020 
00021 #include "tasks_multiple_test.hpp"
00022 #include <os/threads.hpp>
00023 #include <Logger.hpp>
00024 
00025 #include <iostream>
00026 using namespace std;
00027 using namespace RTT;
00028 
00029 
00030     void ActivitiesMultipleTest::setUp()
00031     {
00032         nr_of_p = TimerThread::MAX_ACTIVITIES/2;
00033         nr_of_np = TimerThread::MAX_ACTIVITIES/2;
00034         runningP = 1;
00035         runningNp = 1; // see step() why it's 1 and not 0
00036         errInitNP = "Not all NonPreemptibleActivity::init() or finalize() functions were called.";
00037         errStepNP = "Not all NonPreemptibleActivity::step() functions were called.";
00038         errFinNP = "Not all NonPreemptibleActivity::finalize() or finalize() functions were called.";
00039         errInitP ="Not all PreemptibleActivity::init() functions were called.";
00040         errStepP ="Not all PreemptibleActivity::step() functions were called.";
00041         errFinP ="Not all PreemptibleActivity::finalize() functions were called.";
00042 
00043         log(Info) << "Creating "<< nr_of_np << " High priority and "<< nr_of_p << " Low priority activities."<<endlog();
00044 
00045         np_tasks.reserve(nr_of_np);
00046         p_tasks.reserve(nr_of_p);
00047         for (unsigned int i=0; i< nr_of_np/2; ++i)
00048             np_tasks.push_back( new DummyNPTask( os::HighestPriority, 0.004 ) );
00049         for (unsigned int i=0; i< nr_of_np/2; ++i)
00050             np_tasks.push_back( new DummyNPTask( os::HighestPriority, 0.004*2) );
00051         for (unsigned int i=0; i< nr_of_p/3; ++i)
00052             p_tasks.push_back( new DummyPTask( os::HighestPriority - os::IncreasePriority, 0.032 ) );
00053         for (unsigned int i=0; i< nr_of_p/3; ++i)
00054             p_tasks.push_back( new DummyPTask( os::HighestPriority - os::IncreasePriority, 0.032*2) );
00055         for (unsigned int i=0; i< nr_of_p/3; ++i)
00056             p_tasks.push_back( new DummyPTask( os::HighestPriority - os::IncreasePriority, 0.032*7) );
00057 
00058         log(Info) << "Done."<<endlog();
00059 
00060         nr_of_p = p_tasks.size();
00061         nr_of_np = np_tasks.size();
00062     }
00063 
00064 void ActivitiesMultipleTest::tearDown()
00065     {
00066         // stop to be sure that task does not access memory during destruction.
00067         for (NPI i=np_tasks.begin(); i != np_tasks.end(); ++i)
00068             {
00069                 (*i)->stop();
00070                 delete *i;
00071             }
00072         for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i)
00073             {
00074                 (*i)->stop();
00075                 delete *i;
00076             }
00077     }
00078 
00079 
00080 // Registers the fixture into the 'registry'
00081 BOOST_FIXTURE_TEST_SUITE( ActivitiesMultipleTestSuite, ActivitiesMultipleTest )
00082 
00083     BOOST_AUTO_TEST_CASE( testMultiple )
00084     {
00085         for (NPI i=np_tasks.begin(); i != np_tasks.end(); ++i)
00086             {
00087                 BOOST_CHECK( (*i)->start() );
00088             }
00089         for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i)
00090             {
00091                 BOOST_CHECK( (*i)->start() );
00092             }
00093 
00094         int runs = 0;
00095 
00096         // we lower the 'load' if the period is too short.
00097         // this is a bit arbitrary.
00098         int correction = 1;
00099 
00100         while ( runs++ != 100/correction ) {
00101             if ( np_tasks[runningNp]->isRunning() )
00102                 BOOST_CHECK( np_tasks[runningNp]->stop() );
00103             if ( !np_tasks[runningNp - 1]->isRunning() )
00104                 BOOST_CHECK( np_tasks[runningNp - 1]->start() );
00105 
00106             if ( p_tasks[runningP]->isRunning() )
00107                 BOOST_CHECK( p_tasks[runningP]->stop() );
00108             if ( !p_tasks[runningP - 1]->isRunning() )
00109                 BOOST_CHECK( p_tasks[runningP - 1]->start() );
00110 
00111             if ( ++runningP == nr_of_p) runningP = 1;
00112             if ( ++runningNp == nr_of_np) runningNp = 1;
00113             if ( runs % (20/correction) == 0 )
00114                 sleep(1);
00115         }
00116 
00117         for (NPI i=np_tasks.begin(); i != np_tasks.end(); ++i)
00118             {
00119                 if ( (*i)->isRunning() )
00120                     BOOST_CHECK( (*i)->stop() );
00121             }
00122         for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i)
00123             {
00124                 if ( (*i)->isRunning() )
00125                     BOOST_CHECK( (*i)->stop() );
00126             }
00127 
00128         for (unsigned int i=0; i < nr_of_np; ++i)
00129             {
00130                 BOOST_CHECK_EQUAL( np_tasks[i]->nrOfOKStarts(), np_tasks[i]->nrOfInits() );
00131                 //BOOST_CHECK_EQUAL( np_tasks[i]->nrOfOKStarts() , np_tasks[i]->nrOfStarts() );
00132 
00133                 BOOST_CHECK_EQUAL( np_tasks[i]->nrOfOKStops(), np_tasks[i]->nrOfFinals() );
00134                 //BOOST_CHECK_EQUAL( np_tasks[i]->nrOfOKStops() , np_tasks[i]->nrOfStops() );
00135             }
00136         for (unsigned int i=0; i < nr_of_p; ++i)
00137             {
00138                 BOOST_CHECK_EQUAL( p_tasks[i]->nrOfOKStarts(), p_tasks[i]->nrOfInits() );
00139                 //BOOST_CHECK_EQUAL( p_tasks[i]->nrOfOKStarts(), p_tasks[i]->nrOfStarts() );
00140                 BOOST_CHECK_EQUAL( p_tasks[i]->nrOfOKStops(), p_tasks[i]->nrOfFinals() );
00141                 //BOOST_CHECK_EQUAL( p_tasks[i]->nrOfOKStops(), p_tasks[i]->nrOfStops() );
00142             }
00143 
00144         int totInit=0, totSteps=0, totFins=0;
00145 
00146         // exclude first and last one from checking
00147         for (unsigned int i=1; i < nr_of_np-1; ++i)
00148             {
00149                 totInit += np_tasks[i]->nrOfInits();
00150                 totSteps += np_tasks[i]->nrOfSteps();
00151                 totFins += np_tasks[i]->nrOfFinals();
00152             }
00153         BOOST_CHECK_MESSAGE( totInit == totFins, errInitNP);
00154         BOOST_CHECK_MESSAGE( totSteps >= totInit, errStepNP );
00155         //BOOST_CHECK_MESSAGE(errFinNP, totFins == (nr_of_np-2) * 10 );
00156 
00157         totInit = totSteps = totFins = 0;
00158 
00159         for (unsigned int i=1; i < nr_of_p-1; ++i)
00160             {
00161                 totInit += p_tasks[i]->nrOfInits();
00162                 totSteps += p_tasks[i]->nrOfSteps();
00163                 totFins += p_tasks[i]->nrOfFinals();
00164             }
00165         BOOST_CHECK_MESSAGE(totInit == totFins, errInitP );
00166         BOOST_CHECK_MESSAGE(totSteps >= totInit, errStepP );
00167         //BOOST_CHECK_MESSAGE(errFinP, totFins == (nr_of_p-2) * 10 );
00168     }
00169 
00170 BOOST_AUTO_TEST_SUITE_END()


rtt
Author(s): RTT Developers
autogenerated on Thu Jan 2 2014 11:35:39