Test case for clinit support in app image

Add a new test case to test how class initializers are executed in
different situations. Currently clinit for app image is not supported.

Test: make test-art-host -j64
Change-Id: I5218a57c14eae29299762da3f610d163a16b0b68
diff --git a/test/660-clinit/expected.txt b/test/660-clinit/expected.txt
new file mode 100644
index 0000000..e103a2c
--- /dev/null
+++ b/test/660-clinit/expected.txt
@@ -0,0 +1,9 @@
+JNI_OnLoad called
+X: 4950
+Y: 5730
+str: Hello World!
+ooo: OoooooO
+Z: 11206655
+A: 100
+AA: 100
+a != 101
diff --git a/test/660-clinit/info.txt b/test/660-clinit/info.txt
new file mode 100644
index 0000000..da0193d
--- /dev/null
+++ b/test/660-clinit/info.txt
@@ -0,0 +1 @@
+Tests that class initializers are executed correctly.
diff --git a/test/660-clinit/src/Main.java b/test/660-clinit/src/Main.java
new file mode 100644
index 0000000..f547692
--- /dev/null
+++ b/test/660-clinit/src/Main.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2017 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.
+ */
+
+import java.util.*;
+
+public class Main {
+
+  public static void main(String[] args) throws Exception {
+    System.loadLibrary(args[0]);
+
+    if (!checkAppImageLoaded()) {
+      System.out.println("AppImage not loaded.");
+    }
+
+    expectNotPreInit(Day.class);
+    expectNotPreInit(ClInit.class);
+
+    ClInit c = new ClInit();
+    int aa = c.a;
+
+    System.out.println("X: " + c.getX());
+    System.out.println("Y: " + c.getY());
+    System.out.println("str: " + c.str);
+    System.out.println("ooo: " + c.ooo);
+    System.out.println("Z: " + c.getZ());
+    System.out.println("A: " + c.getA());
+    System.out.println("AA: " + aa);
+
+    if (c.a != 101) {
+      System.out.println("a != 101");
+    }
+
+    return;
+  }
+
+  static void expectPreInit(Class<?> klass) {
+    if (checkInitialized(klass) == false) {
+      System.out.println(klass.getName() + " should be initialized!");
+    }
+  }
+
+  static void expectNotPreInit(Class<?> klass) {
+    if (checkInitialized(klass) == true) {
+      System.out.println(klass.getName() + " should not be initialized!");
+    }
+  }
+
+  public static native boolean checkAppImageLoaded();
+  public static native boolean checkAppImageContains(Class<?> klass);
+  public static native boolean checkInitialized(Class<?> klass);
+}
+
+enum Day {
+    SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
+    THURSDAY, FRIDAY, SATURDAY
+}
+
+class ClInit {
+
+  static String ooo = "OoooooO";
+  static String str;
+  static int z;
+  static int x, y;
+  public static volatile int a = 100;
+
+  static {
+    StringBuilder sb = new StringBuilder();
+    sb.append("Hello ");
+    sb.append("World!");
+    str = sb.toString();
+
+    z = 0xFF;
+    z += 0xFF00;
+    z += 0xAA0000;
+
+    for(int i = 0; i < 100; i++) {
+      x += i;
+    }
+
+    y = x;
+    for(int i = 0; i < 40; i++) {
+      y += i;
+    }
+  }
+
+  int getX() {
+    return x;
+  }
+
+  int getZ() {
+    return z;
+  }
+
+  int getY() {
+    return y;
+  }
+
+  int getA() {
+    return a;
+  }
+}
+