ANNA Suite  2020b
Multipurpose development suite for Telco applications
TestManager.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
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 //
7 
8 
9 #ifndef anna_testing_TestManager_hpp
10 #define anna_testing_TestManager_hpp
11 
12 // Project
13 #include <anna/config/defines.hpp>
15 #include <anna/core/Singleton.hpp>
18 #include <anna/core/DataBlock.hpp>
21 
22 
23 namespace anna {
24  class Millisecond;
25 
26  namespace timex {
27  class Engine;
28  }
29  namespace diameter {
30  namespace comm {
31  class ClientSession;
32  class ServerSession;
33  }
34  }
35 
36 namespace testing {
37 
38 
39 class TestClock;
40 class TestCase;
41 class TestCaseStep;
42 
43 
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;
47 
48 
52 class TestManager : public anna::timex::TimeEventObserver, public anna::Singleton <TestManager> {
53 
54  // Statistics summary:
55  class StatSummary {
56 
57  unsigned int a_initializedTcs;
58  unsigned int a_inprogressTcs;
59  unsigned int a_failedTcs;
60  unsigned int a_sucessTcs;
61 
62  public:
63  StatSummary() { clear(); }
64  void newTCState(const TestCase::State::_v beginState, const TestCase::State::_v endState) ;
65  void clear() ;
66  unsigned int getInitializedCount() const { return a_initializedTcs; }
67  unsigned int getInProgressCount() const { return a_inprogressTcs; }
68  unsigned int getFailedCount() const { return a_failedTcs; }
69  unsigned int getSuccessCount() const { return a_sucessTcs; }
70  unsigned int getFinishedCount() const { return a_sucessTcs + a_failedTcs; }
71  unsigned int getTotal() const { return (a_initializedTcs + a_inprogressTcs + a_failedTcs + a_sucessTcs); }
72 
73  anna::xml::Node* asXML(anna::xml::Node* parent) const ;
74  };
75 
76 
77 
79 
80  anna::timex::Engine* a_timeController;
81 
82  // reports
83  std::string a_reportsDirectory;
84  bool a_dumpInitializedReports, a_dumpInProgressReports, a_dumpFailedReports, a_dumpSuccessReports;
85  bool a_dumpHexMessages;
86  bool a_dumpStdout;
87 
88  // Pool of test cases
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)
95 
96  // Test clock
97  int a_synchronousAmount;
98  TestClock *a_clock;
99  bool tick() ;
100  bool nextTestCase() ;
101 
102  // Test timers
103  timer_container a_timers;
104 
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;
108 
109  // Diameter shall use: key1 -> sessionId, key2 -> subscriberId
110  //
111 
112  StatSummary a_statSummary; // general statistics
113 
114 
115  TestManager();
116  TestManager(const TestManager&);
117  virtual ~TestManager() {;}
118 
119  TestTimer* createTimer(TestCaseStep*, const anna::Millisecond &, const TestTimer::Type::_v type) noexcept(false);
120  void cancelTimer(TestTimer*) ;
121  void release(anna::timex::TimeEvent*) ;
122 
123 
124  public:
125 
126  void registerKey1(const std::string &key, const TestCase *testCase) noexcept(false);
127  void registerKey2(const std::string &key, const TestCase *testCase) noexcept(false);
128 
129  int tests() const { return a_testPool.size(); }
130  void setTimerController(anna::timex::Engine *engine) { a_timeController = engine; }
131 
132  void setReportsDirectory(const std::string &rd) { a_reportsDirectory = rd; }
133  const std::string &getReportsDirectory() const { return a_reportsDirectory; }
134 
135  void setDumpHex(bool dh) { a_dumpHexMessages = dh; }
136  bool getDumpHex() const { return a_dumpHexMessages; }
137 
138  void setDumpStdout(bool ds) { a_dumpStdout = ds; }
139  bool getDumpStdout() const { return a_dumpStdout; }
140 
141  void setDumpInitializedReports(bool enable) { a_dumpInitializedReports = enable; }
142  void setDumpInProgressReports(bool enable) { a_dumpInProgressReports = enable; }
143  void setDumpFailedReports(bool enable) { a_dumpFailedReports = enable; }
144  void setDumpSuccessReports(bool enable) { a_dumpSuccessReports = enable; }
145  void setDumpAllReports(bool enable) {
146  setDumpInitializedReports(enable);
147  setDumpInProgressReports(enable);
148  setDumpFailedReports(enable);
149  setDumpSuccessReports(enable);
150  }
151 
152  bool getDumpInitializedReports() const { return a_dumpInitializedReports; }
153  bool getDumpInProgressReports() const { return a_dumpInProgressReports; }
154  bool getDumpFailedReports() const { return a_dumpFailedReports; }
155  bool getDumpSuccessReports() const { return a_dumpSuccessReports; }
156 
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) ;
160 
161  bool clearTestCase(std::string &result, unsigned int id) ;
162  bool clearPool(std::string &result) ;
163  bool resetPool(bool hard /* hard reset includes in-progress test cases */) ;
164  void setPoolRepeats(int repeats) { a_poolRepeats = repeats; }
165  int getPoolRepeats() const { return a_poolRepeats; }
166  int getPoolCycle() const { return a_poolCycle; }
167 
168  bool getAutoResetHard() const { return a_autoResetHard; }
169  void setAutoResetHard(bool hard = true) { a_autoResetHard = hard; }
170 
171 
172  unsigned int getInProgressCount() const { return a_statSummary.getInProgressCount(); }
173  unsigned int getInitializedCount() const { return a_statSummary.getInitializedCount(); }
174  unsigned int getFinishedCount() const { return a_statSummary.getFinishedCount(); }
175  unsigned int getInProgressLimit() const { return a_inProgressLimit; }
176  void setInProgressLimit(unsigned int limit) { a_inProgressLimit = limit; } // -1 = UINT_MAX (no limit)
177 
178  bool gotoTestCase(unsigned int id) ;
179  bool runTestCase(unsigned int id) ;
180  TestCase *findTestCase(unsigned int id) const ; // id = -1 provides current test case triggered
181  TestCase *getTestCase(unsigned int id, const std::string &description = "") ; // creates/reuses a test case
182  // provide 0 to reserve the id = tests() + 1
183  // Diameter-specific
184  TestCase *getDiameterTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) ;
185  TestCase *getDiameterTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) ;
186  void receiveDiameterMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) noexcept(false);
187  void receiveDiameterMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) noexcept(false);
188 
189  // Non-trasactional (kafka)
190  //
191  //
192 
193  bool execTestCases(int sync_amount) ;
194 
195  anna::xml::Node* asXML(anna::xml::Node* parent) const ;
196  anna::xml::Node* junitAsXML(anna::xml::Node* parent) const ;
197  std::string asXMLString() const ;
198  std::string junitAsXMLString() const ;
199  std::string summaryCounts() const ;
200  std::string summaryStates() const ;
201 
202  // stats
203  void tcsStateStats(const TestCase::State::_v beginState, const TestCase::State::_v endState) {
204  a_statSummary.newTCState(beginState, endState);
205  }
206 
207 
208  friend class anna::Singleton <TestManager>;
209  friend class TestStepTimeout; // createTimer
210  friend class TestStepDelay; // createTimer
211  friend class TestClock; // tick
212 };
213 
214 }
215 }
216 
217 #endif
218 
Definition: Millisecond.hpp:24
void setReportsDirectory(const std::string &rd)
Definition: TestManager.hpp:132
std::map< unsigned int, TestCase * >::iterator test_pool_nc_it
Definition: TestManager.hpp:46
Definition: TestTimer.hpp:25
bool getDumpHex() const
Definition: TestManager.hpp:136
Definition: Node.hpp:56
Definition: Singleton.hpp:76
void setDumpSuccessReports(bool enable)
Definition: TestManager.hpp:144
int getPoolRepeats() const
Definition: TestManager.hpp:165
void setInProgressLimit(unsigned int limit)
Definition: TestManager.hpp:176
Definition: TestManager.hpp:52
Definition: TestStep.hpp:166
Definition: TestClock.hpp:22
unsigned int getInProgressCount() const
Definition: TestManager.hpp:172
bool getDumpInitializedReports() const
Definition: TestManager.hpp:152
int getPoolCycle() const
Definition: TestManager.hpp:166
void setDumpInProgressReports(bool enable)
Definition: TestManager.hpp:142
std::map< unsigned int, TestCase * >::const_iterator test_pool_it
Definition: TestManager.hpp:45
bool getDumpStdout() const
Definition: TestManager.hpp:139
void setDumpHex(bool dh)
Definition: TestManager.hpp:135
Definition: TimeEvent.hpp:26
Definition: ServerSession.hpp:53
Definition: ClientSession.hpp:51
bool getDumpInProgressReports() const
Definition: TestManager.hpp:153
unsigned int getInitializedCount() const
Definition: TestManager.hpp:173
void setPoolRepeats(int repeats)
Definition: TestManager.hpp:164
void setAutoResetHard(bool hard=true)
Definition: TestManager.hpp:169
Definition: TimeEventObserver.hpp:33
bool getDumpSuccessReports() const
Definition: TestManager.hpp:155
const std::string & getReportsDirectory() const
Definition: TestManager.hpp:133
Definition: TestStep.hpp:99
Definition: TestCase.hpp:42
void tcsStateStats(const TestCase::State::_v beginState, const TestCase::State::_v endState)
Definition: TestManager.hpp:203
Definition: app.hpp:12
unsigned int getInProgressLimit() const
Definition: TestManager.hpp:175
unsigned int getFinishedCount() const
Definition: TestManager.hpp:174
bool getAutoResetHard() const
Definition: TestManager.hpp:168
Definition: Engine.hpp:62
void setDumpAllReports(bool enable)
Definition: TestManager.hpp:145
_v
Definition: TestTimer.hpp:29
int tests() const
Definition: TestManager.hpp:129
void setDumpInitializedReports(bool enable)
Definition: TestManager.hpp:141
void setTimerController(anna::timex::Engine *engine)
Definition: TestManager.hpp:130
Definition: DataBlock.hpp:24
std::map< unsigned int, TestCase * > test_pool_t
Definition: TestManager.hpp:41
void setDumpFailedReports(bool enable)
Definition: TestManager.hpp:143
void setDumpStdout(bool ds)
Definition: TestManager.hpp:138
_v
Definition: TestCase.hpp:69
bool getDumpFailedReports() const
Definition: TestManager.hpp:154