Make run-test fail if output-path is too long

Long output-path in no prebuild mode leads to silent fallback to
interpreter in dalvikvm.

This change ensures that we handle this situation by failing the
test.

Bug: 31597671
Test: m test-art-run-test -j
Change-Id: I19a7cee788760a81c9395be1252b2edab0db39f7
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index c51cb0d..d8f42a2 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -404,6 +404,24 @@
   fi
 fi
 
+# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
+# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
+# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
+# remaining '/' into '@'.
+if [ "$HOST" = "y" ]; then
+  max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
+else
+  # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
+  max_filename_size=255
+fi
+# Compute VDEX_NAME.
+DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
+VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
+if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
+    echo  "Dex location path too long."
+    exit 1
+fi
+
 dex2oat_cmdline="true"
 mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
 strip_cmdline="true"