ART: Fix old run scripts

The run scripts had not been updated when the central command script
was unified, so they were always choosing target mode.

Also update the run scripts so they abort when wrong options are
used.

Also strip superfluous whitespace from commands.

Change-Id: I13cc59f43734a86062fc3ce5ff4ea308c301d4d3
diff --git a/test/116-nodex2oat/run b/test/116-nodex2oat/run
index 72488f0..9e5c7dd 100755
--- a/test/116-nodex2oat/run
+++ b/test/116-nodex2oat/run
@@ -16,6 +16,14 @@
 
 flags="${@}"
 
+# This test is supposed to test without oat files, so doesn't work for prebuild. Make sure that
+# flag isn't set, or complain.
+# Note: prebuild is the default.
+if [[ "${flags}" == *--prebuild* || "${flags}" != *--no-prebuild* ]] ; then
+  echo "Test 116-nodex2oat cannot run in prebuild mode."
+  exit 1
+fi
+
 # Make sure we can run without an oat file,
 echo "Run -Xnodex2oat"
 ${RUN} ${flags} --runtime-option -Xnodex2oat
diff --git a/test/117-nopatchoat/run b/test/117-nopatchoat/run
index a7c96a0..c749c74 100755
--- a/test/117-nopatchoat/run
+++ b/test/117-nopatchoat/run
@@ -16,10 +16,23 @@
 
 # ensure flags includes prebuild and relocate. It doesn't make sense unless we
 # have a oat file we want to relocate.
-# TODO Unfortunately we have no way to force prebuild on for both host and target (or skip if not on).
-flags="${@/--relocate/}"
-flags="${flags/--no-relocate/}"
-flags="${flags} --relocate"
+flags="$@"
+
+# This test is supposed to test with oat files. Make sure that the no-prebuild flag isn't set,
+# or complain.
+# Note: prebuild is the default.
+if [[ "${flags}" == *--no-prebuild* ]] ; then
+  echo "Test 117-nopatchoat is not intended to run in no-prebuild mode."
+  exit 1
+fi
+
+# This test is supposed to test relocation. Make sure that the no-relocate flag isn't set,
+# or complain.
+# Note: relocate is the default.
+if [[ "${flags}" == *--no-relocate* ]] ; then
+  echo "Test 117-nopatchoat is not intended to run in no-relocate mode."
+  exit 1
+fi
 
 # Make sure we can run without relocation
 echo "Run without dex2oat/patchoat"
diff --git a/test/118-noimage-dex2oat/run b/test/118-noimage-dex2oat/run
index 92a4ec2..2037797 100644
--- a/test/118-noimage-dex2oat/run
+++ b/test/118-noimage-dex2oat/run
@@ -14,17 +14,26 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+flags="$@"
+
+# This test is supposed to test without oat files, so doesn't work for prebuild. Make sure that
+# flag isn't set, or complain.
+# Note: prebuild is the default.
+if [[ "${flags}" == *--prebuild* || "${flags}" != *--no-prebuild* ]] ; then
+  echo "Test 118-noimage-dex2oat cannot run in prebuild mode."
+  exit 1
+fi
+
 # Force relocation otherwise we will just use the already created core.oat/art pair.
-flags="${@/--no-relocate/--relocate}"
+# Note: relocate is the default.
+if [[ "${flags}" == *--no-relocate* ]] ; then
+  echo "Test 118-noimage-dex2oat is not intended to run in no-relocate mode."
+  exit 1
+fi
 
-# Use the non-prebuild script.
-RUN="${RUN/push-and-run-prebuilt-test-jar/push-and-run-test-jar}"
-
-if [ $(basename $RUN) == 'host-run-test-jar' ]; then
+if [[ $@ == *--host* ]]; then
     framework="${ANDROID_HOST_OUT}/framework"
     bpath_suffix="-hostdex"
-    # Remove prebuild from the flags, this test is for testing not having oat files.
-    flags="${flags/--prebuild/}"
 else
     framework="/system/framework"
     bpath_suffix=""
diff --git a/test/119-noimage-patchoat/run b/test/119-noimage-patchoat/run
index 745b0c9..c409cbb 100644
--- a/test/119-noimage-patchoat/run
+++ b/test/119-noimage-patchoat/run
@@ -14,10 +14,16 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Force relocation otherwise we will just use the already created core.oat/art pair.
-flags="${@/--no-relocate/--relocate}"
+flags="$@"
 
-if [ $(basename $RUN) == 'host-run-test-jar' ]; then
+# Force relocation otherwise we will just use the already created core.oat/art pair.
+# Note: relocate is the default.
+if [[ "${flags}" == *--no-relocate* ]] ; then
+  echo "Test 119-noimage-patchoat is not intended to run in no-relocate mode."
+  exit 1
+fi
+
+if [[ $@ == *--host* ]]; then
   false_bin="/bin/false"
 else
   false_bin="/system/bin/false"
diff --git a/test/Android.run-test.mk b/test/Android.run-test.mk
index 2057cb9..a8f2001 100644
--- a/test/Android.run-test.mk
+++ b/test/Android.run-test.mk
@@ -180,7 +180,8 @@
 
 # Note 116-nodex2oat is not broken per-se it just doesn't (and isn't meant to) work with --prebuild.
 TEST_ART_BROKEN_PREBUILD_RUN_TESTS := \
-  116-nodex2oat
+  116-nodex2oat \
+  118-noimage-dex2oat
 
 ifneq (,$(filter prebuild,$(PREBUILD_TYPES)))
   ART_TEST_KNOWN_BROKEN += $(call all-run-test-names,$(TARGET_TYPES),$(RUN_TYPES),prebuild, \
@@ -204,7 +205,9 @@
 # Note 117-nopatchoat is not broken per-se it just doesn't work (and isn't meant to) without
 # --prebuild --relocate
 TEST_ART_BROKEN_NO_RELOCATE_TESTS := \
-  117-nopatchoat
+  117-nopatchoat \
+  118-noimage-dex2oat \
+  119-noimage-patchoat
 
 ifneq (,$(filter no-relocate,$(RELOCATE_TYPES)))
   ART_TEST_KNOWN_BROKEN += $(call all-run-test-names,$(TARGET_TYPES),$(RUN_TYPES),$(PREBUILD_TYPES), \
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index 92b1e82..907218a 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -309,6 +309,9 @@
                   $DALVIKVM_BOOT_OPT \
                   -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN"
 
+# Remove whitespace.
+dex2oat_cmdline=$(echo $dex2oat_cmdline)
+dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
 
 if [ "$HOST" = "n" ]; then
     adb root > /dev/null