build: Add golem run_build_test_targets for go/ab

Adds following golem build targets:
 * art-golem-android-armv7
 * art-golem-android-armv8
 * art-golem-linux-armv7
 * art-golem-linux-armv8
 * art-golem-linux-ia32 (this is a host build)
 * art-golem-linux-x64  (this is a host build)

Call the art/tools/golem/build-target.sh with its corresponding target name as the
machine type, and it uses art-opt-cc for golem config type.

Ensures that we don't accidentally break the golem targets.

Also refactor the target_config.py to make it more clear
what's a make, run-test, or golem command.

Bug: 35766356
Change-Id: Id1a72e5eaed8b20d1d208cf0720b1cb45d48e74d
diff --git a/test/testrunner/run_build_test_target.py b/test/testrunner/run_build_test_target.py
index 282ac48..0ab50af 100755
--- a/test/testrunner/run_build_test_target.py
+++ b/test/testrunner/run_build_test_target.py
@@ -16,14 +16,14 @@
 
 """Build and run go/ab/git_master-art-host target
 
+This script is executed by the android build server and must not be moved,
+or changed in an otherwise backwards-incompatible manner.
+
 Provided with a target name, the script setup the environment for
 building the test target by taking config information from
 from target_config.py.
 
-If the target field is defined in the configuration for the target, it
-invokes `make` to build the target, otherwise, it assumes
-that the its is a run-test target, and invokes testrunner.py
-script for building and running the run-tests.
+See target_config.py for the configuration syntax.
 """
 
 import argparse
@@ -35,10 +35,26 @@
 import env
 
 parser = argparse.ArgumentParser()
-parser.add_argument('build_target')
 parser.add_argument('-j', default='1', dest='n_threads')
+# either -l/--list OR build-target is required (but not both).
+group = parser.add_mutually_exclusive_group(required=True)
+group.add_argument('build_target', nargs='?')
+group.add_argument('-l', '--list', action='store_true', help='List all possible run-build targets.')
 options = parser.parse_args()
 
+##########
+
+if options.list:
+  print "List of all known build_target: "
+  for k in sorted(target_config.iterkeys()):
+    print " * " + k
+  # TODO: would be nice if this was the same order as the target config file.
+  sys.exit(1)
+
+if not target_config.get(options.build_target):
+  sys.stderr.write("error: invalid build_target, see -l/--list.\n")
+  sys.exit(1)
+
 target = target_config[options.build_target]
 n_threads = options.n_threads
 custom_env = target.get('env', {})
@@ -46,28 +62,46 @@
 print custom_env
 os.environ.update(custom_env)
 
-if target.get('target'):
+if target.get('make'):
   build_command = 'make'
   build_command += ' -j' + str(n_threads)
   build_command += ' -C ' + env.ANDROID_BUILD_TOP
-  build_command += ' ' + target.get('target')
+  build_command += ' ' + target.get('make')
   # Add 'dist' to avoid Jack issues b/36169180.
   build_command += ' dist'
-  sys.stdout.write(str(build_command))
+  sys.stdout.write(str(build_command) + '\n')
   sys.stdout.flush()
   if subprocess.call(build_command.split()):
     sys.exit(1)
 
-if target.get('run-tests'):
+if target.get('golem'):
+  machine_type = target.get('golem')
+  # use art-opt-cc by default since it mimics the default preopt config.
+  default_golem_config = 'art-opt-cc'
+
+  os.chdir(env.ANDROID_BUILD_TOP)
+  cmd =  ['art/tools/golem/build-target.sh']
+  cmd += ['-j' + str(n_threads)]
+  cmd += ['--showcommands']
+  cmd += ['--machine-type=%s' %(machine_type)]
+  cmd += ['--golem=%s' %(default_golem_config)]
+  cmd += ['--tarball']
+  sys.stdout.write(str(cmd) + '\n')
+  sys.stdout.flush()
+
+  if subprocess.call(cmd):
+    sys.exit(1)
+
+if target.get('run-test'):
   run_test_command = [os.path.join(env.ANDROID_BUILD_TOP,
                                    'art/test/testrunner/testrunner.py')]
-  run_test_command += target.get('flags', [])
+  run_test_command += target.get('run-test', [])
   run_test_command += ['-j', str(n_threads)]
   run_test_command += ['-b']
   run_test_command += ['--host']
   run_test_command += ['--verbose']
 
-  sys.stdout.write(str(run_test_command))
+  sys.stdout.write(str(run_test_command) + '\n')
   sys.stdout.flush()
   if subprocess.call(run_test_command):
     sys.exit(1)
diff --git a/test/testrunner/target_config.py b/test/testrunner/target_config.py
index 5a6ecff..82f7832 100644
--- a/test/testrunner/target_config.py
+++ b/test/testrunner/target_config.py
@@ -1,72 +1,86 @@
 target_config = {
+
+# Configuration syntax:
+#
+#   Required keys: (Use one or more of these)
+#    * golem - specify a golem machine-type to build, e.g. android-armv8
+#              (uses art/tools/golem/build-target.sh)
+#    * make - specify a make target to build, e.g. build-art-host
+#    * run-test - runs the tests in art/test/ directory with testrunner.py,
+#                 specify a list of arguments to pass to testrunner.py
+#
+#   Optional keys: (Use any of these)
+#    * env - Add additional environment variable to the current environment.
+#
+# *** IMPORTANT ***:
+#    This configuration is used by the android build server. Targets must not be renamed
+#    or removed.
+#
+
+##########################################
+
+    # ART run-test configurations
+    # (calls testrunner which builds and then runs the test targets)
+
     'art-test' : {
-        'target' : 'test-art-host-gtest',
-        'run-tests' : True,
-        'flags' : [],
+        'make' : 'test-art-host-gtest',
+        'run-test' : [],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-interpreter' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter'],
+        'run-test' : ['--interpreter'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-interpreter-access-checks' : {
-        'run-tests' : True,
-        'flags' : ['--interp-ac'],
+        'run-test' : ['--interp-ac'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-jit' : {
-        'run-tests' : True,
-        'flags' : ['--jit'],
+        'run-test' : ['--jit'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-gcstress-gcverify': {
-        'run-tests' : True,
-        'flags' : ['--gcstress',
-                   '--gcverify'],
+        'run-test': ['--gcstress',
+                     '--gcverify'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
             'ART_DEFAULT_GC_TYPE' : 'SS'
         }
     },
     'art-interpreter-gcstress' : {
-        'run-tests' : True,
-        'flags': ['--interpreter',
-                  '--gcstress'],
+        'run-test' : ['--interpreter',
+                      '--gcstress'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
             'ART_DEFAULT_GC_TYPE' : 'SS'
         }
     },
     'art-optimizing-gcstress' : {
-        'run-tests' : True,
-        'flags': ['--gcstress',
-                  '--optimizing'],
+        'run-test' : ['--gcstress',
+                      '--optimizing'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
             'ART_DEFAULT_GC_TYPE' : 'SS'
         }
     },
     'art-jit-gcstress' : {
-        'run-tests' : True,
-        'flags': ['--jit',
-                  '--gcstress'],
+        'run-test' : ['--jit',
+                      '--gcstress'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
             'ART_DEFAULT_GC_TYPE' : 'SS'
         }
     },
     'art-read-barrier' : {
-        'run-tests' : True,
-        'flags': ['--interpreter',
+        'run-test': ['--interpreter',
                   '--optimizing'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'true',
@@ -74,19 +88,17 @@
         }
     },
     'art-read-barrier-gcstress' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--optimizing',
-                   '--gcstress'],
+        'run-test' : ['--interpreter',
+                      '--optimizing',
+                      '--gcstress'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'true',
             'ART_HEAP_POISONING' : 'true'
         }
     },
     'art-read-barrier-table-lookup' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--optimizing'],
+        'run-test' : ['--interpreter',
+                      '--optimizing'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'true',
             'ART_READ_BARRIER_TYPE' : 'TABLELOOKUP',
@@ -94,39 +106,35 @@
         }
     },
     'art-debug-gc' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--optimizing'],
+        'run-test' : ['--interpreter',
+                      '--optimizing'],
         'env' : {
             'ART_TEST_DEBUG_GC' : 'true',
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-ss-gc' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--optimizing',
-                   '--jit'],
+        'run-test' : ['--interpreter',
+                      '--optimizing',
+                      '--jit'],
         'env' : {
             'ART_DEFAULT_GC_TYPE' : 'SS',
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-gss-gc' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--optimizing',
-                   '--jit'],
+        'run-test' : ['--interpreter',
+                      '--optimizing',
+                      '--jit'],
         'env' : {
             'ART_DEFAULT_GC_TYPE' : 'GSS',
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-ss-gc-tlab' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--optimizing',
-                   '--jit'],
+        'run-test' : ['--interpreter',
+                      '--optimizing',
+                      '--jit'],
         'env' : {
             'ART_DEFAULT_GC_TYPE' : 'SS',
             'ART_USE_TLAB' : 'true',
@@ -134,10 +142,9 @@
         }
     },
     'art-gss-gc-tlab' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--optimizing',
-                   '--jit'],
+        'run-test' : ['--interpreter',
+                      '--optimizing',
+                      '--jit'],
         'env' : {
             'ART_DEFAULT_GC_TYPE' : 'GSS',
             'ART_USE_TLAB' : 'true',
@@ -145,87 +152,82 @@
         }
     },
     'art-tracing' : {
-        'run-tests' : True,
-        'flags' : ['--trace'],
+        'run-test' : ['--trace'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-interpreter-tracing' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--trace'],
+        'run-test' : ['--interpreter',
+                      '--trace'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
         }
     },
     'art-forcecopy' : {
-        'run-tests' : True,
-        'flags' : ['--forcecopy'],
+        'run-test' : ['--forcecopy'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
         }
     },
     'art-no-prebuild' : {
-        'run-tests' : True,
-        'flags' : ['--no-prebuild'],
+        'run-test' : ['--no-prebuild'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
         }
     },
     'art-no-image' : {
-        'run-tests' : True,
-        'flags' : ['--no-image'],
+        'run-test' : ['--no-image'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
         }
     },
     'art-interpreter-no-image' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--no-image'],
+        'run-test' : ['--interpreter',
+                      '--no-image'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
         }
     },
     'art-relocate-no-patchoat' : {
-        'run-tests' : True,
-        'flags' : ['--relocate-npatchoat'],
+        'run-test' : ['--relocate-npatchoat'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
         }
     },
     'art-no-dex2oat' : {
-        'run-tests' : True,
-        'flags' : ['--no-dex2oat'],
+        'run-test' : ['--no-dex2oat'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
         }
     },
     'art-heap-poisoning' : {
-        'run-tests' : True,
-        'flags' : ['--interpreter',
-                   '--optimizing'],
+        'run-test' : ['--interpreter',
+                      '--optimizing'],
         'env' : {
             'ART_USE_READ_BARRIER' : 'false',
             'ART_HEAP_POISONING' : 'true'
         }
     },
+
+    # ART gtest configurations
+    # (calls make 'target' which builds and then runs the gtests).
+
     'art-gtest' : {
-        'target' :  'test-art-host-gtest',
+        'make' :  'test-art-host-gtest',
         'env' : {
             'ART_USE_READ_BARRIER' : 'true'
         }
     },
     'art-gtest-read-barrier': {
-        'target' :  'test-art-host-gtest',
+        'make' :  'test-art-host-gtest',
         'env' : {
             'ART_USE_READ_BARRIER' : 'true',
             'ART_HEAP_POISONING' : 'true'
         }
     },
     'art-gtest-read-barrier-table-lookup': {
-        'target' :  'test-art-host-gtest',
+        'make' :  'test-art-host-gtest',
         'env': {
             'ART_USE_READ_BARRIER' : 'true',
             'ART_READ_BARRIER_TYPE' : 'TABLELOOKUP',
@@ -233,21 +235,21 @@
         }
     },
     'art-gtest-ss-gc': {
-        'target' :  'test-art-host-gtest',
+        'make' :  'test-art-host-gtest',
         'env': {
             'ART_DEFAULT_GC_TYPE' : 'SS',
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-gtest-gss-gc': {
-        'target' :  'test-art-host-gtest',
+        'make' :  'test-art-host-gtest',
         'env' : {
             'ART_DEFAULT_GC_TYPE' : 'GSS',
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-gtest-ss-gc-tlab': {
-        'target' :  'test-art-host-gtest',
+        'make' :  'test-art-host-gtest',
         'env': {
             'ART_DEFAULT_GC_TYPE' : 'SS',
             'ART_USE_TLAB' : 'true',
@@ -255,7 +257,7 @@
         }
     },
     'art-gtest-gss-gc-tlab': {
-        'target' :  'test-art-host-gtest',
+        'make' :  'test-art-host-gtest',
         'env': {
             'ART_DEFAULT_GC_TYPE' : 'GSS',
             'ART_USE_TLAB' : 'true',
@@ -263,29 +265,54 @@
         }
     },
     'art-gtest-debug-gc' : {
-        'target' :  'test-art-host-gtest',
+        'make' :  'test-art-host-gtest',
         'env' : {
             'ART_TEST_DEBUG_GC' : 'true',
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-gtest-valgrind32': {
-        'target' : 'valgrind-test-art-host32',
+        'make' : 'valgrind-test-art-host32',
         'env': {
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-gtest-valgrind64': {
-        'target' : 'valgrind-test-art-host64',
+        'make' : 'valgrind-test-art-host64',
         'env': {
             'ART_USE_READ_BARRIER' : 'false'
         }
     },
     'art-gtest-heap-poisoning': {
-        'target' : 'valgrind-test-art-host64',
+        'make' : 'valgrind-test-art-host64',
         'env' : {
             'ART_HEAP_POISONING' : 'true',
             'ART_USE_READ_BARRIER' : 'false'
         }
-    }
+    },
+
+   # ART Golem build targets used by go/lem (continuous ART benchmarking),
+   # (art-opt-cc is used by default since it mimics the default preopt config),
+   #
+   # calls golem/build-target.sh which builds a golem tarball of the target name,
+   #     e.g. 'golem: android-armv7' produces an 'android-armv7.tar.gz' upon success.
+
+    'art-golem-android-armv7': {
+        'golem' : 'android-armv7'
+    },
+    'art-golem-android-armv8': {
+        'golem' : 'android-armv8'
+    },
+    'art-golem-linux-armv7': {
+        'golem' : 'linux-armv7'
+    },
+    'art-golem-linux-armv8': {
+        'golem' : 'linux-armv8'
+    },
+    'art-golem-linux-ia32': {
+        'golem' : 'linux-ia32'
+    },
+    'art-golem-linux-x64': {
+        'golem' : 'linux-x64'
+    },
 }