Improved STC to show commands being executed.

Enhanced the net-smoke test scenario.

Change-Id: Idc828a6a4f18a02db1723a58a6020c4f07b8f3f1
diff --git a/tools/test/scenarios/net-setup.xml b/tools/test/scenarios/net-setup.xml
index 6fef8b1..6df7aa3 100644
--- a/tools/test/scenarios/net-setup.xml
+++ b/tools/test/scenarios/net-setup.xml
@@ -17,6 +17,7 @@
     <!-- TODO: parametrize this via recipes -->
     <group name="Net-Setup">
         <step name="Push-Topos" exec="onos-push-topos ${OCN}"/>
+        <step name="Stop-Mininet-If-Needed" env="~" exec="onos-mininet stop"/>
 
         <step name="Install-Apps"
               exec="onos ${OC1} app activate org.onosproject.openflow org.onosproject.proxyarp org.onosproject.fwd"/>
@@ -30,11 +31,11 @@
               exec="onos-check-summary ${OC1} [0-9]* 0 0 0"/>
 
         <step name="Start-Mininet"
-              requires="Install-Apps,Initial-Summary-Check,Push-Topos"
+              requires="Install-Apps,Initial-Summary-Check,Push-Topos,Stop-Mininet-If-Needed"
               exec="onos-mininet start topos/topo att-onos.py ${ONOS_INSTANCES}"/>
 
         <step name="Wait-For-Mininet" requires="Start-Mininet"
-              exec="onos-mininet wait 15"/>
+              exec="onos-mininet wait 20"/>
 
         <step name="Check-Summary" requires="Wait-For-Mininet"
               exec="onos-check-summary ${OC1} [0-9]* 25 140 0"/>
diff --git a/tools/test/scenarios/net-smoke.xml b/tools/test/scenarios/net-smoke.xml
index 87bd38c..aa47aef 100644
--- a/tools/test/scenarios/net-smoke.xml
+++ b/tools/test/scenarios/net-smoke.xml
@@ -21,10 +21,10 @@
         <dependency name="Reactive-Forwarding.Net-Pingall" requires="Net-Setup"/>
 
         <import file="${ONOS_SCENARIOS}/net-link-down-up.xml" namespace="Reactive-Forwarding"/>
-        <dependency name="Reactive-Forwarding.Net-Link-Down-Up" requires="~Reactive-Forwarding.Net-Pingall"/>
+        <dependency name="Reactive-Forwarding.Net-Link-Down-Up" requires="Net-Setup,~Reactive-Forwarding.Net-Pingall"/>
 
         <import file="${ONOS_SCENARIOS}/net-host-intent.xml"/>
-        <dependency name="Host-Intent-Connectivity" requires="~Reactive-Forwarding.Net-Link-Down-Up"/>
+        <dependency name="Host-Intent-Connectivity" requires="Net-Setup,~Reactive-Forwarding.Net-Link-Down-Up"/>
 
         <import file="${ONOS_SCENARIOS}/net-teardown.xml"/>
         <dependency name="Net-Teardown" requires="~Host-Intent-Connectivity"/>
diff --git a/utils/stc/src/main/java/org/onlab/stc/Compiler.java b/utils/stc/src/main/java/org/onlab/stc/Compiler.java
index 6464909..2d6fafa 100644
--- a/utils/stc/src/main/java/org/onlab/stc/Compiler.java
+++ b/utils/stc/src/main/java/org/onlab/stc/Compiler.java
@@ -425,7 +425,7 @@
             last = end + 1;
         }
         sb.append(pString.substring(last));
-        return sb.toString();
+        return sb.toString().replace('\n', ' ').replace('\r', ' ');
     }
 
     /**
diff --git a/utils/stc/src/main/java/org/onlab/stc/Main.java b/utils/stc/src/main/java/org/onlab/stc/Main.java
index 5708446..01ebe36 100644
--- a/utils/stc/src/main/java/org/onlab/stc/Main.java
+++ b/utils/stc/src/main/java/org/onlab/stc/Main.java
@@ -166,7 +166,7 @@
     // Processes the scenario 'list' command.
     private void processList() {
         coordinator.getRecords()
-                .forEach(event -> logStatus(event.time(), event.name(), event.status()));
+                .forEach(event -> logStatus(event.time(), event.name(), event.status(), event.command()));
     }
 
     // Processes the scenario 'run' command for range of steps.
@@ -188,12 +188,12 @@
     private static class Listener implements StepProcessListener {
         @Override
         public void onStart(Step step) {
-            logStatus(currentTimeMillis(), step.name(), IN_PROGRESS);
+            logStatus(currentTimeMillis(), step.name(), IN_PROGRESS, step.command());
         }
 
         @Override
         public void onCompletion(Step step, Status status) {
-            logStatus(currentTimeMillis(), step.name(), status);
+            logStatus(currentTimeMillis(), step.name(), status, null);
         }
 
         @Override
@@ -202,8 +202,12 @@
     }
 
     // Logs the step status.
-    private static void logStatus(long time, String name, Status status) {
-        print("%s  %s%s %s%s", time(time), color(status), name, action(status), color(null));
+    private static void logStatus(long time, String name, Status status, String cmd) {
+        if (cmd != null) {
+            print("%s  %s%s %s%s -- %s", time(time), color(status), name, action(status), color(null), cmd);
+        } else {
+            print("%s  %s%s %s%s", time(time), color(status), name, action(status), color(null));
+        }
     }
 
     // Produces a description of event using the specified step status.
diff --git a/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java b/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
index 70b5cb0..d7b8e18 100644
--- a/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
+++ b/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
@@ -109,7 +109,7 @@
      * @param step test step or group
      */
     synchronized void markStarted(Step step) {
-        add(new StepEvent(step.name(), IN_PROGRESS));
+        add(new StepEvent(step.name(), IN_PROGRESS, step.command()));
         save();
     }
 
@@ -120,7 +120,7 @@
      * @param status new step status
      */
     synchronized void markComplete(Step step, Status status) {
-        add(new StepEvent(step.name(), status));
+        add(new StepEvent(step.name(), status, null));
         save();
     }
 
diff --git a/utils/stc/src/main/java/org/onlab/stc/StepEvent.java b/utils/stc/src/main/java/org/onlab/stc/StepEvent.java
index 4c10f23..93120fe 100644
--- a/utils/stc/src/main/java/org/onlab/stc/StepEvent.java
+++ b/utils/stc/src/main/java/org/onlab/stc/StepEvent.java
@@ -18,27 +18,33 @@
 import org.onlab.stc.Coordinator.Status;
 
 import static java.lang.Long.parseLong;
+import static org.onlab.stc.Coordinator.Status.valueOf;
 
 /**
  * Represents an event of execution of a scenario step or group.
  */
 public class StepEvent {
 
+    private static final String SEP = "~";
+
     private final String name;
     private final long time;
     private final Status status;
+    private final String command;
 
     /**
      * Creates a new step record.
      *
-     * @param name   test step or group name
-     * @param time   time in millis since start of epoch
-     * @param status step completion status
+     * @param name    test step or group name
+     * @param time    time in millis since start of epoch
+     * @param status  step completion status
+     * @param command step command
      */
-    public StepEvent(String name, long time, Status status) {
+    public StepEvent(String name, long time, Status status, String command) {
         this.name = name;
         this.time = time;
         this.status = status;
+        this.command = command;
     }
 
     /**
@@ -46,9 +52,10 @@
      *
      * @param name   test step or group name
      * @param status status
+     * @param command step command
      */
-    public StepEvent(String name, Status status) {
-        this(name, System.currentTimeMillis(), status);
+    public StepEvent(String name, Status status, String command) {
+        this(name, System.currentTimeMillis(), status, command);
     }
 
     /**
@@ -78,10 +85,19 @@
         return status;
     }
 
+    /**
+     * Returns the step command.
+     *
+     * @return step command
+     */
+    public String command() {
+        return command;
+    }
+
 
     @Override
     public String toString() {
-        return name + ":" + time + ":" + status;
+        return name + SEP + time + SEP + status + SEP + command;
     }
 
     /**
@@ -91,7 +107,8 @@
      * @return step record
      */
     public static StepEvent fromString(String string) {
-        String[] fields = string.split(":");
-        return new StepEvent(fields[0], parseLong(fields[1]), Status.valueOf(fields[2]));
+        String[] fields = string.split("~");
+        return new StepEvent(fields[0], parseLong(fields[1]), valueOf(fields[2]),
+                             fields[3].equals("null") ? null : fields[3]);
     }
 }
diff --git a/utils/stc/src/test/java/org/onlab/stc/CoordinatorTest.java b/utils/stc/src/test/java/org/onlab/stc/CoordinatorTest.java
index 5174598..c6566ca 100644
--- a/utils/stc/src/test/java/org/onlab/stc/CoordinatorTest.java
+++ b/utils/stc/src/test/java/org/onlab/stc/CoordinatorTest.java
@@ -17,8 +17,8 @@
 
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.onlab.util.Tools;
 
-import java.io.FileNotFoundException;
 import java.io.IOException;
 
 import static org.onlab.stc.CompilerTest.getStream;
@@ -36,23 +36,26 @@
     @BeforeClass
     public static void setUpClass() throws IOException {
         CompilerTest.setUpClass();
+        Tools.removeDirectory(StepProcessorTest.DIR);
+
         StepProcessor.launcher = "true ";
     }
 
     @Test
-    public void simple() throws FileNotFoundException, InterruptedException {
+    public void simple() throws IOException, InterruptedException {
         executeTest("simple-scenario.xml");
     }
 
     @Test
-    public void complex() throws FileNotFoundException, InterruptedException {
+    public void complex() throws IOException, InterruptedException {
         executeTest("scenario.xml");
     }
 
-    private void executeTest(String name) throws FileNotFoundException, InterruptedException {
+    private void executeTest(String name) throws IOException, InterruptedException {
         Scenario scenario = loadScenario(getStream(name));
         Compiler compiler = new Compiler(scenario);
         compiler.compile();
+        Tools.removeDirectory(compiler.logDir());
         coordinator = new Coordinator(scenario, compiler.processFlow(), compiler.logDir());
         coordinator.addListener(listener);
         coordinator.reset();
diff --git a/utils/stc/src/test/java/org/onlab/stc/StepProcessorTest.java b/utils/stc/src/test/java/org/onlab/stc/StepProcessorTest.java
index d074a62..35a5ab0 100644
--- a/utils/stc/src/test/java/org/onlab/stc/StepProcessorTest.java
+++ b/utils/stc/src/test/java/org/onlab/stc/StepProcessorTest.java
@@ -32,7 +32,7 @@
  */
 public class StepProcessorTest {
 
-    private static final File DIR = new File("/tmp/stc/foo");
+    static final File DIR = new File("/tmp/stc/foo");
 
     private final Listener delegate = new Listener();