ART: Make run tests out of oat tests

Transforms all former oat tests into run tests.

Change-Id: I190dd39456454c36e5538a2c044d993965a67533
diff --git a/test/004-StackWalk/expected.txt b/test/004-StackWalk/expected.txt
new file mode 100644
index 0000000..bde0024
--- /dev/null
+++ b/test/004-StackWalk/expected.txt
@@ -0,0 +1,4 @@
+1st call
+172001234567891011121314151617181920652310201919
+2nd call
+172001234567891011121314151617181920652310201919
diff --git a/test/004-StackWalk/info.txt b/test/004-StackWalk/info.txt
new file mode 100644
index 0000000..00b0d9a
--- /dev/null
+++ b/test/004-StackWalk/info.txt
@@ -0,0 +1 @@
+Imported from oat tests.
diff --git a/test/004-StackWalk/src/Main.java b/test/004-StackWalk/src/Main.java
new file mode 100644
index 0000000..1e2a91b
--- /dev/null
+++ b/test/004-StackWalk/src/Main.java
@@ -0,0 +1,93 @@
+public class Main {
+  public Main() {
+  }
+
+  int f() {
+    g(1);
+    g(2);
+    return 0;
+  }
+
+  void g(int num_calls) {
+    if (num_calls == 1) {
+      System.out.println("1st call");
+    } else if (num_calls == 2) {
+      System.out.println("2nd call");
+    }
+    System.out.println(shlemiel());
+  }
+
+  String shlemiel() {
+    String s0 = new String("0");
+    String s1 = new String("1");
+    String s2 = new String("2");
+    String s3 = new String("3");
+    String s4 = new String("4");
+    String s5 = new String("5");
+    String s6 = new String("6");
+    String s7 = new String("7");
+    String s8 = new String("8");
+    String s9 = new String("9");
+    String s10 = new String("10");
+    String s11 = new String("11");
+    String s12 = new String("12");
+    String s13 = new String("13");
+    String s14 = new String("14");
+    String s15 = new String("15");
+    String s16 = new String("16");
+    String s17 = new String("17");
+    String s18 = new String("18");
+    String s19 = new String("19");
+    String s20 = new String("20");
+    String s = new String();
+    s += s0;
+    s += s1;
+    s += s2;
+    s += s3;
+    s += s4;
+    s += s5;
+    s += s6;
+    s += s7;
+    s += s8;
+    s += s9;
+    s += s10;
+    s += s11;
+    s += s12;
+    s += s13;
+    s += s14;
+    s += s15;
+    s += s16;
+    s += s17;
+    s += s18;
+    s += s19;
+    s += s20;
+
+    s += s6;
+    s += s5;
+    s += s2;
+    s += s3;
+
+    s10 = s + s10;
+    s10 += s20;
+
+    s20 += s10;
+    s = s17 + s20;
+
+    s4 = s18 = s19;
+    s += s4;
+    s += s18;
+    stackmap(0);
+    return s;
+  }
+
+  native int stackmap(int x);
+
+  static {
+    System.loadLibrary("arttest");
+  }
+
+  public static void main(String[] args) {
+    Main st = new Main();
+    st.f();
+  }
+}
diff --git a/test/004-StackWalk/stack_walk_jni.cc b/test/004-StackWalk/stack_walk_jni.cc
new file mode 100644
index 0000000..30a0d59
--- /dev/null
+++ b/test/004-StackWalk/stack_walk_jni.cc
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#include <stdio.h>
+#include <memory>
+
+#include "class_linker.h"
+#include "gc_map.h"
+#include "mirror/art_method-inl.h"
+#include "mirror/class-inl.h"
+#include "mirror/object_array-inl.h"
+#include "mirror/object-inl.h"
+#include "jni.h"
+#include "scoped_thread_state_change.h"
+
+namespace art {
+
+#define REG(reg_bitmap, reg) \
+    (((reg) < m->GetCodeItem()->registers_size_) && \
+     ((*((reg_bitmap) + (reg)/8) >> ((reg) % 8) ) & 0x01))
+
+#define CHECK_REGS(...) if (!IsShadowFrame()) { \
+    int t[] = {__VA_ARGS__}; \
+    int t_size = sizeof(t) / sizeof(*t); \
+    for (int i = 0; i < t_size; ++i) \
+      CHECK(REG(reg_bitmap, t[i])) << "Error: Reg " << i << " is not in RegisterMap"; \
+  }
+
+static int gJava_StackWalk_refmap_calls = 0;
+
+struct TestReferenceMapVisitor : public StackVisitor {
+  explicit TestReferenceMapVisitor(Thread* thread)
+      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
+      : StackVisitor(thread, NULL) {
+  }
+
+  bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+    mirror::ArtMethod* m = GetMethod();
+    CHECK(m != NULL);
+    LOG(INFO) << "At " << PrettyMethod(m, false);
+
+    if (m->IsCalleeSaveMethod() || m->IsNative()) {
+      LOG(WARNING) << "no PC for " << PrettyMethod(m);
+      CHECK_EQ(GetDexPc(), DexFile::kDexNoIndex);
+      return true;
+    }
+    const uint8_t* reg_bitmap = NULL;
+    if (!IsShadowFrame()) {
+      NativePcOffsetToReferenceMap map(m->GetNativeGcMap());
+      reg_bitmap = map.FindBitMap(GetNativePcOffset());
+    }
+    StringPiece m_name(m->GetName());
+
+    // Given the method name and the number of times the method has been called,
+    // we know the Dex registers with live reference values. Assert that what we
+    // find is what is expected.
+    if (m_name == "f") {
+      if (gJava_StackWalk_refmap_calls == 1) {
+        CHECK_EQ(1U, GetDexPc());
+        CHECK_REGS(1);
+      } else {
+        CHECK_EQ(gJava_StackWalk_refmap_calls, 2);
+        CHECK_EQ(5U, GetDexPc());
+        CHECK_REGS(1);
+      }
+    } else if (m_name == "g") {
+      if (gJava_StackWalk_refmap_calls == 1) {
+        CHECK_EQ(0xcU, GetDexPc());
+        CHECK_REGS(0, 2);  // Note that v1 is not in the minimal root set
+      } else {
+        CHECK_EQ(gJava_StackWalk_refmap_calls, 2);
+        CHECK_EQ(0xcU, GetDexPc());
+        CHECK_REGS(0, 2);
+      }
+    } else if (m_name == "shlemiel") {
+      if (gJava_StackWalk_refmap_calls == 1) {
+        CHECK_EQ(0x380U, GetDexPc());
+        CHECK_REGS(2, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 25);
+      } else {
+        CHECK_EQ(gJava_StackWalk_refmap_calls, 2);
+        CHECK_EQ(0x380U, GetDexPc());
+        CHECK_REGS(2, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 25);
+      }
+    }
+
+    return true;
+  }
+};
+
+extern "C" JNIEXPORT jint JNICALL Java_Main_stackmap(JNIEnv*, jobject, jint count) {
+  ScopedObjectAccess soa(Thread::Current());
+  CHECK_EQ(count, 0);
+  gJava_StackWalk_refmap_calls++;
+
+  // Visitor
+  TestReferenceMapVisitor mapper(soa.Self());
+  mapper.WalkStack();
+
+  return count + 1;
+}
+
+extern "C" JNIEXPORT jint JNICALL Java_Main_refmap2(JNIEnv*, jobject, jint count) {
+  ScopedObjectAccess soa(Thread::Current());
+  gJava_StackWalk_refmap_calls++;
+
+  // Visitor
+  TestReferenceMapVisitor mapper(soa.Self());
+  mapper.WalkStack();
+
+  return count + 1;
+}
+
+}  // namespace art