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 getInitializedCount() const throw() { return a_initializedTcs; }
67 unsigned int getInProgressCount() const throw() { return a_inprogressTcs; }
68 unsigned int getFailedCount() const throw() { return a_failedTcs; }
69 unsigned int getSuccessCount() const throw() { return a_sucessTcs; }
70 unsigned int getFinishedCount() const throw() { return a_sucessTcs + a_failedTcs; }
71 unsigned int getTotal() const throw() { return (a_initializedTcs + a_inprogressTcs + a_failedTcs + a_sucessTcs); }
73 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
78 typedef anna::Recycler <TestTimer> timer_container;
80 anna::timex::Engine* a_timeController;
83 std::string a_reportsDirectory;
84 bool a_dumpInitializedReports, a_dumpInProgressReports, a_dumpFailedReports, a_dumpSuccessReports;
85 bool a_dumpHexMessages;
89 test_pool_t a_testPool;
90 test_pool_it a_currentTestIt;
91 int a_poolRepeats; // repeat pool N times
92 int a_poolCycle; // current cycle, from 1 to N
93 unsigned int a_inProgressLimit; // limit load to have this value
94 bool a_autoResetHard; // automatic reset on next cycle (soft by default, false)
97 int a_synchronousAmount;
100 bool nextTestCase() throw();
103 timer_container a_timers;
105 // Test case identifiers: key1 (strong); key2 (alternative)
106 std::map<std::string /* key */, TestCase*> a_key1TestCaseMap;
107 std::map<std::string /* key */, TestCase*> a_key2TestCaseMap;
109 // Diameter shall use: key1 -> sessionId, key2 -> subscriberId
112 StatSummary a_statSummary; // general statistics
116 TestManager(const TestManager&);
117 virtual ~TestManager() {;}
119 TestTimer* createTimer(TestCaseStep*, const anna::Millisecond &, const TestTimer::Type::_v type) throw(anna::RuntimeException);
120 void cancelTimer(TestTimer*) throw();
121 void release(anna::timex::TimeEvent*) throw();
126 void registerKey1(const std::string &key, const TestCase *testCase) throw(anna::RuntimeException);
127 void registerKey2(const std::string &key, const TestCase *testCase) throw(anna::RuntimeException);
129 int tests() const throw() { return a_testPool.size(); }
130 void setTimerController(anna::timex::Engine *engine) throw() { a_timeController = engine; }
132 void setReportsDirectory(const std::string &rd) throw() { a_reportsDirectory = rd; }
133 const std::string &getReportsDirectory() const throw() { return a_reportsDirectory; }
135 void setDumpHex(bool dh) throw() { a_dumpHexMessages = dh; }
136 bool getDumpHex() const throw() { return a_dumpHexMessages; }
138 void setDumpStdout(bool ds) throw() { a_dumpStdout = ds; }
139 bool getDumpStdout() const throw() { return a_dumpStdout; }
141 void setDumpInitializedReports(bool enable) throw() { a_dumpInitializedReports = enable; }
142 void setDumpInProgressReports(bool enable) throw() { a_dumpInProgressReports = enable; }
143 void setDumpFailedReports(bool enable) throw() { a_dumpFailedReports = enable; }
144 void setDumpSuccessReports(bool enable) throw() { a_dumpSuccessReports = enable; }
145 void setDumpAllReports(bool enable) throw() {
146 setDumpInitializedReports(enable);
147 setDumpInProgressReports(enable);
148 setDumpFailedReports(enable);
149 setDumpSuccessReports(enable);
152 bool getDumpInitializedReports() const throw() { return a_dumpInitializedReports; }
153 bool getDumpInProgressReports() const throw() { return a_dumpInProgressReports; }
154 bool getDumpFailedReports() const throw() { return a_dumpFailedReports; }
155 bool getDumpSuccessReports() const throw() { return a_dumpSuccessReports; }
157 // Helper to calculate time interval and synchronous amount of execution tests to guarantee the input rate (tests per second)
158 // 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.
159 bool configureTTPS(int testTicksPerSecond) throw();
161 bool clearPool() throw();
162 bool resetPool(bool hard /* hard reset includes in-progress test cases */) throw();
163 void setPoolRepeats(int repeats) throw() { a_poolRepeats = repeats; }
164 int getPoolRepeats() const throw() { return a_poolRepeats; }
165 int getPoolCycle() const throw() { return a_poolCycle; }
167 bool getAutoResetHard() const throw() { return a_autoResetHard; }
168 void setAutoResetHard(bool hard = true) throw() { a_autoResetHard = hard; }
171 unsigned int getInProgressCount() const throw() { return a_statSummary.getInProgressCount(); }
172 unsigned int getInitializedCount() const throw() { return a_statSummary.getInitializedCount(); }
173 unsigned int getFinishedCount() const throw() { return a_statSummary.getFinishedCount(); }
174 unsigned int getInProgressLimit() const throw() { return a_inProgressLimit; }
175 void setInProgressLimit(unsigned int limit) throw() { a_inProgressLimit = limit; } // -1 = UINT_MAX (no limit)
177 bool gotoTestCase(unsigned int id) throw();
178 bool runTestCase(unsigned int id) throw();
179 TestCase *findTestCase(unsigned int id) const throw(); // id = -1 provides current test case triggered
180 TestCase *getTestCase(unsigned int id, const std::string &description = "") throw(); // creates/reuses a test case
183 TestCase *getDiameterTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw();
184 TestCase *getDiameterTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) throw();
185 void receiveDiameterMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException);
186 void receiveDiameterMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException);
188 // Non-trasactional (kafka)
192 bool execTestCases(int sync_amount) throw();
194 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
195 anna::xml::Node* junitAsXML(anna::xml::Node* parent) const throw();
196 std::string asXMLString() const throw();
197 std::string junitAsXMLString() const throw();
198 std::string summaryCounts() const throw();
199 std::string summaryStates() const throw();
202 void tcsStateStats(const TestCase::State::_v beginState, const TestCase::State::_v endState) throw() {
203 a_statSummary.newTCState(beginState, endState);
207 friend class anna::Singleton <TestManager>;
208 friend class TestStepTimeout; // createTimer
209 friend class TestStepDelay; // createTimer
210 friend class TestClock; // tick