Fix falkiness in 117-nopatchoat
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
diff --git a/test/117-nopatchoat/nopatchoat.cc b/test/117-nopatchoat/nopatchoat.cc
index 7eac412..3e533ad 100644
--- a/test/117-nopatchoat/nopatchoat.cc
+++ b/test/117-nopatchoat/nopatchoat.cc
@@ -16,7 +16,10 @@
#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 @@
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 @@
}
};
+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);
}
diff --git a/test/117-nopatchoat/run b/test/117-nopatchoat/run
index c749c74..c634900 100755
--- a/test/117-nopatchoat/run
+++ b/test/117-nopatchoat/run
@@ -36,8 +36,6 @@
# 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.
diff --git a/test/117-nopatchoat/src/Main.java b/test/117-nopatchoat/src/Main.java
index 223e120..5cca309 100644
--- a/test/117-nopatchoat/src/Main.java
+++ b/test/117-nopatchoat/src/Main.java
@@ -18,9 +18,13 @@
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 @@
private native static boolean hasOat();
private native static boolean hasExecutableOat();
+
+ private native static boolean isRelocationDeltaZero();
}