OSDN Git Service

Add more checks to diagnose flaky oat file assistant test.
authorRichard Uhler <ruhler@google.com>
Mon, 20 Jul 2015 16:40:34 +0000 (09:40 -0700)
committerRichard Uhler <ruhler@google.com>
Mon, 20 Jul 2015 16:43:21 +0000 (09:43 -0700)
Bug: 22599792
Change-Id: I00574444133fb1cb2571f6ae71ac39c30a36275f

runtime/oat_file_assistant_test.cc

index adb6851..d133fa3 100644 (file)
@@ -446,6 +446,27 @@ TEST_F(OatFileAssistantTest, OatOutOfDate) {
   EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
 }
 
+// Some tests very occasionally fail: we expect to have an unrelocated non-pic
+// odex file that is reported as needing relocation, but it is reported
+// instead as being up to date (b/22599792).
+//
+// This function adds extra checks for diagnosing why the given oat file is
+// reported up to date, when it should be non-pic needing relocation.
+// These extra diagnostics checks should be removed once b/22599792 has been
+// resolved.
+static void DiagnoseFlakyTestFailure(const OatFile& oat_file) {
+  Runtime* runtime = Runtime::Current();
+  const gc::space::ImageSpace* image_space = runtime->GetHeap()->GetImageSpace();
+  ASSERT_TRUE(image_space != nullptr);
+  const ImageHeader& image_header = image_space->GetImageHeader();
+  const OatHeader& oat_header = oat_file.GetOatHeader();
+  EXPECT_FALSE(oat_file.IsPic());
+  EXPECT_EQ(image_header.GetOatChecksum(), oat_header.GetImageFileLocationOatChecksum());
+  EXPECT_NE(reinterpret_cast<uintptr_t>(image_header.GetOatDataBegin()),
+      oat_header.GetImageFileLocationOatDataBegin());
+  EXPECT_NE(image_header.GetPatchDelta(), oat_header.GetImagePatchDelta());
+}
+
 // Case: We have a DEX file and an ODEX file, but no OAT file.
 // Expect: The status is kPatchOatNeeded.
 TEST_F(OatFileAssistantTest, DexOdexNoOat) {
@@ -474,6 +495,8 @@ TEST_F(OatFileAssistantTest, DexOdexNoOat) {
   // We should still be able to get the non-executable odex file to run from.
   std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
   ASSERT_TRUE(oat_file.get() != nullptr);
+
+  DiagnoseFlakyTestFailure(*oat_file);
 }
 
 // Case: We have a stripped DEX file and an ODEX file, but no OAT file.
@@ -716,17 +739,7 @@ TEST_F(OatFileAssistantTest, OdexOatOverlap) {
   dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
   EXPECT_EQ(1u, dex_files.size());
 
-  // Add some extra checks to help diagnose apparently flaky test failures.
-  Runtime* runtime = Runtime::Current();
-  const gc::space::ImageSpace* image_space = runtime->GetHeap()->GetImageSpace();
-  ASSERT_TRUE(image_space != nullptr);
-  const ImageHeader& image_header = image_space->GetImageHeader();
-  const OatHeader& oat_header = oat_file->GetOatHeader();
-  EXPECT_FALSE(oat_file->IsPic());
-  EXPECT_EQ(image_header.GetOatChecksum(), oat_header.GetImageFileLocationOatChecksum());
-  EXPECT_NE(reinterpret_cast<uintptr_t>(image_header.GetOatDataBegin()),
-      oat_header.GetImageFileLocationOatDataBegin());
-  EXPECT_NE(image_header.GetPatchDelta(), oat_header.GetImagePatchDelta());
+  DiagnoseFlakyTestFailure(*oat_file);
 }
 
 // Case: We have a DEX file and a PIC ODEX file, but no OAT file.