X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Ftesting%2FTestManager.cpp;h=2c03b4dad4bcf3b0f58e1c9506bcc26a1d93cb23;hb=daeeaacceeccefcac46838f460b19409cc5c4cb4;hp=ca45e9c3199969a6dd48103bea28aab5272208a4;hpb=4552131b751399a8b4fd323f5547f91c7cb0f978;p=anna.git diff --git a/example/diameter/launcher/testing/TestManager.cpp b/example/diameter/launcher/testing/TestManager.cpp index ca45e9c..2c03b4d 100644 --- a/example/diameter/launcher/testing/TestManager.cpp +++ b/example/diameter/launcher/testing/TestManager.cpp @@ -21,22 +21,72 @@ // Process #include -#include #include #include +#include class TestTimer; + + +/////////////////////////////////////////////////////////////////////////////////////////////////// +void TestManager::StatSummary::newTCState(const TestCase::State::_v beginState, const TestCase::State::_v endState) throw() { + + if ((beginState == TestCase::State::Initialized)&&(endState == TestCase::State::Initialized)) { // special case (new test case provisioning) + a_initializedTcs++; + return; + } + + switch (beginState) { + case TestCase::State::Initialized: a_initializedTcs--; break; + case TestCase::State::InProgress: a_inprogressTcs--; break; + case TestCase::State::Failed: a_failedTcs--; break; + case TestCase::State::Success: a_sucessTcs--; break; + default: break; + } + switch (endState) { + case TestCase::State::Initialized: a_initializedTcs++; break; + case TestCase::State::InProgress: a_inprogressTcs++; break; + case TestCase::State::Failed: a_failedTcs++; break; + case TestCase::State::Success: a_sucessTcs++; break; + default: break; + } +} + +void TestManager::StatSummary::clear() throw() { + a_initializedTcs = 0; + a_inprogressTcs = 0; + a_failedTcs = 0; + a_sucessTcs = 0; +} + +anna::xml::Node *TestManager::StatSummary::asXML(anna::xml::Node* parent) const throw() { + anna::xml::Node* result = parent->createChild("StatSummary"); + + anna::xml::Node* tcs = result->createChild("TestCasesCounts"); + tcs->createAttribute("Total", a_initializedTcs + a_inprogressTcs + a_failedTcs + a_sucessTcs); + tcs->createAttribute("Initialized", a_initializedTcs); + tcs->createAttribute("InProgress", a_inprogressTcs); + tcs->createAttribute("Failed", a_failedTcs); + tcs->createAttribute("Success", a_sucessTcs); + + return result; +} +/////////////////////////////////////////////////////////////////////////////////////////////////// + + + TestManager::TestManager() : - anna::timex::TimeEventObserver("TestManager") { + anna::timex::TimeEventObserver("TestManager") { a_timeController = NULL; a_reportsDirectory = "./"; a_dumpReports = false; + a_dumpHexMessages = false; a_synchronousAmount = 1; - a_poolRepeat = false; - a_inProgressCount = 0; + a_poolRepeats = 0; // repeat disabled by default + a_poolCycle = 1; a_inProgressLimit = UINT_MAX; // no limit a_clock = NULL; //a_testPool.clear(); @@ -73,9 +123,9 @@ throw(anna::RuntimeException) { result->setTimeout(timeout); LOGDEBUG( - std::string msg("TestManager::createTimer | "); - msg += result->asString(); - anna::Logger::debug(msg, ANNA_FILE_LOCATION); + std::string msg("TestManager::createTimer | "); + msg += result->asString(); + anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); a_timeController->activate(result); @@ -88,9 +138,9 @@ throw() { return; LOGDEBUG( - std::string msg("TestManager::cancel | "); - msg += timer->asString(); - anna::Logger::debug(msg, ANNA_FILE_LOCATION); + std::string msg("TestManager::cancel | "); + msg += timer->asString(); + anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); try { @@ -134,7 +184,7 @@ bool TestManager::configureTTPS(int testTicksPerSecond) throw() { a_synchronousAmount = 1; if (admlTimeInterval < anna::Millisecond(1)) { - LOGWARNING(anna::Logger::warning("Not allowed to configure more than 1000 events per second for the time trigger testing system", ANNA_FILE_LOCATION)); + LOGWARNING(anna::Logger::warning("Not allowed to configure more than 1000 events per second for for triggering testing system", ANNA_FILE_LOCATION)); return false; } @@ -150,15 +200,15 @@ bool TestManager::configureTTPS(int testTicksPerSecond) throw() { if (a_synchronousAmount > 1) { LOGWARNING( - std::string msg = anna::functions::asString("Desired testing time trigger rate (%d events per second) requires more than one sending per event (%d every %lld milliseconds). Consider launch more instances with lower rate (for example %d ADML processes with %d ttps), or configure %d or more sockets to the remote endpoints to avoid burst sendings", - testTicksPerSecond, - a_synchronousAmount, - admlTimeInterval.getValue(), - a_synchronousAmount, - 1000/admlTimeInterval, - a_synchronousAmount); - - anna::Logger::warning(msg, ANNA_FILE_LOCATION); + std::string msg = anna::functions::asString("Desired testing time trigger rate (%d events per second) requires more than one sending per event (%d every %lld milliseconds). Consider launch more instances with lower rate (for example %d ADML processes with %d ttps), or configure %d or more sockets to the remote endpoints to avoid burst sendings", + testTicksPerSecond, + a_synchronousAmount, + admlTimeInterval.getValue(), + a_synchronousAmount, + 1000/admlTimeInterval, + a_synchronousAmount); + + anna::Logger::warning(msg, ANNA_FILE_LOCATION); ); } @@ -205,9 +255,12 @@ TestCase *TestManager::getTestCase(unsigned int id) throw() { bool TestManager::clearPool() throw() { if (!tests()) return false; for (test_pool_it it = a_testPool.begin(); it != a_testPool.end(); it++) delete it->second; + // TODO: stop the possible command threads or there will be a core dump + a_testPool.clear(); a_sessionIdTestCaseMap.clear(); a_currentTestIt = a_testPool.end(); + a_poolCycle = 1; configureTTPS(0); // stop return true; } @@ -217,8 +270,8 @@ bool TestManager::resetPool(bool hard) throw() { if (!tests()) return result; for (test_pool_nc_it it = a_testPool.begin(); it != a_testPool.end(); it++) { - it->second->reset(hard); - result = true; + if (it->second->reset(hard)) + result = true; } //a_sessionIdTestCaseMap.clear(); return result; @@ -226,13 +279,18 @@ bool TestManager::resetPool(bool hard) throw() { bool TestManager::tick() throw() { LOGDEBUG(anna::Logger::debug("New test clock tick !", ANNA_FILE_LOCATION)); + return execTestCases(a_synchronousAmount); +} + +bool TestManager::execTestCases(int sync_amount) throw() { if (!tests()) { - LOGWARNING(anna::Logger::warning("Testing pool is empty. You need programming. Stopping test clock", ANNA_FILE_LOCATION)); + LOGWARNING(anna::Logger::warning("Testing pool is empty. You need programming", ANNA_FILE_LOCATION)); return false; } - int count = a_synchronousAmount; + // Synchronous sendings per tick: + int count = sync_amount; while (count > 0) { if (!nextTestCase()) return false; // stop the clock count--; @@ -246,7 +304,7 @@ bool TestManager::nextTestCase() throw() { while (true) { // Limit for in-progress test cases: - if (a_inProgressCount >= a_inProgressLimit) { + if (getInProgressCount() >= a_inProgressLimit) { LOGDEBUG(anna::Logger::debug(anna::functions::asString("TestManager next case ignored (over in-progress count limit: %llu)", a_inProgressLimit), ANNA_FILE_LOCATION)); return true; // wait next tick to release OTA test cases } @@ -259,33 +317,46 @@ bool TestManager::nextTestCase() throw() { // Completed: if (a_currentTestIt == a_testPool.end()) { - if (a_poolRepeat) { - LOGWARNING(anna::Logger::warning("Testing pool cycle completed. Repeat mode on. Restarting", ANNA_FILE_LOCATION)); - //a_currentTestIt = a_testPool.begin(); - return true; // avoids infinite loop: if the cycle takes less time than test cases completion, below reset never will turns state - // into Initialized and this while will be infinite. It is preferable to wait one tick when the cycle is completed. + if ((a_poolCycle > a_poolRepeats) && (a_poolRepeats != -1)) { + LOGWARNING(anna::Logger::warning("Testing pool cycle completed. No remaining repeat cycles left. Suspending", ANNA_FILE_LOCATION)); + a_poolCycle = 1; + return false; } else { - LOGWARNING(anna::Logger::warning("Testing pool cycle completed. Repeat mode off. Suspending", ANNA_FILE_LOCATION)); - return false; + LOGWARNING( + std::string nolimit = (a_poolRepeats != -1) ? "":" [no limit]"; + anna::Logger::warning(anna::functions::asString("Testing pool cycle %d completed (repeats configured: %d%s). Restarting for the %s cycle", a_poolCycle, a_poolRepeats, nolimit.c_str(), (a_poolRepeats == a_poolCycle) ? "last":"next"), ANNA_FILE_LOCATION); + ); + a_poolCycle++; + //a_currentTestIt = a_testPool.begin(); + return true; // avoids infinite loop: if the cycle takes less time than test cases completion, below reset never will turns state + // into Initialized and this while will be infinite. It is preferable to wait one tick when the cycle is completed. } } - // Hard reset, because normally a cycle takes more time that a single test case lifetime. We can consider that never - // going to break a in-progress test case due to cycle repeat + // Soft reset to initialize already finished (in previous cycle) test cases: a_currentTestIt->second->reset(false); // Process test case: LOGDEBUG(anna::Logger::debug(anna::functions::asString("Processing test case id = %llu, currently '%s' state", a_currentTestIt->first, TestCase::asText(a_currentTestIt->second->getState())), ANNA_FILE_LOCATION)); if (a_currentTestIt->second->getState() != TestCase::State::InProgress) { a_currentTestIt->second->process(); - return true; + return true; // is not probably to reach still In-Progress test cases from previous cycles due to the whole + // time for complete the test cases pool regarding the single test case lifetime. You shouldn't + // forget to programm a test case timeout with a reasonable value } } } -TestCase *TestManager::getTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw(anna::RuntimeException) { - sessionId = anna::diameter::helpers::base::functions::getSessionId(message); +TestCase *TestManager::getTestCaseFromSessionId(const anna::DataBlock &message, std::string &sessionId) throw() { + try { + sessionId = anna::diameter::helpers::base::functions::getSessionId(message); + } + catch (anna::RuntimeException &ex) { + //ex.trace(); + LOGWARNING(anna::Logger::warning("Cannot get the Session-Id from received DataBlock in order to identify the Test Case", ANNA_FILE_LOCATION)); + return NULL; + } std::map::const_iterator sessionIdIt = a_sessionIdTestCaseMap.find(sessionId); if (sessionIdIt != a_sessionIdTestCaseMap.end()) return sessionIdIt->second; @@ -294,7 +365,7 @@ TestCase *TestManager::getTestCaseFromSessionId(const anna::DataBlock &message, return NULL; } -void TestManager::receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException) { +void TestManager::receiveMessage(const anna::DataBlock &message, RealmNode *realm, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException) { // Testing disabled: if (!tests()) return; @@ -310,10 +381,15 @@ void TestManager::receiveMessage(const anna::DataBlock &message, const anna::dia std::string hint = "Uncovered condition for received message from entity over Session-Id '"; hint += sessionId; hint += "':"; try { - Launcher& my_app = static_cast (anna::app::functions::getApp()); - static anna::diameter::codec::Message codecMsg(my_app.getCodecEngine()); + static anna::diameter::codec::Message codecMsg; codecMsg.decode(message); hint += "\n"; hint += codecMsg.asXMLString(); + + // // Realm checking: + // std::string messageOR = message.getAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->getValue(); + // if (messageOR != realm->getName()) { + // LOGWARNING(anna::Logger::warning(anna::functions::asString("Received message from realm '%s', with different Origin-Realm: %s", realm->getName().c_str(), messageOR.c_str()), ANNA_FILE_LOCATION)); + // } } catch (anna::RuntimeException &ex) { ex.trace(); @@ -325,10 +401,11 @@ void TestManager::receiveMessage(const anna::DataBlock &message, const anna::dia } else { tsw->setClientSession(const_cast(clientSession)); + tc->process(); } } -void TestManager::receiveMessage(const anna::DataBlock &message, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException) { +void TestManager::receiveMessage(const anna::DataBlock &message, RealmNode *realm, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException) { // Testing disabled: if (!tests()) return; @@ -344,10 +421,15 @@ void TestManager::receiveMessage(const anna::DataBlock &message, const anna::dia std::string hint = "Uncovered condition for received message from client over Session-Id '"; hint += sessionId; hint += "':"; try { - Launcher& my_app = static_cast (anna::app::functions::getApp()); - static anna::diameter::codec::Message codecMsg(my_app.getCodecEngine()); + static anna::diameter::codec::Message codecMsg; codecMsg.decode(message); hint += "\n"; hint += codecMsg.asXMLString(); + + // // Realm checking: + // std::string messageOR = message.getAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->getValue(); + // if (messageOR != realm->getName()) { + // LOGWARNING(anna::Logger::warning(anna::functions::asString("Received message from realm '%s', with different Origin-Realm: %s", realm->getName().c_str(), messageOR.c_str()), ANNA_FILE_LOCATION)); + // } } catch (anna::RuntimeException &ex) { ex.trace(); @@ -359,6 +441,7 @@ void TestManager::receiveMessage(const anna::DataBlock &message, const anna::dia } else { tsw->setServerSession(const_cast(serverSession)); + tc->process(); } } @@ -368,13 +451,16 @@ throw() { int poolSize = a_testPool.size(); result->createAttribute("NumberOfTestCases", poolSize); - result->createAttribute("PoolRepeat", (a_poolRepeat ? "yes":"no")); - result->createAttribute("InProgressCount", a_inProgressCount); + if (a_poolRepeats) result->createAttribute("PoolRepeats", a_poolRepeats); + else result->createAttribute("PoolRepeats", "disabled"); + result->createAttribute("PoolCycle", a_poolCycle); + a_statSummary.asXML(result); if (a_inProgressLimit == UINT_MAX) result->createAttribute("InProgressLimit", ""); else result->createAttribute("InProgressLimit", a_inProgressLimit); result->createAttribute("DumpReports", (a_dumpReports ? "yes":"no")); + result->createAttribute("DumpHexMessages", (a_dumpHexMessages ? "yes":"no")); result->createAttribute("ReportsDirectory", a_reportsDirectory); if (a_clock) { result->createAttribute("AsynchronousSendings", a_synchronousAmount);