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 anna_testing_TestManager_hpp
10 #define anna_testing_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>
19 #include <anna/testing/TestTimer.hpp>
20 #include <anna/testing/TestCase.hpp>
44 typedef std::map<unsigned int /* test case id */, TestCase*> test_pool_t;
45 typedef std::map<unsigned int /* test case id */, TestCase*>::const_iterator test_pool_it;
46 typedef std::map<unsigned int /* test case id */, TestCase*>::iterator test_pool_nc_it;
50 Timer Manager for testing system
52 class TestManager : public anna::timex::TimeEventObserver, public anna::Singleton <TestManager> {
54 // Statistics summary:
57 unsigned int a_initializedTcs;
58 unsigned int a_inprogressTcs;
59 unsigned int a_failedTcs;
60 unsigned int a_sucessTcs;
63 StatSummary() { clear(); }
64 void newTCState(const TestCase::State::_v beginState, const TestCase::State::_v endState) throw();
66 unsigned int getInProgressCount() const throw() { return a_inprogressTcs; }
67 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
72 typedef anna::Recycler <TestTimer> timer_container;
74 anna::timex::Engine* a_timeController;
77 std::string a_reportsDirectory;
78 bool a_dumpInitializedReports, a_dumpInProgressReports, a_dumpFailedReports, a_dumpSuccessReports;
79 bool a_dumpHexMessages;
82 test_pool_t a_testPool;
83 test_pool_it a_currentTestIt;
84 int a_poolRepeats; // repeat pool N times
85 int a_poolCycle; // current cycle, from 1 to N
86 unsigned int a_inProgressLimit; // limit load to have this value
89 int a_synchronousAmount;
92 bool nextTestCase() throw();
95 timer_container a_timers;
97 // Test case identifiers:
99 std::map<std::string /* session id's */, TestCase*> a_sessionIdTestCaseMap; // stores used Session-Id values within a test case.
100 // No other can use them, but a test case could use more than one.
102 std::map<std::string /* subscriber id's */, TestCase*> a_subscriberIdTestCaseMap; // stores used Subscriber-Id values within a test case.
106 StatSummary a_statSummary; // general statistics
110 TestManager(const TestManager&);
111 virtual ~TestManager() {;}
113 TestTimer* createTimer(TestCaseStep*, const anna::Millisecond &, const TestTimer::Type::_v type) throw(anna::RuntimeException);
114 void cancelTimer(TestTimer*) throw();
115 void release(anna::timex::TimeEvent*) throw();
120 void registerSessionId(const std::string &sessionId, const TestCase *testCase) throw(anna::RuntimeException);
121 void registerSubscriberId(const std::string &subscriberId, const TestCase *testCase) throw(anna::RuntimeException);
123 int tests() const throw() { return a_testPool.size(); }
124 void setTimerController(anna::timex::Engine *engine) throw() { a_timeController = engine; }
126 void setReportsDirectory(const std::string &rd) throw() { a_reportsDirectory = rd; }
127 const std::string &getReportsDirectory() const throw() { return a_reportsDirectory; }
129 void setDumpHex(bool dh) throw() { a_dumpHexMessages = dh; }
130 bool getDumpHex() const throw() { return a_dumpHexMessages; }
133 void setDumpInitializedReports(bool enable) throw() { a_dumpInitializedReports = enable; }
134 void setDumpInProgressReports(bool enable) throw() { a_dumpInProgressReports = enable; }
135 void setDumpFailedReports(bool enable) throw() { a_dumpFailedReports = enable; }
136 void setDumpSuccessReports(bool enable) throw() { a_dumpSuccessReports = enable; }
137 void setDumpAllReports(bool enable) throw() {
138 setDumpInitializedReports(enable);
139 setDumpInProgressReports(enable);
140 setDumpFailedReports(enable);
141 setDumpSuccessReports(enable);
144 bool getDumpInitializedReports() const throw() { return a_dumpInitializedReports; }
145 bool getDumpInProgressReports() const throw() { return a_dumpInProgressReports; }
146 bool getDumpFailedReports() const throw() { return a_dumpFailedReports; }
147 bool getDumpSuccessReports() const throw() { return a_dumpSuccessReports; }
149 // Helper to calculate time interval and synchronous amount of execution tests to guarantee the input rate (tests per second)
150 // through the time manager. The first call to this method will start the time trigger system and check for new test cases to be launched.
151 bool configureTTPS(int testTicksPerSecond) throw();
153 bool clearPool() throw();
154 bool resetPool(bool hard /* hard reset includes in-progress test cases */) throw();
155 void setPoolRepeats(int repeats) throw() { a_poolRepeats = repeats; }
156 int getPoolRepeats() const throw() { return a_poolRepeats; }
157 int getPoolCycle() const throw() { return a_poolCycle; }
159 unsigned int getInProgressCount() const throw() { return a_statSummary.getInProgressCount(); }
160 unsigned int getInProgressLimit() const throw() { return a_inProgressLimit; }
161 void setInProgressLimit(unsigned int limit) throw() { a_inProgressLimit = limit; } // 0 = UINT_MAX (no limit)
163 bool gotoTestCase(unsigned int id) throw();
164 TestCase *findTestCase(unsigned int id) const throw(); // id = -1 provides current test case triggered
165 TestCase *getTestCase(unsigned int id) throw(); // creates/reuses a test case
168 TestCase *getTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw();
169 TestCase *getTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) throw();
170 void receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException);
171 void receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException);
173 bool execTestCases(int sync_amount) throw();
175 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
176 std::string asXMLString() const throw();
179 void tcsStateStats(const TestCase::State::_v beginState, const TestCase::State::_v endState) throw() {
180 a_statSummary.newTCState(beginState, endState);
184 friend class anna::Singleton <TestManager>;
185 friend class TestStepTimeout; // createTimer
186 friend class TestStepDelay; // createTimer
187 friend class TestClock; // tick