art/test: support sequential run

Introduce --seq option for art/test/run-all-tests.
This option runs tests one-by-one, avoiding failures
caused by busy CPU

Change-Id: Ibe29f749d267fb05dff4617787c7afcbdbeb43c0
Signed-off-by: Dmitry Petrochenko <dmitry.petrochenko@intel.com>
diff --git a/Android.mk b/Android.mk
index 92339af..01819ee 100644
--- a/Android.mk
+++ b/Android.mk
@@ -63,7 +63,7 @@
 	rm -f $(2ND_TARGET_OUT_INTERMEDIATES)/JAVA_LIBRARIES/*_intermediates/javalib.odex
 	rm -f $(2ND_TARGET_OUT_INTERMEDIATES)/APPS/*_intermediates/*.odex
 endif
-	rm -rf /tmp/test-*/dalvik-cache/*
+	rm -rf /tmp/$(USER)/test-*/dalvik-cache/*
 	rm -rf /tmp/android-data/dalvik-cache/*
 
 .PHONY: clean-oat-target
diff --git a/test/run-all-tests b/test/run-all-tests
index a6675df..3a991e9 100755
--- a/test/run-all-tests
+++ b/test/run-all-tests
@@ -35,6 +35,7 @@
 
 run_args=""
 usage="no"
+sequental="no"
 
 while true; do
     if [ "x$1" = "x--host" ]; then
@@ -70,6 +71,12 @@
     elif [ "x$1" = "x--help" ]; then
         usage="yes"
         shift
+    elif [ "x$1" = "x--seq" ]; then
+        sequental="yes"
+        shift
+    elif [ "x$1" = "x-O" ]; then
+        run_args="${run_args} -O"
+        shift
     elif expr "x$1" : "x--" >/dev/null 2>&1; then
         echo "unknown $0 option: $1" 1>&2
         usage="yes"
@@ -89,34 +96,55 @@
              "further documentation:"
         echo "    --debug --dev --host --interpreter --jvm --no-optimize"
         echo "    --no-verify -O --update --valgrind --zygote"
+        echo "  Specific Runtime Options:"
+        echo "    --seq                Run tests one-by-one, avoiding failures caused by busy CPU"
     ) 1>&2
     exit 1
 fi
 
-# start all the tests
-i=0
-for test_name in *; do
-  if [ -d "$test_name" -a -r "$test_name" -a -r "$test_name/info.txt" ]; then
-    ./run-test ${run_args} "$test_name" &
-    test_pids[i]=$!
-    test_names[test_pids[i]]="$test_name"
-    let i+=1
-  fi
-done
+if [ "$sequental" == "yes" ]; then
+  i=0
+  for test_name in *; do
+    if [ -d "$test_name" -a -r "$test_name" -a -r "$test_name/info.txt" ]; then
+      ./run-test ${run_args} "$test_name"
+      RES=$?
+      test_pids[i]=i
+      test_names[test_pids[i]]="$test_name"
+      if [ "$RES" != "0" ]; then
+        let failure_count+=1
+        failed_test_names="$failed_test_names ${test_names[i]}"
+      else
+        let succeeded_count+=1
+      fi
+      let i+=1
+    fi
+  done
+else
+  # start all the tests
+  i=0
+  for test_name in *; do
+    if [ -d "$test_name" -a -r "$test_name" -a -r "$test_name/info.txt" ]; then
+      ./run-test ${run_args} "$test_name" &
+      test_pids[i]=$!
+      test_names[test_pids[i]]="$test_name"
+      let i+=1
+    fi
+  done
 
-# wait for all the tests, collecting the failures
-failure_count=0
-succeeded_count=0
-failed_test_names=""
-for pid in ${test_pids[@]}; do
-  wait $pid
-  if [ "$?" != "0" ]; then
-    let failure_count+=1
-    failed_test_names="$failed_test_names ${test_names[$pid]}[pid=$pid]"
-  else
-    let succeeded_count+=1
-  fi
-done
+  # wait for all the tests, collecting the failures
+  failure_count=0
+  succeeded_count=0
+  failed_test_names=""
+  for pid in ${test_pids[@]}; do
+    wait $pid
+    if [ "$?" != "0" ]; then
+      let failure_count+=1
+      failed_test_names="$failed_test_names ${test_names[$pid]}[pid=$pid]"
+    else
+      let succeeded_count+=1
+    fi
+  done
+fi
 
 echo "succeeded tests: $succeeded_count"
 echo "failed tests: $failure_count"
diff --git a/test/run-test b/test/run-test
index 6e59641..1c5904f 100755
--- a/test/run-test
+++ b/test/run-test
@@ -33,7 +33,7 @@
 progdir=`pwd`
 prog="${progdir}"/`basename "${prog}"`
 test_dir="test-$$"
-tmp_dir="/tmp/${test_dir}"
+tmp_dir="/tmp/$USER/${test_dir}"
 
 export JAVA="java"
 export JAVAC="javac -g"
@@ -165,6 +165,7 @@
         break
     fi
 done
+mkdir -p $tmp_dir
 
 if [ ! "$runtime" = "jvm" ]; then
   run_args="${run_args} --lib $lib"
@@ -356,7 +357,7 @@
     cd "$oldwd"
     rm -rf "$tmp_dir"
     if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
-        adb shell rm -r $DEX_LOCATION
+        adb shell rm -rf $DEX_LOCATION
     fi
     exit 0
 fi