X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FLauncher.cpp;h=420a498c0250175ec8e515c3114a7abc0d2af6ee;hb=0e992a5c0f14d91268d00304d90c7073499ff54e;hp=94d8f66f52e5c12e52c4c4f9d0694b0f3e8102ee;hpb=5406b19bdbfe101b264f8c4d878392e2916b8f9d;p=anna.git diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 94d8f66..420a498 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -330,7 +330,7 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp // Checking command line parameters std::string sessionBasedModelsType; - anna::diameter::comm::Entity::SessionBasedModelsType::_v sessionBasedModelsTypeEnum; + anna::diameter::comm::Entity::SessionBasedModelsType::_v sessionBasedModelsTypeEnum = anna::diameter::comm::Entity::SessionBasedModelsType::SessionIdLowPart; if(sessionBasedModelsClientSocketSelection) { sessionBasedModelsType = sessionBasedModelsClientSocketSelection->getValue(); if (sessionBasedModelsType == "RoundRobin") { @@ -867,6 +867,15 @@ void Launcher::resetCounters() throw() { anna::diameter::codec::OamModule::instantiate().resetCounters(); } +void Launcher::signalTerminate() throw(anna::RuntimeException) { + LOGMETHOD(anna::TraceMethod tm("Launcher", "signalTerminate", ANNA_FILE_LOCATION)); + + forceCountersRecord(); + + a_communicator->terminate (); + comm::Application::signalTerminate (); +} + void Launcher::signalUSR2() throw(anna::RuntimeException) { std::string inputFile = getSignalUSR2InputFile(); @@ -1220,7 +1229,17 @@ std::string Launcher::help() const throw() { result += "\n values (Session-Id, Subscriber-Id, etc.)."; result += "\n"; result += "\n : commands to be executed for the test id provided. Each command programmed"; - result += "\n constitutes a test case 'step', numbered from 1 to N."; + result += "\n constitutes a test case 'step', numbered from 1 to N, with an exception for"; + result += "\n 'description' which is used to describe the test case:"; + result += "\n"; + result += "\n description| Sets a test case description. Test cases by default are"; + result += "\n constructed with description 'Testcase_'."; + result += "\n"; + result += "\n ip-limit[|amount] In-progress limit of test cases controlled from this test."; + result += "\n No new test cases will be launched over this value (test"; + result += "\n manager tick work will be ignored). Zero-value is equivalent"; + result += "\n to stop the clock tick, -1 is used to specify 'no limit' which"; + result += "\n is the default. For missing amount, value of 1 is applied."; result += "\n"; result += "\n timeout| Sets an asynchronous timer to restrict the maximum timeout"; result += "\n until last test step. Normally, this command is invoked"; @@ -1433,10 +1452,10 @@ std::string Launcher::help() const throw() { result += "\n next programmed test cases (1 by default). This event works regardless the timer tick"; result += "\n function, but it is normally used with the test manager tick stopped."; result += "\n"; - result += "\n test|ip-limit[|amount] In-progress limit of test cases. No new test cases will be launched over this value"; - result += "\n (test Manager tick work will be ignored). Zero-value is equivalent to stop the clock."; - result += "\n tick, -1 is used to specify 'no limit' which is the default. If missing amount, the"; - result += "\n limit and current amount of in-progress test cases will be shown."; + result += "\n test|ip-limit[|amount] In-progress limit of test cases established from global context. This value will be"; + result += "\n overwritten if used at test case level when the corresponding test step is executed."; + result += "\n Anyway, the meaning is the same in both contexts. But now, when the amount is missing,"; + result += "\n the limit and current amount of in-progress test cases will be shown."; result += "\n"; result += "\n test|goto| Updates current test pointer position."; result += "\n"; @@ -1444,13 +1463,16 @@ std::string Launcher::help() const throw() { result += "\n Test cases reports are not dumped on process context (too many information in general)."; result += "\n The report contains context information in every moment: this operation acts as a snapshot."; result += "\n"; - result += "\n test|interact|amount|id Makes interactive a specific test case id. The amount is the margin of execution steps"; - result += "\n to be done. Normally, we will execute 'test|interact|0|', which means that"; + result += "\n test|state[|id] Get test case state for id provided, current 'in-process' test case when missing."; + result += "\n"; + result += "\n test|interact|amount[|id] Makes interactive a specific test case id. The amount is the margin of execution steps"; + result += "\n to be done. Normally, we will execute 'test|interact|0[|]', which means that"; result += "\n the test case is selected to be interactive, but no step is executed. Then you have to"; result += "\n interact with positive amounts (usually 1), executing the provided number of steps if"; result += "\n they are ready and fulfill the needed conditions. The value of 0, implies no execution"; result += "\n steps margin, which could be useful to 'freeze' a test in the middle of its execution."; result += "\n You could also provide -1 to make it non-interactive resuming it from the current step."; + result += "\n By default, current test case id is selected for interaction."; result += "\n"; result += "\n test|reset|<[soft]/hard>[|id] Reset the test case for id provided, all the tests when missing. It could be hard/soft:"; result += "\n - hard: you probably may need to stop the load rate before. This operation initializes"; @@ -1468,8 +1490,19 @@ std::string Launcher::help() const throw() { result += "\n been configured for the test case, hard reset could prevent stuck on the next cycle for"; result += "\n those test cases still in progress."; result += "\n"; + result += "\n test|initialized Shows the number of initialized test cases. Zero-value means that everything was processed"; + result += " or not initiated yet.\n"; + result += "\n"; + result += "\n test|finished Shows the number of finished (successful or failed) test cases."; + result += "\n"; result += "\n test|clear Clears all the programmed test cases and stop testing (if in progress)."; result += "\n"; + result += "\n test|junit Shows the junit report in the moment of execution."; + result += "\n"; + result += "\n test|summary-counts Test manager counts report. Counts by state and prints total verdict."; + result += "\n"; + result += "\n test|summary-states Test manager states report."; + result += "\n"; result += "\n test|summary Test manager general report (number of test cases, counts by state, global configuration,"; result += "\n forced in-progress limitation, reports visibility, etc.). Be careful when you have reports"; result += "\n enabled because the programmed test cases dumps could be heavy (anyway you could enable the"; @@ -1492,6 +1525,8 @@ std::string Launcher::help() const throw() { result += "\n"; result += "\n test|report-hex[|[yes]|no] Reports could include the diameter messages in hexadecimal format. Disabled by default."; result += "\n"; + result += "\n test|dump-stdout[|[yes]|no] Test manager information is dumped into stdout."; + result += "\n"; result += "\n"; result += "\n------------------------------------------------------------------------------------- Dynamic procedure"; result += "\n"; @@ -1534,7 +1569,7 @@ std::string Launcher::help() const throw() { result += "\n"; result += "\nThe alternative using SIGUSR2 signal requires the creation of the task(s) file which will be read at"; result += "\n signal event:"; - result += "\n echo \"<\" > "; result += getSignalUSR2InputFile(); + result += "\n echo \"\" > "; result += getSignalUSR2InputFile(); result += "\n then"; result += "\n kill -12 "; result += "\n or"; @@ -1586,9 +1621,12 @@ void Launcher::logStatisticsSamples(const std::string &conceptsList) throw() { } -void Launcher::eventOperation(const std::string &operation, std::string &response_content) throw(anna::RuntimeException) { +bool Launcher::eventOperation(const std::string &operation, std::string &response_content) throw(anna::RuntimeException) { + + bool result = true; + LOGMETHOD(anna::TraceMethod tm("Launcher", "eventOperation", ANNA_FILE_LOCATION)); - if (operation == "") return; // ignore + if (operation == "") return result; // ignore LOGDEBUG(anna::Logger::debug(anna::functions::asString("Operation: %s", operation.c_str()), ANNA_FILE_LOCATION)); // Default response: @@ -1618,15 +1656,15 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons catch(anna::RuntimeException &ex) { ex.trace(); response_content = ex.asString(); - return; + return false; } - return; + return true; // OK } // Help: if(operation == "help") { response_content = help(); - return; + return true; // OK } // Reset performance data: @@ -1634,26 +1672,26 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons resetCounters(); resetStatistics(); response_content = "All process counters & statistic information have been reset"; - return; + return true; // OK } // Counters dump on demand: if(operation == "forceCountersRecord") { forceCountersRecord(); response_content = "Current counters have been dump to disk"; - return; + return true; // OK } // OAM & statistics: if(operation == "show-oam") { anna::xml::Node root("root"); response_content = anna::xml::Compiler().apply(oamAsXML(&root)); - return; + return true; // OK } if(operation == "show-stats") { anna::xml::Node root("root"); response_content = anna::xml::Compiler().apply(statsAsXML(&root)); - return; + return true; // OK } /////////////////////////////////////////////////////////////////// @@ -1728,25 +1766,27 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons std::string contextFile = ((numParams == 1) ? param1 : anna::functions::asString("/var/tmp/anna.context.%05d", getPid())); writeContext(contextFile); response_content = anna::functions::asString("Context dumped on file '%s'", contextFile.c_str()); - return; + return true; // OK } if(opType == "log-statistics-samples") { logStatisticsSamples(param1); response_content = anna::functions::asString("Log statistics samples for '%s' concepts", param1.c_str()); - return; + return true; // OK } // Change execution directory: if(opType == "change-dir") { if (param1 == "") param1 = a_initialWorkingDirectory; - if (chdir(param1.c_str()) == 0) + result = (chdir(param1.c_str()) == 0); + + if (result) response_content = "New execution directory configured: "; else response_content = "Cannot assign provided execution directory: "; response_content += param1; - return; + return result; } if(opType == "services") { @@ -1757,10 +1797,10 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons catch(anna::RuntimeException &ex) { ex.trace(); response_content = anna::functions::asString("Loaded services from file '%s' with errors", servicesFile.c_str()); - return; + return false; } response_content = anna::functions::asString("Loaded services from file '%s'", servicesFile.c_str()); - return; + return true; // OK } // Host switch: @@ -1777,12 +1817,12 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons response_content = "Working node is automatic"; } } - return; + return true; // OK } if(opType == "node_auto") { a_workingNode = NULL; response_content = "Working node has been set to automatic"; - return; + return true; // OK } // Operated host from possible forced-working node: @@ -2094,6 +2134,14 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons testManager.setDumpHex((param2 == "yes")); opt_response_content += (testManager.getDumpHex() ? "report includes hexadecimal messages" : "report excludes hexadecimal messages"); } + else if(param1 == "dump-stdout") { + if (numParams > 2) + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + + if(param2 == "") param2 = "yes"; + testManager.setDumpStdout((param2 == "yes")); + opt_response_content += (testManager.getDumpHex() ? "test manager dumps progress into stdout" : "test manager does not dump progress into stdout"); + } else if(param1 == "goto") { if (numParams > 2) throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); @@ -2118,9 +2166,33 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if (testCase) { response_content = testCase->asXMLString(); - return; + return true; // OK + } + else { + result = false; + if (id == -1) { + opt_response_content = "no current test case detected (testing started ?)"; + } + else { + opt_response_content = "cannot found test id ("; + opt_response_content += anna::functions::asString(id); + opt_response_content += ")"; + } + } + } + else if(param1 == "state") { + if (numParams > 2) + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + + int id = ((param2 != "") ? atoi(param2.c_str()) : -1); + anna::testing::TestCase *testCase = testManager.findTestCase(id); + + if (testCase) { + response_content = anna::testing::TestCase::asText(testCase->getState()); + return testCase->isSuccess(); } else { + result = false; if (id == -1) { opt_response_content = "no current test case detected (testing started ?)"; } @@ -2132,14 +2204,14 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } } else if (param1 == "interact") { - if (numParams != 3) + if (numParams != 2) throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); int amount = atoi(param2.c_str()); if (amount < -1) throw anna::RuntimeException("Interactive amount must be -1 (to disable interactive mode) or a positive number.", ANNA_FILE_LOCATION); - int id = atoi(param3.c_str()); + int id = ((param3 != "") ? atoi(param3.c_str()) : -1); anna::testing::TestCase *testCase = testManager.findTestCase(id); if (testCase) { if (amount == -1) { @@ -2157,6 +2229,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons opt_response_content += anna::functions::asString(id); } else { + result = false; opt_response_content = "cannot found test id ("; opt_response_content += anna::functions::asString(id); opt_response_content += ")"; @@ -2187,6 +2260,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons opt_response_content = param2; opt_response_content += " reset have been sent to all programmed tests: "; opt_response_content += anyReset ? "some/all have been reset" : "nothing was reset"; } else { + result = false; opt_response_content = "cannot found test id ("; opt_response_content += anna::functions::asString(id); opt_response_content += ")"; @@ -2203,6 +2277,18 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons testManager.setAutoResetHard(param2 == "hard"); opt_response_content += anna::functions::asString("Auto-reset configured to '%s'", param2.c_str()); } + else if(param1 == "initialized") { + if (numParams > 1) + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + + opt_response_content = anna::functions::asString("%lu", testManager.getInitializedCount()); + } + else if(param1 == "finished") { + if (numParams > 1) + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + + opt_response_content = anna::functions::asString("%lu", testManager.getFinishedCount()); + } else if(param1 == "clear") { if (numParams > 1) throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); @@ -2214,9 +2300,21 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons opt_response_content = "there are not programmed test cases to be removed"; } } + else if(param1 == "junit") { + response_content = testManager.junitAsXMLString(); + return true; // OK + } + else if(param1 == "summary-counts") { + response_content = testManager.summaryCounts(); + return true; // OK + } + else if(param1 == "summary-states") { + response_content = testManager.summaryStates(); + return true; // OK + } else if(param1 == "summary") { response_content = testManager.asXMLString(); - return; + return true; // OK } else { int id = atoi(param1.c_str()); @@ -2225,6 +2323,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons // PARAM: 1 2 3 4 5 6 7 8 9 10 11 // test|| + // description| + // ip-limit[|] // timeout| // sendxml2e| [|] // sendxml2c| [|] @@ -2236,7 +2336,19 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(param2 == "") throw anna::RuntimeException("Missing command for test id operation", ANNA_FILE_LOCATION); // Commands: - if (param2 == "timeout") { + if (param2 == "description") { + if (numParams > 3) + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + if(param3 == "") throw anna::RuntimeException("Missing description for test case", ANNA_FILE_LOCATION); + testManager.getTestCase(id)->setDescription(param3); // creates / reuses + } + else if (param2 == "ip-limit") { + if (numParams > 3) + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + unsigned int limit = (param3 == "") ? 1 : atoi(param3.c_str()); + testManager.getTestCase(id)->addIpLimit(limit); // creates / reuses + } + else if (param2 == "timeout") { if (numParams > 3) throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); if(param3 == "") throw anna::RuntimeException("Missing milliseconds for 'timeout' command in test id operation", ANNA_FILE_LOCATION); @@ -2257,9 +2369,9 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons int stepNumber = ((param4 != "") ? atoi(param4.c_str()):-1); if (param2 == "sendxml2e") - testManager.getTestCase(id)->addSendxml2e(codecMsg.code(), getOperatedHost(), stepNumber); // creates / reuses + testManager.getTestCase(id)->addSendDiameterXml2e(codecMsg.code(), getOperatedHost(), stepNumber); // creates / reuses else - testManager.getTestCase(id)->addSendxml2c(codecMsg.code(), getOperatedHost(), stepNumber); // creates / reuses + testManager.getTestCase(id)->addSendDiameterXml2c(codecMsg.code(), getOperatedHost(), stepNumber); // creates / reuses } else if (param2 == "delay") { if (numParams > 3) @@ -2273,7 +2385,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); if (param3 != "" || param4 != "" || param5 != "" || param6 != "" || param7 != "" || param8 != "" || param9 != "" || param10 != "" || param11 != "") { bool fromEntity = (param2.substr(4,2) == "fe"); - testManager.getTestCase(id)->addWait(fromEntity, param3, param4, param5, param6, param7, param8, param9, param10, param11); + testManager.getTestCase(id)->addWaitDiameter(fromEntity, param3, param4, param5, param6, param7, param8, param9, param10, param11); } else { throw anna::RuntimeException(anna::functions::asString("Missing condition for '%s' command in test id operation", param2.c_str()), ANNA_FILE_LOCATION); @@ -2302,7 +2414,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } bool fromEntity = (param2.substr(4,2) == "fe"); - testManager.getTestCase(id)->addWaitRegexpHex(fromEntity, regexp); + testManager.getTestCase(id)->addWaitDiameterRegexpHex(fromEntity, regexp); } else if ((param2 == "waitfe-xml")||(param2 == "waitfc-xml")) { if (numParams > 4) @@ -2362,7 +2474,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } bool fromEntity = (param2.substr(4,2) == "fe"); - testManager.getTestCase(id)->addWaitRegexpXml(fromEntity, regexp); + testManager.getTestCase(id)->addWaitDiameterRegexpXml(fromEntity, regexp); } else if (param2 == "sh-command") { // Allow pipes in command: @@ -2409,7 +2521,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if(opType == "loadxml") { codecMsg.loadXML(param1); response_content = codecMsg.asXMLString(); - return; + return true; // OK } else if(opType == "diameterServerSessions") { int diameterServerSessions = atoi(param1.c_str()); getOperatedServer()->setMaxConnections(diameterServerSessions); @@ -2417,7 +2529,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if(opType == "answerxml2c") { if(param1 == "") { // programmed answers FIFO's to stdout response_content = getOperatedServer()->getReactingAnswers()->asString("ANSWERS TO CLIENT"); - return; + return true; // OK } else if (param1 == "rotate") { getOperatedServer()->getReactingAnswers()->rotate(true); } else if (param1 == "exhaust") { @@ -2443,7 +2555,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(param1 == "") { // programmed answers FIFO's to stdout response_content = getOperatedEntity()->getReactingAnswers()->asString("ANSWERS TO ENTITY"); - return; + return true; // OK } else if (param1 == "rotate") { getOperatedEntity()->getReactingAnswers()->rotate(true); } else if (param1 == "exhaust") { @@ -2475,6 +2587,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons response_content += " => "; response_content += opt_response_content; } + + return result; } anna::xml::Node* Launcher::asXML(anna::xml::Node* parent) const