+////////////////////////////////////////////////////////////////////////////////////////////////////////
+// TestStepCmd
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+anna::xml::Node* TestStepCmd::asXML(anna::xml::Node* parent) const
+throw() {
+ anna::xml::Node* result = TestStep::asXML(parent);
+ //parent->createChild("TestStepCmd");
+
+ result->createAttribute("Script", (a_script != "") ? a_script:"<no script>");
+ result->createAttribute("Parameters", (a_parameters != "") ? a_parameters:"<no parameters>");
+ result->createAttribute("CommandInProgress", a_threadRunning ? "yes":"no");
+ if (!a_threadRunning && a_resultCode != -2) {
+ result->createAttribute("ResultCode", a_resultCode);
+ //if (a_output != "") result->createAttribute("Output", a_output);
+ }
+
+ return result;
+}
+
+bool TestStepCmd::do_execute() throw() {
+ if (!a_threadRunning) {
+ // Special tags to replace:
+ std::string cmd = getScript();
+ cmd += " ";
+ cmd += getParameters();
+ size_t index;
+ while ((index = cmd.find(SH_COMMAND_TAG_FOR_REPLACE__CYCLE_ID)) != std::string::npos)
+ cmd.replace(index, strlen(SH_COMMAND_TAG_FOR_REPLACE__CYCLE_ID), anna::functions::asString(TestManager::instantiate().getPoolCycle()));
+ while ((index = cmd.find(SH_COMMAND_TAG_FOR_REPLACE__TESTCASE_ID)) != std::string::npos)
+ cmd.replace(index, strlen(SH_COMMAND_TAG_FOR_REPLACE__TESTCASE_ID), anna::functions::asString(a_testCase->getId()));
+ while ((index = cmd.find(SH_COMMAND_TAG_FOR_REPLACE__TESTSTEP_ID)) != std::string::npos)
+ cmd.replace(index, strlen(SH_COMMAND_TAG_FOR_REPLACE__TESTSTEP_ID), anna::functions::asString(getNumber()));
+
+ a_thread = std::thread(cmdRunOnThread, this, cmd);
+ a_thread.detach();
+ }
+
+ return false; // don't go next (wait complete)
+}
+
+void TestStepCmd::do_complete() throw() {
+
+ a_threadRunning = false;
+ if (a_threadDeprecated) {
+ a_threadDeprecated = false;
+ return; // ignore TODO: interrupt the thread to avoid execution of the script
+ }
+
+ if (getResultCode() != 0)
+ a_testCase->setState(TestCase::State::Failed);
+ else
+ next(); // next() invoked here because execute() is always false for delay and never advance the iterator
+}
+
+void TestStepCmd::do_reset() throw() {
+
+ if (a_threadRunning) {
+ std::string s_warn = anna::functions::asString("Thread still in progress: deprecating step %d for Test Case %llu", getNumber(), a_testCase->getId());
+ LOGWARNING(anna::Logger::warning(s_warn, ANNA_FILE_LOCATION));
+ a_threadDeprecated = true;
+ }
+
+ a_resultCode = -2;
+ //a_output = "";
+}
+