OSDN Git Service

Fix falkiness in 117-nopatchoat
authorAlex Light <allight@google.com>
Sat, 19 Sep 2015 00:09:43 +0000 (17:09 -0700)
committerAlex Light <allight@google.com>
Wed, 23 Sep 2015 16:37:51 +0000 (09:37 -0700)
Previously if the image chose a relocation delta of 0 this test would
fail. Now we check for this state directly.

Bug: 24192015

Change-Id: Ie818701edc5605fed590547f0e8b1e97d1d994e3

test/117-nopatchoat/nopatchoat.cc
test/117-nopatchoat/run
test/117-nopatchoat/src/Main.java

index 7eac412..3e533ad 100644 (file)
 
 #include "class_linker.h"
 #include "dex_file-inl.h"
+#include "gc/heap.h"
+#include "gc/space/image_space.h"
 #include "mirror/class-inl.h"
+#include "runtime.h"
 #include "scoped_thread_state_change.h"
 #include "thread.h"
 
@@ -31,6 +34,11 @@ class NoPatchoatTest {
     return dex_file.GetOatDexFile();
   }
 
+  static bool isRelocationDeltaZero() {
+    gc::space::ImageSpace* space = Runtime::Current()->GetHeap()->GetImageSpace();
+    return space != nullptr && space->GetImageHeader().GetPatchDelta() == 0;
+  }
+
   static bool hasExecutableOat(jclass cls) {
     const OatFile::OatDexFile* oat_dex_file = getOatDexFile(cls);
 
@@ -49,6 +57,10 @@ class NoPatchoatTest {
   }
 };
 
+extern "C" JNIEXPORT jboolean JNICALL Java_Main_isRelocationDeltaZero(JNIEnv*, jclass) {
+  return NoPatchoatTest::isRelocationDeltaZero();
+}
+
 extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasExecutableOat(JNIEnv*, jclass cls) {
   return NoPatchoatTest::hasExecutableOat(cls);
 }
index c749c74..c634900 100755 (executable)
@@ -36,8 +36,6 @@ fi
 
 # Make sure we can run without relocation
 echo "Run without dex2oat/patchoat"
-# /bin/false is actually not even there for either, so the exec will fail.
-# Unfortunately there is no equivalent to /bin/false in android.
 ${RUN} ${flags} --runtime-option -Xnodex2oat
 
 # Make sure we can run with the oat file.
index 223e120..5cca309 100644 (file)
@@ -18,9 +18,13 @@ public class Main {
   public static void main(String[] args) {
     System.loadLibrary(args[0]);
 
+    // With a relocationDelta of 0, the runtime has no way to determine if the oat file in
+    // ANDROID_DATA has been relocated, since a non-relocated oat file always has a 0 delta.
+    // Hitting this condition should be rare and ideally we would prevent it from happening but
+    // there is no way to do so without major changes to the run-test framework.
     boolean executable_correct = (isPic() ?
-                                  hasExecutableOat() == true :
-                                  hasExecutableOat() == isDex2OatEnabled());
+        hasExecutableOat() == true :
+        hasExecutableOat() == (isDex2OatEnabled() || isRelocationDeltaZero()));
 
     System.out.println(
         "dex2oat & patchoat are " + ((isDex2OatEnabled()) ? "enabled" : "disabled") +
@@ -50,4 +54,6 @@ public class Main {
   private native static boolean hasOat();
 
   private native static boolean hasExecutableOat();
+
+  private native static boolean isRelocationDeltaZero();
 }