Incorporate random profile tests into run-test.

Uses profman to generate random profiles to pass into run-test.
Adds a new COMPILER_TYPE "speed-profile" to the build.

Bug: 36107940
Test: mm test-art-host

(cherry-picked from 002b9314d0e432ecc85e43d8fe800e375a33cebb)

Change-Id: Ie123c1abb6b24e57f4c00912ea58158fe167ed01
diff --git a/build/Android.common_test.mk b/build/Android.common_test.mk
index 1876efc..1ae79ac 100644
--- a/build/Android.common_test.mk
+++ b/build/Android.common_test.mk
@@ -66,6 +66,9 @@
 # Do you want to test the optimizing compiler with graph coloring register allocation?
 ART_TEST_OPTIMIZING_GRAPH_COLOR ?= $(ART_TEST_FULL)
 
+# Do you want to do run-tests with profiles?
+ART_TEST_SPEED_PROFILE ?= $(ART_TEST_FULL)
+
 # Do we want to test PIC-compiled tests ("apps")?
 ART_TEST_PIC_TEST ?= $(ART_TEST_FULL)
 
diff --git a/test/Android.run-test.mk b/test/Android.run-test.mk
index cc015b0..187b383 100644
--- a/test/Android.run-test.mk
+++ b/test/Android.run-test.mk
@@ -208,7 +208,7 @@
 endef
 
 TARGET_TYPES := host target
-COMPILER_TYPES := jit interpreter optimizing regalloc_gc jit interp-ac
+COMPILER_TYPES := jit interpreter optimizing regalloc_gc jit interp-ac speed-profile
 IMAGE_TYPES := picimage no-image multipicimage
 ALL_ADDRESS_SIZES := 64 32
 
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index 808e58a..f1b6132 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -64,6 +64,7 @@
 APP_IMAGE="y"
 VDEX_FILTER=""
 PROFILE="n"
+RANDOM_PROFILE="n"
 
 # if "y", run 'sync' before dalvikvm to make sure all files from
 # build step (e.g. dex2oat) were finished writing.
@@ -273,6 +274,9 @@
     elif [ "x$1" = "x--profile" ]; then
         PROFILE="y"
         shift
+    elif [ "x$1" = "x--random-profile" ]; then
+        RANDOM_PROFILE="y"
+        shift
     elif expr "x$1" : "x--" >/dev/null 2>&1; then
         echo "unknown $0 option: $1" 1>&2
         exit 1
@@ -506,17 +510,23 @@
 strip_cmdline="true"
 sync_cmdline="true"
 
-if [ "$PROFILE" = "y" ]; then
+# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
+# specific profile to run properly.
+if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
   profman_cmdline="${ANDROID_ROOT}/bin/profman  \
     --apk=$DEX_LOCATION/$TEST_NAME.jar \
-    --dex-location=$DEX_LOCATION/$TEST_NAME.jar \
-    --create-profile-from=$DEX_LOCATION/profile \
-    --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
+    --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
   COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
   FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
+  if [ "$PROFILE" = "y" ]; then
+    profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
+        --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
+  else
+    profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
+        --generate-test-profile-seed=0"
+  fi
 fi
 
-
 if [ "$PREBUILD" = "y" ]; then
   mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
   if [ "$APP_IMAGE" = "y" ]; then
@@ -603,7 +613,7 @@
       adb shell mkdir -p $DEX_LOCATION
       adb push $TEST_NAME.jar $DEX_LOCATION
       adb push $TEST_NAME-ex.jar $DEX_LOCATION
-      if [ "$PROFILE" = "y" ]; then
+      if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
         adb push profile $DEX_LOCATION
       fi
     else
@@ -611,7 +621,7 @@
       adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
       adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
       adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
-      if [ "$PROFILE" = "y" ]; then
+      if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
         adb push profile $DEX_LOCATION >/dev/null 2>&1
       fi
 
diff --git a/test/knownfailures.json b/test/knownfailures.json
index 3f722c7..1738acf 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -259,7 +259,7 @@
                   "602-deoptimizeable"],
         "description": ["Tests that should fail when the optimizing compiler ",
                         "compiles them non-debuggable."],
-        "variant": "optimizing &  ndebuggable | regalloc_gc & ndebuggable"
+        "variant": "optimizing & ndebuggable | regalloc_gc & ndebuggable | speed-profile & ndebuggable"
     },
     {
         "tests": "596-app-images",
diff --git a/test/run-all-tests b/test/run-all-tests
index 402c299..a0d2f23 100755
--- a/test/run-all-tests
+++ b/test/run-all-tests
@@ -155,6 +155,9 @@
     elif [ "x$1" = "x--strace" ]; then
         run_args="${run_args} --strace"
         shift
+    elif [ "x$1" = "x--random-profile" ]; then
+        run_args="${run_args} --random-profile"
+        shift
     elif expr "x$1" : "x--" >/dev/null 2>&1; then
         echo "unknown $0 option: $1" 1>&2
         usage="yes"
diff --git a/test/run-test b/test/run-test
index a6903ff..91ffdfa 100755
--- a/test/run-test
+++ b/test/run-test
@@ -382,6 +382,9 @@
         filter=$1
         run_args="${run_args} --vdex-filter $filter"
         shift
+    elif [ "x$1" = "x--random-profile" ]; then
+        run_args="${run_args} --random-profile"
+        shift
     elif expr "x$1" : "x--" >/dev/null 2>&1; then
         echo "unknown $0 option: $1" 1>&2
         usage="yes"
diff --git a/test/testrunner/env.py b/test/testrunner/env.py
index e93fb3a..46244a4 100644
--- a/test/testrunner/env.py
+++ b/test/testrunner/env.py
@@ -105,6 +105,9 @@
 # Do you want to test the optimizing compiler with graph coloring register allocation?
 ART_TEST_OPTIMIZING_GRAPH_COLOR = getEnvBoolean('ART_TEST_OPTIMIZING_GRAPH_COLOR', ART_TEST_FULL)
 
+# Do you want to do run-tests with profiles?
+ART_TEST_SPEED_PROFILE = getEnvBoolean('ART_TEST_SPEED_PROFILE', ART_TEST_FULL)
+
 # Do we want to test PIC-compiled tests ("apps")?
 ART_TEST_PIC_TEST = getEnvBoolean('ART_TEST_PIC_TEST', ART_TEST_FULL)
 # Do you want tracing tests run?
diff --git a/test/testrunner/testrunner.py b/test/testrunner/testrunner.py
index 149578d..49dc657 100755
--- a/test/testrunner/testrunner.py
+++ b/test/testrunner/testrunner.py
@@ -147,7 +147,7 @@
   VARIANT_TYPE_DICT['jni'] = {'jni', 'forcecopy', 'checkjni'}
   VARIANT_TYPE_DICT['address_sizes'] = {'64', '32'}
   VARIANT_TYPE_DICT['compiler'] = {'interp-ac', 'interpreter', 'jit', 'optimizing',
-                              'regalloc_gc'}
+                              'regalloc_gc', 'speed-profile'}
 
   for v_type in VARIANT_TYPE_DICT:
     TOTAL_VARIANTS_SET = TOTAL_VARIANTS_SET.union(VARIANT_TYPE_DICT.get(v_type))
@@ -192,6 +192,8 @@
   if env.ART_TEST_OPTIMIZING:
     COMPILER_TYPES.add('optimizing')
     OPTIMIZING_COMPILER_TYPES.add('optimizing')
+  if env.ART_TEST_SPEED_PROFILE:
+    COMPILER_TYPES.add('speed-profile')
 
   # By default we run all 'compiler' variants.
   if not COMPILER_TYPES:
@@ -199,6 +201,7 @@
     COMPILER_TYPES.add('jit')
     COMPILER_TYPES.add('interpreter')
     COMPILER_TYPES.add('interp-ac')
+    COMPILER_TYPES.add('speed-profile')
     OPTIMIZING_COMPILER_TYPES.add('optimizing')
 
   if env.ART_TEST_RUN_TEST_RELOCATE:
@@ -389,6 +392,8 @@
         options_test += ' --interpreter --verify-soft-fail'
       elif compiler == 'jit':
         options_test += ' --jit'
+      elif compiler == 'speed-profile':
+        options_test += ' --random-profile'
 
       if relocate == 'relocate':
         options_test += ' --relocate'
@@ -881,6 +886,8 @@
     IMAGE_TYPES.add('no-image')
   if options['optimizing']:
     COMPILER_TYPES.add('optimizing')
+  if options['speed_profile']:
+    COMPILER_TYPES.add('speed-profile')
   if options['trace']:
     TRACE_TYPES.add('trace')
   if options['gcstress']: