run-tests with jvmti-stress configuration

Adds a jvmti-stress mode to our run-tests. This mode runs our test
suite with every class-load being intercepted and undergoing
redefinition.

Test: DEXTER_BINARY="/path/to/built/dexter" \
      ./testrunner/testrunner.py --host --jvmti-stress -j40

Change-Id: I898e5cffea42a203aa4c45981b48baf8dc64fbb6
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index f1b6132..56cfd24 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -62,6 +62,7 @@
 TEST_VDEX="n"
 TEST_IS_NDEBUG="n"
 APP_IMAGE="y"
+JVMTI_STRESS="n"
 VDEX_FILTER=""
 PROFILE="n"
 RANDOM_PROFILE="n"
@@ -145,6 +146,11 @@
     elif [ "x$1" = "x--prebuild" ]; then
         PREBUILD="y"
         shift
+    elif [ "x$1" = "x--jvmti-stress" ]; then
+        # APP_IMAGE doesn't really work with jvmti-torture
+        APP_IMAGE="n"
+        JVMTI_STRESS="y"
+        shift
     elif [ "x$1" = "x--no-app-image" ]; then
         APP_IMAGE="n"
         shift
@@ -365,6 +371,28 @@
   fi
 fi
 
+if [[ "$JVMTI_STRESS" = "y" ]]; then
+  if [[ "$USE_JVM" = "n" ]]; then
+    plugin=libopenjdkjvmtid.so
+    agent=libtistressd.so
+    if  [[ "$TEST_IS_NDEBUG" = "y" ]]; then
+      agent=libtistress.so
+      plugin=libopenjdkjvmti.so
+    fi
+
+    file_1=$(mktemp --tmpdir=${DEX_LOCATION})
+    file_2=$(mktemp --tmpdir=${DEX_LOCATION})
+    # TODO Remove need for DEXTER_BINARY!
+    FLAGS="${FLAGS} -agentpath:${agent}=${DEXTER_BINARY},${file_1},${file_2}"
+    if [ "$IS_JVMTI_TEST" = "n" ]; then
+      FLAGS="${FLAGS} -Xplugin:${plugin}"
+      FLAGS="${FLAGS} -Xcompiler-option --debuggable"
+      # Always make the compilation be debuggable.
+      COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
+    fi
+  fi
+fi
+
 if [ "$USE_JVM" = "y" ]; then
   export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
   # Xmx is necessary since we don't pass down the ART flags to JVM.