Improving stw and adding ability to clean-up mininet properly between runs.

Change-Id: Idb163bfa0cfd13b0ed7b9e4715ca7a2c0ffe69f6
diff --git a/tools/test/bin/ogroup-opts b/tools/test/bin/ogroup-opts
index fe35be2..cdc623f 100644
--- a/tools/test/bin/ogroup-opts
+++ b/tools/test/bin/ogroup-opts
@@ -12,15 +12,16 @@
 complete -F _ogroup-opts onos-group
 
 
-# Tab completion settings for stc
+# Tab completion settings for stc & stw
 function _stc-opts () {
   local cur=${COMP_WORDS[COMP_CWORD]}
-  if [ $COMP_CWORD -eq 1 ]; then
+  if [ $COMP_CWORD -ge 1 ]; then
     COMPREPLY=( $( compgen -W "$(cd $ONOS_ROOT/tools/test/scenarios && ls -1 | sed 's/.xml//g')" -- $cur ) )
   fi
 }
 
 complete -F _stc-opts stc
+complete -F _stc-opts stw
 
 
 # Tab completion settings for stl
diff --git a/tools/test/bin/onos-mininet b/tools/test/bin/onos-mininet
index ef2c8ea..4ce341e 100755
--- a/tools/test/bin/onos-mininet
+++ b/tools/test/bin/onos-mininet
@@ -66,4 +66,8 @@
         $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
         $mininet -X "stuff \"exit\\n\"" 2>/dev/null
     ;;
+cleanup)
+    ssh -t -t $remote sudo mn -c
+    ssh -t -t $remote "ps -ef | grep 'tail -n1 screenlog.0' | grep -v grep | cut -c10-15 | xargs kill -9"
+    ;;
 esac
diff --git a/tools/test/bin/stw b/tools/test/bin/stw
index f78659d..d3a00c2 100755
--- a/tools/test/bin/stw
+++ b/tools/test/bin/stw
@@ -3,13 +3,40 @@
 # Loops the System Test Coordinator invocations while success/until failure.
 #-------------------------------------------------------------------------------
 
+count=0
+unset doSetup doTeardown
+
+# Scan arguments for user/password or other options...
+while getopts c:st o; do
+    case "$o" in
+        c) count=$OPTARG;;
+        s) doSetup=true;;
+        t) toTeardown=true;;
+    esac
+done
+let OPC=$OPTIND-1
+shift $OPC
+
+if [ -n "$doSetup" ]; then
+    printf "Setting up...\n"
+    stc setup || exit 1
+fi
+
 let run=1
-while true; do
+while [ $count -le 0 -o $run -le $count ]; do
     printf "\033]0;%s\007" "STC Run #$run"
     printf "Starting run %d...\n" $run
-    stc "$@"
+    for scenario in "${@:-smoke}"; do
+        printf "Running scenario %s...\n" $scenario
+        stc $scenario
+    done
     status=$?
     printf "Finished run %d...\n" $run
-    [ $status -ne 0 ] && break
+    [ $status -ne 0 ] && exit $status
     let run=run+1
 done
+
+if [ -n "$doTeardown" ]; then
+    printf "Tearing down...\n"
+    stc teardown || exit 1
+fi