Introduce arch-specific checker tests.

- The '.cfg' output is now created on target.
- Arch-specific checker tests can be created by inserting a
  suffix. For example:
      /// CHECK-START-ARM64: int Main.foo(int) register (after)
      /// CHECK-DAG:   <<Arg:i\d+>>     ParameterValue

Change-Id: I55cdb37f8e806c7ffdde6b676c8f44ac30b59051
diff --git a/test/526-checker-caller-callee-regs/expected.txt b/test/526-checker-caller-callee-regs/expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/526-checker-caller-callee-regs/expected.txt
diff --git a/test/526-checker-caller-callee-regs/info.txt b/test/526-checker-caller-callee-regs/info.txt
new file mode 100644
index 0000000..0e0373a
--- /dev/null
+++ b/test/526-checker-caller-callee-regs/info.txt
@@ -0,0 +1 @@
+Test allocation of caller and callee saved registers.
diff --git a/test/526-checker-caller-callee-regs/src/Main.java b/test/526-checker-caller-callee-regs/src/Main.java
new file mode 100644
index 0000000..a1f3301
--- /dev/null
+++ b/test/526-checker-caller-callee-regs/src/Main.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Main {
+
+  public static void assertIntEquals(int expected, int result) {
+    if (expected != result) {
+      throw new Error("Expected: " + expected + ", found: " + result);
+    }
+  }
+
+  static boolean doThrow = false;
+
+  // This function always returns 1.
+  // We use 'throw' to prevent the function from being inlined.
+  public static int $opt$noinline$function_call(int arg) {
+    if (doThrow) throw new Error();
+    return 1 % arg;
+  }
+
+  //                               | registers available to | regexp
+  //                               | the register allocator |
+  // ------------------------------|------------------------|-----------------
+  // ARM64 callee-saved registers  | [x20-x29]              | x2[0-9]
+  // ARM callee-saved registers    | [r5-r8,r10,r11]        | r([5-8]|10|11)
+
+  /**
+   * Check that a value live across a function call is allocated in a callee
+   * saved register.
+   */
+
+  /// CHECK-START-ARM:   int Main.$opt$LiveInCall(int) register (after)
+  /// CHECK-DAG:   <<Arg:i\d+>>     ParameterValue
+  /// CHECK-DAG:   <<Const1:i\d+>>  IntConstant 1
+  /// CHECK:       <<t1:i\d+>>      Add [<<Arg>>,<<Const1>>] {{.*->r([5-8]|10|11)}}
+  /// CHECK:       <<t2:i\d+>>      InvokeStaticOrDirect
+  /// CHECK:                        Sub [<<t1>>,<<t2>>]
+  /// CHECK:                        Return
+
+  /// CHECK-START-ARM64: int Main.$opt$LiveInCall(int) register (after)
+  /// CHECK-DAG:   <<Arg:i\d+>>     ParameterValue
+  /// CHECK-DAG:   <<Const1:i\d+>>  IntConstant 1
+  /// CHECK:       <<t1:i\d+>>      Add [<<Arg>>,<<Const1>>] {{.*->x2[0-9]}}
+  /// CHECK:       <<t2:i\d+>>      InvokeStaticOrDirect
+  /// CHECK:                        Sub [<<t1>>,<<t2>>]
+  /// CHECK:                        Return
+
+  // TODO: Add tests for other architectures.
+
+  public static int $opt$LiveInCall(int arg) {
+    int t1 = arg + 1;
+    int t2 = $opt$noinline$function_call(arg);
+    return t1 - t2;
+  }
+
+  public static void main(String[] args) {
+    int arg = 123;
+    assertIntEquals($opt$LiveInCall(arg), arg);
+  }
+}
diff --git a/test/run-test b/test/run-test
index 3d6f073..84c818b 100755
--- a/test/run-test
+++ b/test/run-test
@@ -626,12 +626,19 @@
   # on a particular DEX output, keep building them with dx for now (b/19467889).
   USE_JACK="false"
 
-  if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$target_mode" = "no" -a "$debuggable" = "no" ]; then
+  if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$debuggable" = "no" ]; then
     # In no-prebuild mode, the compiler is only invoked if both dex2oat and
     # patchoat are available. Disable Checker otherwise (b/22552692).
     if [ "$prebuild_mode" = "yes" ] || [ "$have_patchoat" = "yes" -a "$have_dex2oat" = "yes" ]; then
       run_checker="yes"
-      run_args="${run_args} -Xcompiler-option --dump-cfg=$tmp_dir/$cfg_output \
+      if [ "$target_mode" = "no" ]; then
+        cfg_output_dir="$tmp_dir"
+        checker_arch_option=
+      else
+        cfg_output_dir="$DEX_LOCATION"
+        checker_arch_option="--arch=${target_arch_name^^}"
+      fi
+      run_args="${run_args} -Xcompiler-option --dump-cfg=$cfg_output_dir/$cfg_output \
                             -Xcompiler-option -j1"
     fi
   fi
@@ -647,6 +654,12 @@
   build_file_size_limit=5120
   run_file_size_limit=5120
 fi
+if [ "$run_checker" = "yes" -a "$target_mode" = "yes" ]; then
+  # We will need to `adb pull` the .cfg output from the target onto the host to
+  # run checker on it. This file can be big.
+  build_file_size_limit=16384
+  run_file_size_limit=16384
+fi
 if [ ${USE_JACK} = "false" ]; then
   # Set ulimit if we build with dx only, Jack can generate big temp files.
   if ! ulimit -S "$build_file_size_limit"; then
@@ -671,7 +684,10 @@
 
         if [ "$run_exit" = "0" ]; then
             if [ "$run_checker" = "yes" ]; then
-                "$checker" "$cfg_output" "$tmp_dir" 2>&1
+                if [ "$target_mode" = "yes" ]; then
+                  adb pull $cfg_output_dir/$cfg_output &> /dev/null
+                fi
+                "$checker" $checker_arch_option "$cfg_output" "$tmp_dir" 2>&1
                 checker_exit="$?"
                 if [ "$checker_exit" = "0" ]; then
                     good="yes"
@@ -693,7 +709,10 @@
         echo "${test_dir}: running..." 1>&2
         "./${run}" $run_args "$@" >"$output" 2>&1
         if [ "$run_checker" = "yes" ]; then
-          "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
+          if [ "$target_mode" = "yes" ]; then
+            adb pull $cfg_output_dir/$cfg_output &> /dev/null
+          fi
+          "$checker" -q $checker_arch_option "$cfg_output" "$tmp_dir" >> "$output" 2>&1
         fi
         sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
         good="yes"
@@ -731,7 +750,10 @@
             echo "run exit status: $run_exit" 1>&2
             good_run="no"
         elif [ "$run_checker" = "yes" ]; then
-            "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
+            if [ "$target_mode" = "yes" ]; then
+              adb pull $cfg_output_dir/$cfg_output &> /dev/null
+            fi
+            "$checker" -q $checker_arch_option "$cfg_output" "$tmp_dir" >> "$output" 2>&1
             checker_exit="$?"
             if [ "$checker_exit" != "0" ]; then
                 echo "checker exit status: $checker_exit" 1>&2