OSDN Git Service

Test that we can unwind framework code.
authorDavid Srbecky <dsrbecky@google.com>
Mon, 8 Jun 2015 22:41:25 +0000 (23:41 +0100)
committerDavid Srbecky <dsrbecky@google.com>
Tue, 9 Jun 2015 18:51:59 +0000 (19:51 +0100)
Change-Id: I8c0c6c14f3b95ac1fea6ca6a969a1baea80d55fc

test/137-cfi/cfi.cc
test/137-cfi/src/Main.java

index b2d7e55..f451bcb 100644 (file)
@@ -94,6 +94,7 @@ extern "C" JNIEXPORT jboolean JNICALL Java_Main_unwindInProcess(JNIEnv*, jobject
   std::vector<std::string> seq = {
       "Java_Main_unwindInProcess",                   // This function.
       "boolean Main.unwindInProcess(int, boolean)",  // The corresponding Java native method frame.
+      "int java.util.Arrays.binarySearch(java.lang.Object[], int, int, java.lang.Object, java.util.Comparator)",  // Framework method.
       "void Main.main(java.lang.String[])"           // The Java entry method.
   };
 
@@ -185,6 +186,7 @@ extern "C" JNIEXPORT jboolean JNICALL Java_Main_unwindOtherProcess(JNIEnv*, jobj
                                                      // Note: For some reason, the name isn't
                                                      // resolved, so don't look for it right now.
         "boolean Main.sleep(int, boolean, double)",  // The corresponding Java native method frame.
+        "int java.util.Arrays.binarySearch(java.lang.Object[], int, int, java.lang.Object, java.util.Comparator)",  // Framework method.
         "void Main.main(java.lang.String[])"         // The Java entry method.
     };
 
index e184e66..658ba53 100644 (file)
@@ -20,8 +20,10 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Comparator;
 
-public class Main {
+public class Main implements Comparator<Main> {
   // Whether to test local unwinding. Libunwind uses linker info to find executables. As we do
   // not dlopen at the moment, this doesn't work, so keep it off for now.
   public final static boolean TEST_LOCAL_UNWINDING = false;
@@ -32,6 +34,8 @@ public class Main {
 
   private boolean secondary;
 
+  private boolean passed;
+
   public Main(boolean secondary) {
       this.secondary = secondary;
   }
@@ -60,13 +64,13 @@ public class Main {
   }
 
   private void runSecondary() {
-      foo(true);
+      foo();
       throw new RuntimeException("Didn't expect to get back...");
   }
 
   private void runPrimary() {
       // First do the in-process unwinding.
-      if (TEST_LOCAL_UNWINDING && !foo(false)) {
+      if (TEST_LOCAL_UNWINDING && !foo()) {
           System.out.println("Unwinding self failed.");
       }
 
@@ -134,8 +138,19 @@ public class Main {
       }
   }
 
-  public boolean foo(boolean b) {
-      return bar(b);
+  public boolean foo() {
+      // Call bar via Arrays.binarySearch.
+      // This tests that we can unwind from framework code.
+      Main[] array = { this, this, this };
+      Arrays.binarySearch(array, 0, 3, this /* value */, this /* comparator */);
+      return passed;
+  }
+
+  public int compare(Main lhs, Main rhs) {
+      passed = bar(secondary);
+      // Returning "equal" ensures that we terminate search
+      // after first item and thus call bar() only once.
+      return 0;
   }
 
   public boolean bar(boolean b) {