Make ART's run-test support Dalvik so we can remove dalvik/tests

Change-Id: Iba4ddf39169346573c97b443d5d65c6b8963fd4b
diff --git a/build/Android.oat.mk b/build/Android.oat.mk
index ea7b0b0..e8438a2 100644
--- a/build/Android.oat.mk
+++ b/build/Android.oat.mk
@@ -81,6 +81,16 @@
 include $(BUILD_PHONY_PACKAGE)
 endif
 
+ifeq ($(ART_BUILD_TARGET),true)
+include $(CLEAR_VARS)
+LOCAL_MODULE := core.art
+LOCAL_MODULE_TAGS := optional
+LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common.mk
+LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.oat.mk
+LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_CORE_IMG_OUT)
+include $(BUILD_PHONY_PACKAGE)
+endif
+
 ########################################################################
 # The full system boot classpath
 TARGET_BOOT_JARS := $(subst :, ,$(DEXPREOPT_BOOT_JARS))
diff --git a/test/055-enum-performance/run b/test/055-enum-performance/run
index 1436ce2..e27a622 100755
--- a/test/055-enum-performance/run
+++ b/test/055-enum-performance/run
@@ -14,5 +14,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# As this is a performance test we always run -O
-exec ${RUN} -O "$@"
+# As this is a performance test we always use the non-debug build.
+exec ${RUN} "${@/#libartd.so/libart.so}"
diff --git a/test/etc/host-run-test-jar b/test/etc/host-run-test-jar
index 357fb5a..da74532 100755
--- a/test/etc/host-run-test-jar
+++ b/test/etc/host-run-test-jar
@@ -9,7 +9,6 @@
     fi
 }
 
-LIB="libartd.so"
 DEBUGGER="n"
 GDB="n"
 INTERPRETER="n"
@@ -23,11 +22,17 @@
     if [ "x$1" = "x--quiet" ]; then
         QUIET="y"
         shift
-    elif [ "x$1" = "x-lib" ]; then
+    elif [ "x$1" = "x--lib" ]; then
         shift
+        if [ "x$1" = "x" ]; then
+            echo "$0 missing argument to --lib" 1>&2
+            exit 1
+        fi
         LIB="$1"
-    elif [ "x$1" = "x-O" ]; then
-        LIB="libart.so"
+        shift
+    elif [ "x$1" = "x--boot" ]; then
+        shift
+        BOOT_OPT="$1"
         shift
     elif [ "x$1" = "x--debug" ]; then
         DEBUGGER="y"
@@ -38,6 +43,10 @@
         shift
     elif [ "x$1" = "x--invoke-with" ]; then
         shift
+        if [ "x$1" = "x" ]; then
+            echo "$0 missing argument to --invoke-with" 1>&2
+            exit 1
+        fi
         if [ "x$INVOKE_WITH" = "x" ]; then
             INVOKE_WITH="$1"
         else
@@ -106,7 +115,9 @@
 
 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
 
+if [ "$DEV_MODE" = "y" ]; then
+  echo $cmdline "$@"
+fi
+
 cd $ANDROID_BUILD_TOP
-$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB -Ximage:$ANDROID_ROOT/framework/core.art \
-    $JNI_OPTS $INT_OPTS $DEBUGGER_OPTS \
-    -cp $DEX_LOCATION/$TEST_NAME.jar Main "$@"
+$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB $JNI_OPTS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main "$@"
diff --git a/test/etc/push-and-run-test-jar b/test/etc/push-and-run-test-jar
index cc28592..ff75d32 100755
--- a/test/etc/push-and-run-test-jar
+++ b/test/etc/push-and-run-test-jar
@@ -9,7 +9,6 @@
     fi
 }
 
-LIB="libartd.so"
 GDB="n"
 DEBUGGER="n"
 INTERPRETER="n"
@@ -24,11 +23,17 @@
     if [ "x$1" = "x--quiet" ]; then
         QUIET="y"
         shift
-    elif [ "x$1" = "x-lib" ]; then
+    elif [ "x$1" = "x--lib" ]; then
         shift
+        if [ "x$1" = "x" ]; then
+            echo "$0 missing argument to --lib" 1>&2
+            exit 1
+        fi
         LIB="$1"
-    elif [ "x$1" = "x-O" ]; then
-        LIB="libart.so"
+        shift
+    elif [ "x$1" = "x--boot" ]; then
+        shift
+        BOOT_OPT="$1"
         shift
     elif [ "x$1" = "x--debug" ]; then
         DEBUGGER="y"
@@ -49,6 +54,10 @@
         shift
     elif [ "x$1" = "x--invoke-with" ]; then
         shift
+        if [ "x$1" = "x" ]; then
+            echo "$0 missing argument to --invoke-with" 1>&2
+            exit 1
+        fi
         if [ "x$INVOKE_WITH" = "x" ]; then
             INVOKE_WITH="$1"
         else
@@ -132,7 +141,7 @@
 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
 
 cmdline="cd $DEX_LOCATION && mkdir dalvik-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
-    $INVOKE_WITH $gdb dalvikvm $gdbargs -XXlib:$LIB $ZYGOTE $JNI_OPTS $INT_OPTS $DEBUGGER_OPTS -Ximage:/data/art-test/core.art -cp $DEX_LOCATION/$TEST_NAME.jar Main"
+    $INVOKE_WITH $gdb dalvikvm $gdbargs -XXlib:$LIB $ZYGOTE $JNI_OPTS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main"
 if [ "$DEV_MODE" = "y" ]; then
   echo $cmdline "$@"
 fi
diff --git a/test/run-test b/test/run-test
index 11dcfc5..a34cc72 100755
--- a/test/run-test
+++ b/test/run-test
@@ -58,12 +58,14 @@
 expected="expected.txt"
 output="output.txt"
 build_output="build-output.txt"
+lib="libartd.so"
 run_args="--quiet"
 
 target_mode="yes"
 dev_mode="no"
 update_mode="no"
 debug_mode="no"
+dalvik_mode="no"
 usage="no"
 build_only="no"
 
@@ -79,7 +81,16 @@
         NEED_DEX="false"
         shift
     elif [ "x$1" = "x-O" ]; then
-        run_args="${run_args} -O"
+        lib="libart.so"
+        shift
+    elif [ "x$1" = "x--dalvik" ]; then
+        lib="libdvm.so"
+        dalvik_mode="yes"
+        shift
+    elif [ "x$1" = "x--image" ]; then
+        shift
+        image="$1"
+        run_args="${run_args} --image $image"
         shift
     elif [ "x$1" = "x--debug" ]; then
         run_args="${run_args} --debug"
@@ -106,6 +117,11 @@
     elif [ "x$1" = "x--invoke-with" ]; then
         shift
         what="$1"
+        if [ "x$what" = "x" ]; then
+            echo "$0 missing argument to --invoke-with" 1>&2
+            usage="yes"
+            break
+        fi
         run_args="${run_args} --invoke-with ${what}"
         shift
     elif [ "x$1" = "x--dev" ]; then
@@ -118,6 +134,11 @@
     elif [ "x$1" = "x--output-path" ]; then
         shift
         tmp_dir=$1
+        if [ "x$tmp_dir" = "x" ]; then
+            echo "$0 missing argument to --output-path" 1>&2
+            usage="yes"
+            break
+        fi
         shift
     elif [ "x$1" = "x--update" ]; then
         update_mode="yes"
@@ -134,6 +155,24 @@
     fi
 done
 
+run_args="${run_args} --lib $lib"
+
+if [ "$dalvik_mode" = "no" ]; then
+    if [ "$target_mode" = "no" ]; then
+        run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
+    else
+        run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
+    fi
+else
+    if [ "$target_mode" = "no" ]; then
+        framework="${OUT}/system/framework"
+        bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
+        run_args="${run_args} --boot -Xbootclasspath:${bpath}"
+    else
+        true # defaults to using target BOOTCLASSPATH
+    fi
+fi
+
 if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
     echo "--dev and --update are mutually exclusive" 1>&2
     usage="yes"
@@ -185,6 +224,7 @@
         echo "                   other runtime options are ignored."
         echo "    --host         Use the host-mode virtual machine."
         echo "    --invoke-with  Pass --invoke-with option to runtime."
+        echo "    --dalvik       Use Dalvik (off by default)."
         echo "    --jvm          Use a host-local RI virtual machine."
         echo "    --output-path [path] Location where to store the build" \
              "files."
@@ -237,7 +277,7 @@
     if [ "$build_exit" = '0' ]; then
         echo "${test_dir}: running..." 1>&2
         "./${run}" $run_args "$@" 2>&1
-	run_exit="$?"
+        run_exit="$?"
         echo "run exit status: $run_exit" 1>&2
         if [ "$run_exit" = "0" ]; then
             good="yes"