Merge "Add ability to have device-name based options"
diff --git a/test/testrunner/device_config.py b/test/testrunner/device_config.py
new file mode 100644
index 0000000..c7ed6f7
--- /dev/null
+++ b/test/testrunner/device_config.py
@@ -0,0 +1,20 @@
+device_config = {
+# Configuration syntax:
+#
+#  device: The value of ro.product.name or 'host'
+#  properties: (Use one or more of these).
+#     * run-test-args: additional run-test-args
+#
+# *** IMPORTANT ***:
+#    This configuration is used by the android build server. Targets must not be renamed
+#    or removed.
+#
+##########################################
+    # Fugu's don't have enough memory to support a 128m heap with normal concurrency.
+    'aosp_fugu' : {
+        'run-test-args': [ "--runtime-option", "-Xmx128m" ],
+    },
+    'fugu' : {
+        'run-test-args': [ "--runtime-option", "-Xmx128m" ],
+    },
+}
diff --git a/test/testrunner/testrunner.py b/test/testrunner/testrunner.py
index ca29d0a..0226cd4 100755
--- a/test/testrunner/testrunner.py
+++ b/test/testrunner/testrunner.py
@@ -60,6 +60,7 @@
 
 import env
 from target_config import target_config
+from device_config import device_config
 
 # timeout for individual tests.
 # TODO: make it adjustable per tests and for buildbots
@@ -116,6 +117,9 @@
 dex2oat_jobs = -1   # -1 corresponds to default threads for dex2oat
 run_all_configs = False
 
+# Dict containing extra arguments
+extra_arguments = { "host" : [], "target" : [] }
+
 # Dict to store user requested test variants.
 # key: variant_type.
 # value: set of variants user wants to run of type <key>.
@@ -239,6 +243,10 @@
       n_thread = get_default_threads('host')
     print_text("Concurrency: " + str(n_thread) + "\n")
 
+  global extra_arguments
+  for target in _user_input_variants['target']:
+    extra_arguments[target] = find_extra_device_arguments(target)
+
   global semaphore
   semaphore = threading.Semaphore(n_thread)
 
@@ -252,6 +260,33 @@
     COLOR_SKIP = ''
     COLOR_NORMAL = ''
 
+def find_extra_device_arguments(target):
+  """
+  Gets any extra arguments from the device_config.
+  """
+  if target == 'host':
+    return device_config.get(target, [])
+  else:
+    device = get_device_name()
+    return device_config.get(device, [])
+
+def get_device_name():
+  """
+  Gets the value of ro.product.name from remote device.
+  """
+  proc = subprocess.Popen(['adb', 'shell', 'getprop', 'ro.product.name'],
+                          stderr=subprocess.STDOUT,
+                          stdout = subprocess.PIPE,
+                          universal_newlines=True)
+  # only wait 2 seconds.
+  output = proc.communicate(timeout = 2)[0]
+  success = not proc.wait()
+  if success:
+    return output.strip()
+  else:
+    print_text("Unable to determine device type!\n")
+    print_text("Continuing anyway.\n")
+    return "UNKNOWN_TARGET"
 
 def run_tests(tests):
   """Creates thread workers to run the tests.
@@ -434,7 +469,7 @@
           tempfile.mkdtemp(dir=env.ART_HOST_TEST_DIR)) + options_test
 
       run_test_sh = env.ANDROID_BUILD_TOP + '/art/test/run-test'
-      command = run_test_sh + ' ' + options_test + ' ' + test
+      command = ' '.join((run_test_sh, options_test, ' '.join(extra_arguments[target]), test))
 
       semaphore.acquire()
       worker = threading.Thread(target=run_test, args=(command, test, variant_set, test_name))