X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FEventOperation.cpp;h=2b4248615099becb70b7b1f9e735522a85d97f0c;hb=cef452116c2966d7eaa65ff31ee7613bf3ae1b93;hp=7709fb1864a2087f895531d4c90e1a6eb36f522b;hpb=e688b5354af3a5fe0add859710cae41ffe123f65;p=anna.git diff --git a/example/diameter/launcher/EventOperation.cpp b/example/diameter/launcher/EventOperation.cpp index 7709fb1..2b42486 100644 --- a/example/diameter/launcher/EventOperation.cpp +++ b/example/diameter/launcher/EventOperation.cpp @@ -12,47 +12,24 @@ // Process #include #include +#include +#include +#include +#include + +// Standard +#include +#include // chdir // Project #include - - -//// Standard -//#include // std::istringstream -//#include // std::cout -//#include // ceil -//#include -#include // chdir -//#include -// -//// Project #include #include -//#include -//#include -//#include -//#include -//#include -//#include -//#include #include #include #include -//#include -//#include #include -//#include -//#include #include -// -//// Process -//#include -//#include -//#include -#include -#include -#include -//#include ///////////////////// @@ -380,7 +357,7 @@ bool EventOperation::sendmsg_hex_2e(std::string &response, const std::string & d if(my_app.getOperatedHost()->logEnabled()) { anna::diameter::comm::Server *usedServer = my_app.getOperatedEntity()->getLastUsedResource(); anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL; - std::string detail = usedClientSession ? usedClientSession->asString() : ""; // shouldn't happen + std::string detail = usedClientSession ? usedClientSession->asString() : "[null client session]"; // shouldn't happen my_app.getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2e" : "send2eError"), detail); } @@ -445,7 +422,7 @@ bool EventOperation::sendmsg_hex_2c(std::string &response, const std::string & d // Detailed log: if(my_app.getOperatedHost()->logEnabled()) { anna::diameter::comm::ServerSession *usedServerSession = my_app.getOperatedServer()->getLastUsedResource(); - std::string detail = usedServerSession ? usedServerSession->asString() : ""; // shouldn't happen + std::string detail = usedServerSession ? usedServerSession->asString() : "[null server session]"; // shouldn't happen my_app.getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2c" : "send2cError"), detail); } @@ -581,8 +558,9 @@ bool EventOperation::test_id__description(std::string &response, unsigned int id anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); try { - testManager.getTestCase(id)->setDescription(description); // creates / reuses - response = "Done"; + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses + tc->setDescription(description); + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -599,8 +577,9 @@ bool EventOperation::test_id__ip_limit(std::string &response, unsigned int id, i anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); try { - testManager.getTestCase(id)->addIpLimit(amount); // creates / reuses - response = "Done"; + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses + tc->addIpLimit(amount); + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -618,8 +597,9 @@ bool EventOperation::test_id__timeout(std::string &response, unsigned int id, in try { anna::Millisecond timeout = my_app.checkTimeMeasure("Test case timeout", anna::functions::asString(msecs)); - testManager.getTestCase(id)->addTimeout(timeout); // creates / reuses - response = "Done"; + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses + tc->addTimeout(timeout); + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -650,13 +630,14 @@ bool EventOperation::test_id__sendmsg2e_2c(std::string &response, unsigned int i ); try { + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses my_app.updateOperatedOriginHostWithMessage(codecMsg); if (_2e_or_2c) - testManager.getTestCase(id)->addSendDiameterXml2e(codecMsg.code(), my_app.getOperatedHost(), stepNumber); // creates / reuses + tc->addSendDiameterXml2e(codecMsg.code(), my_app.getOperatedHost(), stepNumber); else - testManager.getTestCase(id)->addSendDiameterXml2c(codecMsg.code(), my_app.getOperatedHost(), stepNumber); // creates / reuses + tc->addSendDiameterXml2c(codecMsg.code(), my_app.getOperatedHost(), stepNumber); - response = "Done"; + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -673,9 +654,10 @@ bool EventOperation::test_id__delay(std::string &response, unsigned int id, int anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); try { + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses anna::Millisecond delay = ((msecs == 0 /* special case */) ? (anna::Millisecond)0 : my_app.checkTimeMeasure("Test case delay step", anna::functions::asString(msecs))); - testManager.getTestCase(id)->addDelay(delay); // creates / reuses - response = "Done"; + tc->addDelay(delay); // creates / reuses + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -692,8 +674,9 @@ bool EventOperation::test_id__sh_command(std::string &response, unsigned int id, anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); try { - testManager.getTestCase(id)->addCommand(script); // creates / reuses - response = "Done"; + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses + tc->addCommand(script); // creates / reuses + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -741,8 +724,9 @@ bool EventOperation::test_id__waitfefc_hex(std::string &response, unsigned int i } try { - testManager.getTestCase(id)->addWaitDiameterRegexpHex(fe_or_fc, regexp); - response = "Done"; + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses + tc->addWaitDiameterRegexpHex(fe_or_fc, regexp); + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -777,18 +761,22 @@ bool EventOperation::test_id__waitfefc_msg(std::string &response, unsigned int i std::string::size_type pos, pos_1, pos_2; pos = regexp.find("end-to-end-id=", 0u); - pos = regexp.find("\"", pos); - pos_1 = pos; - pos = regexp.find("\"", pos+1); - pos_2 = pos; - regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); + if (pos != std::string::npos) { + pos = regexp.find("\"", pos); + pos_1 = pos; + pos = regexp.find("\"", pos+1); + pos_2 = pos; + regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); + } pos = regexp.find("hop-by-hop-id=", 0u); - pos = regexp.find("\"", pos); - pos_1 = pos; - pos = regexp.find("\"", pos+1); - pos_2 = pos; - regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); + if (pos != std::string::npos) { + pos = regexp.find("\"", pos); + pos_1 = pos; + pos = regexp.find("\"", pos+1); + pos_2 = pos; + regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); + } // For this representation: //pos = regexp.find("Origin-State-Id", 0u); @@ -800,20 +788,23 @@ bool EventOperation::test_id__waitfefc_msg(std::string &response, unsigned int i //regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); // But we have this one: pos = regexp.find("Origin-State-Id", 0u); - pos = regexp.rfind("\"", pos); - pos = regexp.rfind("\"", pos-1); - pos = regexp.rfind("\"", pos-1); - pos_1 = pos; - pos = regexp.find("\"", pos+1); - pos_2 = pos; - regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); + if (pos != std::string::npos) { + pos = regexp.rfind("\"", pos); + pos = regexp.rfind("\"", pos-1); + pos = regexp.rfind("\"", pos-1); + pos_1 = pos; + pos = regexp.find("\"", pos+1); + pos_2 = pos; + regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); + } //regexp.insert(0, "^"); //regexp += "$"; } - testManager.getTestCase(id)->addWaitDiameterRegexpXml(fe_or_fc, regexp); - response = "Done"; + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses + tc->addWaitDiameterRegexpXml(fe_or_fc, regexp); + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -839,8 +830,9 @@ bool EventOperation::test_id__waitfefc(std::string &response, unsigned int id, b anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); try { // [code]|[bitR]|[hopByHop]|[applicationId]|[sessionId]|[resultCode]|[msisdn]|[imsi]|[serviceContextId] - testManager.getTestCase(id)->addWaitDiameter(fe_or_fc, code, bitR, hopByHop, applicationId, sessionId, resultCode, msisdn, imsi, serviceContextId); - response = "Done"; + anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses + tc->addWaitDiameter(fe_or_fc, code, bitR, hopByHop, applicationId, sessionId, resultCode, msisdn, imsi, serviceContextId); + response = std::to_string(tc->getId()); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -857,26 +849,59 @@ bool EventOperation::test_id__waitfefc(std::string &response, unsigned int id, b bool EventOperation::test__ttps(std::string &response, int amount) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + bool success = testManager.configureTTPS(amount); + if (success) { + response = "Assigned new test launch rate to "; + response += anna::functions::asString(amount); + response += " events per second"; + } + else { + response += "unable to configure the test rate provided"; + } - - return true; // OK + return success; // OK } bool EventOperation::test__next(std::string &response, int syncAmount) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + if (syncAmount < 1) { + response += "the parameter 'sync-amount' must be a positive integer value"; + return false; + } + bool success = testManager.execTestCases(syncAmount); - return true; // OK + response = (success ? "P" : "Not completely p" /* completed cycle and no repeats, rare case */); + response += "rocessed "; + response += anna::functions::asString(syncAmount); + response += ((syncAmount > 1) ? " test cases synchronously" : " test case"); + + return success; } bool EventOperation::test__ip_limit(std::string &response, int amount) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + if (amount > -2) { + testManager.setInProgressLimit(amount); + response = "New in-progress limit: "; + response += (amount != -1) ? anna::functions::asString(amount) : "[no limit]"; + } + else { + response = "In-progress limit amount: "; + int limit = testManager.getInProgressLimit(); + response += (limit != -1) ? anna::functions::asString(limit) : "[no limit]"; + response += "; currently there are "; + response += anna::functions::asString(testManager.getInProgressCount()); + response += " test cases running"; + } return true; // OK } @@ -884,26 +909,64 @@ bool EventOperation::test__ip_limit(std::string &response, int amount) { bool EventOperation::test__goto(std::string &response, int id) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + bool success = testManager.gotoTestCase(id); + if (success) { + response = "Position updated for id provided ("; + } + else { + response += "cannot found test id ("; + } + response += anna::functions::asString(id); + response += ")"; - return true; // OK + return success; } bool EventOperation::test__run(std::string &response, int id) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + bool success = testManager.runTestCase(id); + if (success) { + response = "Test executed for id provided ("; + } + else { + response += "cannot found test id ("; + } + response += anna::functions::asString(id); + response += ")"; - return true; // OK + return success; } bool EventOperation::test__look(std::string &response, int id) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + anna::testing::TestCase *testCase = testManager.findTestCase(id); + if (!testCase) { + if (id == -1) { + response += "no current test case detected (testing started ?)"; + } + else { + response += "cannot found test id ("; + response += anna::functions::asString(id); + response += ")"; + } + return false; + } + + if (a_http) + response = anna::functions::encodeBase64(testCase->asXMLString()); + else + response = testCase->asXMLString(); return true; // OK } @@ -911,26 +974,89 @@ bool EventOperation::test__look(std::string &response, int id) { bool EventOperation::test__state(std::string &response, int id) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + anna::testing::TestCase *testCase = testManager.findTestCase(id); + if (!testCase) { + if (id == -1) { + response += "no current test case detected (testing started ?)"; + } + else { + response += "cannot found test id ("; + response += anna::functions::asString(id); + response += ")"; + } + return false; + } - return true; // OK + response = anna::testing::TestCase::asText(testCase->getState()); + return testCase->isSuccess(); } bool EventOperation::test__interact(std::string &response, int amount, unsigned int id) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + if (amount < -1) { + response += "interactive amount must be -1 (to disable interactive mode) or a positive number."; + return false; + } + anna::testing::TestCase *testCase = testManager.findTestCase(id); + if (testCase) { + if (amount == -1) { + testCase->makeInteractive(false); + response = "Interactive mode disabled"; + } + else { + testCase->addInteractiveAmount(amount); + response = "Added interactive amount of "; + response += anna::functions::asString(amount); + response += " units"; + if (amount == 0) response += " (0: freezing a non-interactive testcase, no effect on already interactive)"; + } + response += " for test case id "; + response += anna::functions::asString(id); + } + else { + response += "cannot found test id ("; + response += anna::functions::asString(id); + response += ")"; + return false; + } return true; // OK } -bool EventOperation::test__reset(std::string &response, bool soft_hard, unsigned int id) { +bool EventOperation::test__reset(std::string &response, bool soft_hard, int id) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + anna::testing::TestCase *testCase = ((id != -1) ? testManager.findTestCase(id) : NULL); + if (testCase) { + bool done = testCase->reset(!soft_hard); + response = "Test "; + response += (soft_hard ? "soft":"hard"); + response += " reset for id "; + response += anna::functions::asString(id); + response += done ? ": done": ": not done"; + } + else { + if (id == -1) { + bool anyReset = testManager.resetPool(!soft_hard); + response = (soft_hard ? "Soft":"Hard"); + response += " reset have been sent to all programmed tests: "; response += anyReset ? "some/all have been reset" : "nothing was reset"; + } + else { + response += "cannot found test id ("; + response += anna::functions::asString(id); + response += ")"; + return false; + } + } return true; // OK } @@ -938,8 +1064,12 @@ bool EventOperation::test__reset(std::string &response, bool soft_hard, unsigned bool EventOperation::test__repeats(std::string &response, int amount) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + if (amount < 0) amount = -1; + testManager.setPoolRepeats(amount); + std::string nolimit = (amount != -1) ? "":" [no limit]"; + response = anna::functions::asString("Pool repeats: %d%s (current cycle: %d)", amount, nolimit.c_str(), testManager.getPoolCycle()); return true; // OK } @@ -947,8 +1077,10 @@ bool EventOperation::test__repeats(std::string &response, int amount) { bool EventOperation::test__auto_reset(std::string &response, bool soft_hard) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + testManager.setAutoResetHard(!soft_hard); + response = anna::functions::asString("Auto-reset configured to '%s'", (soft_hard ? "soft":"hard")); return true; // OK } @@ -956,8 +1088,9 @@ bool EventOperation::test__auto_reset(std::string &response, bool soft_hard) { bool EventOperation::test__initialized(std::string &response) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + response = anna::functions::asString("%lu", testManager.getInitializedCount()); return true; // OK } @@ -965,8 +1098,9 @@ bool EventOperation::test__initialized(std::string &response) { bool EventOperation::test__finished(std::string &response) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + response = anna::functions::asString("%lu", testManager.getFinishedCount()); return true; // OK } @@ -976,28 +1110,30 @@ bool EventOperation::test__clear(std::string &response) { Launcher& my_app = static_cast (anna::app::functions::getApp()); anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - try { - if (testManager.clearPool()) { - response = "All the programmed test cases have been dropped"; - } - else { - response = "There are not programmed test cases to be removed"; - } - } - catch(anna::RuntimeException &ex) { - ex.trace(); - response += "failed"; - return false; - } - - return true; // OK + return testManager.clearPool(response); } bool EventOperation::test__junit(std::string &response, const std::string & targetFile) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + + std::ofstream out; + out.open(targetFile.c_str()); + + if(out.is_open() == false) { + response += "error opening '"; + response += targetFile; + response += "'"; + return false; + } + out << testManager.junitAsXMLString() << std::endl; + out.close(); + response = "Junit report written on '"; + response += targetFile; + response += "'"; return true; // OK } @@ -1005,8 +1141,9 @@ bool EventOperation::test__junit(std::string &response, const std::string & targ bool EventOperation::test__summary_counts(std::string &response) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + response = anna::functions::encodeBase64(testManager.summaryCounts()); return true; // OK } @@ -1014,8 +1151,9 @@ bool EventOperation::test__summary_counts(std::string &response) { bool EventOperation::test__summary_states(std::string &response) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + response = anna::functions::encodeBase64(testManager.summaryStates()); return true; // OK } @@ -1023,8 +1161,9 @@ bool EventOperation::test__summary_states(std::string &response) { bool EventOperation::test__summary(std::string &response) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + response = anna::functions::encodeBase64(testManager.asXMLString()); return true; // OK } @@ -1032,8 +1171,36 @@ bool EventOperation::test__summary(std::string &response) { bool EventOperation::test__report(std::string &response, const std::string & state, bool enable) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + std::string _state = state; + + if(_state == "initialized") + testManager.setDumpInitializedReports(enable); + else if(_state == "in-progress") + testManager.setDumpInProgressReports(enable); + else if(_state == "failed") + testManager.setDumpFailedReports(enable); + else if(_state == "success") + testManager.setDumpSuccessReports(enable); + else if(_state == "all") { + _state = "any"; + testManager.setDumpAllReports(enable); + } + else if(_state == "none") { + enable = !enable; + _state = "any"; + testManager.setDumpAllReports(enable); + } + else { + response += "invalid state (allowed: initialized|in-progress|failed|success|[all]|none)"; + return false; + } + response = (enable ? "Report enabled " : "Report disabled "); + response += "for tests in '"; + response += _state; + response += "' state"; return true; // OK } @@ -1041,8 +1208,10 @@ bool EventOperation::test__report(std::string &response, const std::string & sta bool EventOperation::test__report_hex(std::string &response, bool enable) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); - + testManager.setDumpHex(enable); + response = (testManager.getDumpHex() ? "Report includes hexadecimal messages" : "Report excludes hexadecimal messages"); return true; // OK } @@ -1050,8 +1219,27 @@ bool EventOperation::test__report_hex(std::string &response, bool enable) { bool EventOperation::test__dump_stdout(std::string &response, bool enable) { Launcher& my_app = static_cast (anna::app::functions::getApp()); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); + + testManager.setDumpStdout(enable); + response = (testManager.getDumpStdout() ? "Test manager dumps progress into stdout" : "Test manager does not dump progress into stdout"); + + return true; // OK +} +bool EventOperation::test__dynamic(std::string &response, const nlohmann::json &arguments) { + Launcher& my_app = static_cast (anna::app::functions::getApp()); + + Procedure p(&my_app); + try { + p.execute(arguments, response); + } + catch(anna::RuntimeException &ex) { + ex.trace(); + response += ex.asString(); + return false; + } return true; // OK }