1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef example_diameter_launcher_TestManager_hpp
10 #define example_diameter_launcher_TestManager_hpp
13 #include <anna/config/defines.hpp>
14 #include <anna/core/util/Recycler.hpp>
15 #include <anna/core/Singleton.hpp>
16 #include <anna/timex/TimeEventObserver.hpp>
17 #include <anna/core/RuntimeException.hpp>
18 #include <anna/core/DataBlock.hpp>
21 #include <TestTimer.hpp>
43 typedef std::map<unsigned int /* test case id */, TestCase*> test_pool_t;
44 typedef std::map<unsigned int /* test case id */, TestCase*>::const_iterator test_pool_it;
45 typedef std::map<unsigned int /* test case id */, TestCase*>::iterator test_pool_nc_it;
49 Timer Manager for testing system
51 class TestManager : public anna::timex::TimeEventObserver, public anna::Singleton <TestManager> {
52 typedef anna::Recycler <TestTimer> timer_container;
54 anna::timex::Engine* a_timeController;
57 std::string a_reportsDirectory;
61 test_pool_t a_testPool;
62 test_pool_it a_currentTestIt;
63 bool a_poolRepeat; // repeat pool when finish
64 unsigned int a_inProgressCount;
65 unsigned int a_inProgressLimit; // limit load to have this value
68 int a_synchronousAmount;
71 bool nextTestCase() throw();
74 timer_container a_timers;
77 std::map<std::string /* session id's */, TestCase*> a_sessionIdTestCaseMap; // stores used Session-Id values within a test case.
78 // No other can use them, but a test case could use more than one.
82 TestManager(const TestManager&);
84 TestTimer* createTimer(TestCaseStep*, const anna::Millisecond &, const TestTimer::Type::_v type) throw(anna::RuntimeException);
85 void cancelTimer(TestTimer*) throw();
86 void release(anna::timex::TimeEvent*) throw();
90 void registerSessionId(const std::string &sessionId, const TestCase *testCase) throw(anna::RuntimeException);
92 int tests() const throw() { return a_testPool.size(); }
93 void setTimerController(anna::timex::Engine *engine) throw() { a_timeController = engine; }
95 void setReportsDirectory(const std::string &rd) throw() { a_reportsDirectory = rd; }
96 const std::string &getReportsDirectory() const throw() { return a_reportsDirectory; }
98 void setDumpReports(bool dr) throw() { a_dumpReports = dr; }
99 bool getDumpReports() const throw() { return a_dumpReports; }
101 // Helper to calculate time interval and synchronous amount of execution tests to guarantee the input rate (tests per second)
102 // through the time manager which has a minimum resolution of ADML minimum resolution. The first call to this method will
103 // start the time trigger system and check for new test cases to be launched.
104 bool configureTTPS(int testTicksPerSecond) throw();
106 bool clearPool() throw();
107 bool resetPool(bool hard /* hard reset includes in-progress test cases */) throw();
108 void setPoolRepeat(bool repeat) throw() { a_poolRepeat = repeat; }
109 bool getPoolRepeat() const throw() { return a_poolRepeat; }
110 unsigned int getInProgressCount() const throw() { return a_inProgressCount; }
111 void setInProgressCountDelta(unsigned int delta) throw() { a_inProgressCount += delta; }
112 unsigned int getInProgressLimit() const throw() { return a_inProgressLimit; }
113 void setInProgressLimit(unsigned int limit) throw() { a_inProgressLimit = limit; } // 0 = UINT_MAX (no limit)
115 bool gotoTestCase(unsigned int id) throw();
116 TestCase *findTestCase(unsigned int id) const throw(); // id = -1 provides current test case triggered
117 TestCase *getTestCase(unsigned int id) throw(); // creates/reuses a test case
120 TestCase *getTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw(anna::RuntimeException);
121 void receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException);
122 void receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException);
124 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
125 std::string asXMLString() const throw();
128 friend class anna::Singleton <TestManager>;
129 friend class TestStepTimeout; // createTimer
130 friend class TestStepDelay; // createTimer
131 friend class TestClock; // tick