Command execution for system test cases
[anna.git] / example / diameter / launcher / Launcher.cpp
index 041e7a9..4452ee4 100644 (file)
@@ -1078,6 +1078,24 @@ std::string Launcher::help() const throw() {
   result += "\n                                                          buffer search. The main advantage is the great flexibility to identify";
   result += "\n                                                          any content with a regular expression.";
   result += "\n";
+  result += "\n                              sh-command|<script>[|parameters]";
+  result += "\n                                                          External execution for script/executable via shell through an";
+  result += "\n                                                          independent thread, providing the script name and the parameters.";
+  result += "\n                                                          You could use dynamic variables ##<tag> to have more flexibility:";
+  result += "\n                                                             Test pool cycle id: "; result += SH_COMMAND_TAG_FOR_REPLACE__CYCLE_ID;
+  result += "\n                                                             Test case id:       "; result += SH_COMMAND_TAG_FOR_REPLACE__TESTCASE_ID;
+  result += "\n                                                             Test step id:       "; result += SH_COMMAND_TAG_FOR_REPLACE__TESTSTEP_ID;
+  result += "\n";
+  result += "\n                                                          For example, your command could be something like this:";
+  result += "\n                                                             script:     insert_sql.sh";
+  result += "\n                                                             parameters: -db dbname --verbose > /tmp/cycle-"; result += SH_COMMAND_TAG_FOR_REPLACE__CYCLE_ID; result += ".";
+  result += "\n                                                                            testcase-"; result += SH_COMMAND_TAG_FOR_REPLACE__TESTCASE_ID; result += ".teststep-"; result += SH_COMMAND_TAG_FOR_REPLACE__TESTSTEP_ID; result += ".out";
+  result += "\n";
+  result += "\n                                                          You could also make substitutions on script name: insert_sql_"; result += SH_COMMAND_TAG_FOR_REPLACE__TESTCASE_ID; result += ".sh";
+  result += "\n";
+  result += "\n                                                          Don't try to redirect stdout and stderr to avoid ADML output contamination";
+  result += "\n                                                          with the possible outputs from the scripts.";
+  result += "\n";
   result += "\n                           <condition>: Optional parameters which must be fulfilled to continue through the next step.";
   result += "\n                                        Any received message over diameter interfaces will be evaluated against the";
   result += "\n                                         corresponding test case starting from the current step until the first one";
@@ -1215,17 +1233,18 @@ std::string Launcher::help() const throw() {
   result += "\n";
   result += "\n   test|goto|<id>                Updates current test pointer position.";
   result += "\n";
-  result += "\n   test|look[|id]                Show programmed test case for id provided, current when missing. Test cases programmed";
-  result += "\n                                 are not dumped on process context (too many information in general). When the test case";
-  result += "\n                                 has been completed or initiated, it will contain context information acting as a report.";
+  result += "\n   test|look[|id]                Show programmed test case for id provided, current 'in-process' test case when missing.";
+  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|report[|[yes]|no]        Every time a test case is finished, its xml representation will be dump on a file under";
   result += "\n                                 the execution directory (or the one configured in process command-line 'tmDir') with";
-  result += "\n                                 the name 'testcase.<id>.xml'. If repeat mode is active, new test case executions will";
-  result += "\n                                 append its reports into the same file. This option is disabled by default to improve";
-  result += "\n                                 performance (reducing IO). ADML process context will show test manager whole information";
-  result += "\n                                 and test case reports will be written depending on this report option. Anyway, you could";
-  result += "\n                                  use the 'look' operation to see the report.";
+  result += "\n                                 the name 'cycle-<cycle id>.testcase-<test case id>.xml'. This option is disabled by";
+  result += "\n                                 default reducing IO. ADML process context won't show test manager whole information";
+  result += "\n                                 because it could be a huge amount of data to write. Anyway, you could use the 'look'";
+  result += "\n                                 operation to see the desired report(s).";
+  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|report-hex[|[yes]|no]    Reports could include the diameter messages in hexadecimal format. Disabled by default.";
   result += "\n";
@@ -1235,12 +1254,11 @@ std::string Launcher::help() const throw() {
   result += "\n                                 - soft: only for finished cases (those with 'Success' or 'Failed' states). It does not";
   result += "\n                                         affect to test cases with 'InProgress' state.";
   result += "\n";
-  result += "\n   test|repeat[|[yes]|no]        Restarts the whole programmed test list when finished, disabled by default (testing";
-  result += "\n                                 time trigger system will enter suspended state until new ttps operation is received).";
-  result += "\n                                 Test cases state & data will be reset (when achieved again), but general statistics";
-  result += "\n                                 and counters will continue measuring until reset with 'collect' operation.";
-  result += "\n                                 When the test cases pool has been processed (and this repeat option is disabled), you";
-  result += "\n                                 could reactivate the testing by mean 'test|reset|soft' and then 'test|ttps|<value>'.";
+  result += "\n   test|repeats|<amount>         Restarts the whole programmed test list when finished the amount number of times (repeats";
+  result += "\n                                 forever if value -1 is provided). This is disabled by default (amount = 0): testing trigger";
+  result += "\n                                 system will enter suspended state until new ttps operation is received and a soft reset has";
+  result += "\n                                 been done before. Test cases state & data will be reset (when achieved again), but general";
+  result += "\n                                 statistics and counters will continue measuring until reset with 'collect' operation.";
   result += "\n";
   result += "\n   test|clear                    Clears all the programmed test cases and stop testing (if in progress).";
   result += "\n";
@@ -1610,7 +1628,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     // test|<id>|<command>[|parameters]   Add a new step to the test case ...
     // test|ttps|<amount>                 Starts/resume the provided number of time ticks per second (ttps). The ADML starts ...
     // test|ip-limit[|amount]             In-progress limit of test cases. No new test cases will be launched over this value ...
-    // test|repeat[|[yes]|no]             Restarts the programmed test cases when finished. Disabled by default: the testing ...
+    // test|repeats|<amount>              Restarts the whole programmed test list when finished the amount number of times ...
     // test|report[|[yes]|no]             Every time a test case is finished a report file in xml format will be created under ...
     // test|report-hex[|[yes]|no]         Reports could include the diameter messages in hexadecimal format. Disabled by default.
     // test|goto|<id>                     Updates current test pointer position.
@@ -1652,13 +1670,14 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
         opt_response_content += " test cases running";
       }
     }
-    else if(param1 == "repeat") {
-      if (numParams > 2)
+    else if(param1 == "repeats") {
+      if (numParams > 2 || 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.setPoolRepeat((param2 == "yes"));
-      opt_response_content += (testManager.getPoolRepeat() ? "repeat enabled" : "repeat disabled");
+      testManager.setPoolRepeats(atoi(param2.c_str()));
+      int repeats = testManager.getPoolRepeats();
+      std::string nolimit = (repeats != -1) ? "":" [no limit]";
+      opt_response_content += anna::functions::asString("Pool repeats: %d%s (current cycle: %d)", repeats, nolimit.c_str(), testManager.getPoolCycle());
     }
     else if(param1 == "report") {
       if (numParams > 2)
@@ -1830,6 +1849,12 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
           throw anna::RuntimeException(anna::functions::asString("Missing condition for '%s' command in test id operation", param2.c_str()), ANNA_FILE_LOCATION);
         }
       }
+      else if (param2 == "sh-command") {
+        if (numParams > 4)
+          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 script for 'sh-command' in test id operation", ANNA_FILE_LOCATION);
+        testManager.getTestCase(id)->addCmd(param3, param4); // creates / reuses
+      }
       else {
         throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION);
       }
@@ -1965,7 +1990,7 @@ throw() {
   anna::statistics::Engine::instantiate().asXML(result);
 
   // Testing: could be heavy if test case reports are enabled
-  TestManager::instantiate().asXML(result);
+  //TestManager::instantiate().asXML(result);
 
   return result;
 }