blob: 4a0de59a20408054aa74b37f9dcbddf229e47e65 [file] [log] [blame]
Richard Uhler66d874d2015-01-15 09:37:19 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "oat_file_assistant.h"
18
19#include <algorithm>
20#include <fstream>
21#include <string>
22#include <vector>
23#include <sys/param.h>
24
25#include <backtrace/BacktraceMap.h>
26#include <gtest/gtest.h>
27
Mathieu Chartierc7853442015-03-27 14:35:38 -070028#include "art_field-inl.h"
Igor Murashkinbc1d78d2015-07-30 16:39:45 -070029#include "base/out.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010030#include "class_linker-inl.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080031#include "common_runtime_test.h"
Andreas Gampebb9c6b12015-03-29 13:56:36 -070032#include "compiler_callbacks.h"
Richard Uhlerf16d5722015-05-11 09:32:47 -070033#include "gc/space/image_space.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080034#include "mem_map.h"
35#include "os.h"
Richard Uhler23cedd22015-04-08 13:17:29 -070036#include "scoped_thread_state_change.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080037#include "thread-inl.h"
38#include "utils.h"
39
40namespace art {
41
Richard Uhler94f5bda2015-07-22 08:25:11 -070042// Some tests very occasionally fail: we expect to have an unrelocated non-pic
43// odex file that is reported as needing relocation, but it is reported
44// instead as being up to date (b/22599792).
45//
46// This function adds extra checks for diagnosing why the given oat file is
47// reported up to date, when it should be non-pic needing relocation.
48// These extra diagnostics checks should be removed once b/22599792 has been
49// resolved.
50static void DiagnoseFlakyTestFailure(const OatFile& oat_file) {
51 Runtime* runtime = Runtime::Current();
52 const gc::space::ImageSpace* image_space = runtime->GetHeap()->GetImageSpace();
53 ASSERT_TRUE(image_space != nullptr);
54 const ImageHeader& image_header = image_space->GetImageHeader();
55 const OatHeader& oat_header = oat_file.GetOatHeader();
56 EXPECT_FALSE(oat_file.IsPic());
57 EXPECT_EQ(image_header.GetOatChecksum(), oat_header.GetImageFileLocationOatChecksum());
58 EXPECT_NE(reinterpret_cast<uintptr_t>(image_header.GetOatDataBegin()),
59 oat_header.GetImageFileLocationOatDataBegin());
60 EXPECT_NE(image_header.GetPatchDelta(), oat_header.GetImagePatchDelta());
61}
62
63
Richard Uhler66d874d2015-01-15 09:37:19 -080064class OatFileAssistantTest : public CommonRuntimeTest {
65 public:
66 virtual void SetUp() {
67 ReserveImageSpace();
68 CommonRuntimeTest::SetUp();
69
70 // Create a scratch directory to work from.
71 scratch_dir_ = android_data_ + "/OatFileAssistantTest";
72 ASSERT_EQ(0, mkdir(scratch_dir_.c_str(), 0700));
73
Richard Uhler63434112015-03-16 14:32:16 -070074 // Create a subdirectory in scratch for odex files.
75 odex_oat_dir_ = scratch_dir_ + "/oat";
76 ASSERT_EQ(0, mkdir(odex_oat_dir_.c_str(), 0700));
77
78 odex_dir_ = odex_oat_dir_ + "/" + std::string(GetInstructionSetString(kRuntimeISA));
79 ASSERT_EQ(0, mkdir(odex_dir_.c_str(), 0700));
80
Richard Uhler66d874d2015-01-15 09:37:19 -080081
82 // Verify the environment is as we expect
83 uint32_t checksum;
84 std::string error_msg;
85 ASSERT_TRUE(OS::FileExists(GetImageFile().c_str()))
86 << "Expected pre-compiled boot image to be at: " << GetImageFile();
87 ASSERT_TRUE(OS::FileExists(GetDexSrc1().c_str()))
88 << "Expected dex file to be at: " << GetDexSrc1();
89 ASSERT_TRUE(OS::FileExists(GetStrippedDexSrc1().c_str()))
90 << "Expected stripped dex file to be at: " << GetStrippedDexSrc1();
Igor Murashkina315f5c2015-07-31 17:35:52 -070091 ASSERT_FALSE(DexFile::GetChecksum(GetStrippedDexSrc1().c_str(), &checksum, outof(error_msg)))
Richard Uhler66d874d2015-01-15 09:37:19 -080092 << "Expected stripped dex file to be stripped: " << GetStrippedDexSrc1();
Richard Uhler66d874d2015-01-15 09:37:19 -080093 ASSERT_TRUE(OS::FileExists(GetDexSrc2().c_str()))
94 << "Expected dex file to be at: " << GetDexSrc2();
Richard Uhler67ff7d12015-05-14 13:21:13 -070095
96 // GetMultiDexSrc2 should have the same primary dex checksum as
97 // GetMultiDexSrc1, but a different secondary dex checksum.
98 std::vector<std::unique_ptr<const DexFile>> multi1;
99 ASSERT_TRUE(DexFile::Open(GetMultiDexSrc1().c_str(),
Igor Murashkina315f5c2015-07-31 17:35:52 -0700100 GetMultiDexSrc1().c_str(), outof(error_msg), &multi1)) << error_msg;
Richard Uhler67ff7d12015-05-14 13:21:13 -0700101 ASSERT_GT(multi1.size(), 1u);
102
103 std::vector<std::unique_ptr<const DexFile>> multi2;
104 ASSERT_TRUE(DexFile::Open(GetMultiDexSrc2().c_str(),
Igor Murashkina315f5c2015-07-31 17:35:52 -0700105 GetMultiDexSrc2().c_str(), outof(error_msg), &multi2)) << error_msg;
Richard Uhler67ff7d12015-05-14 13:21:13 -0700106 ASSERT_GT(multi2.size(), 1u);
107
108 ASSERT_EQ(multi1[0]->GetLocationChecksum(), multi2[0]->GetLocationChecksum());
109 ASSERT_NE(multi1[1]->GetLocationChecksum(), multi2[1]->GetLocationChecksum());
Richard Uhler66d874d2015-01-15 09:37:19 -0800110 }
111
112 virtual void SetUpRuntimeOptions(RuntimeOptions* options) {
Richard Uhler892fc962015-03-10 16:57:05 +0000113 // options->push_back(std::make_pair("-verbose:oat", nullptr));
Richard Uhler66d874d2015-01-15 09:37:19 -0800114
115 // Set up the image location.
116 options->push_back(std::make_pair("-Ximage:" + GetImageLocation(),
117 nullptr));
118 // Make sure compilercallbacks are not set so that relocation will be
119 // enabled.
Andreas Gampebb9c6b12015-03-29 13:56:36 -0700120 callbacks_.reset();
Richard Uhler66d874d2015-01-15 09:37:19 -0800121 }
122
123 virtual void PreRuntimeCreate() {
124 UnreserveImageSpace();
125 }
126
127 virtual void PostRuntimeCreate() {
128 ReserveImageSpace();
129 }
130
131 virtual void TearDown() {
Richard Uhler63434112015-03-16 14:32:16 -0700132 ClearDirectory(odex_dir_.c_str());
133 ASSERT_EQ(0, rmdir(odex_dir_.c_str()));
134
135 ClearDirectory(odex_oat_dir_.c_str());
136 ASSERT_EQ(0, rmdir(odex_oat_dir_.c_str()));
Richard Uhler66d874d2015-01-15 09:37:19 -0800137
138 ClearDirectory(scratch_dir_.c_str());
139 ASSERT_EQ(0, rmdir(scratch_dir_.c_str()));
140
141 CommonRuntimeTest::TearDown();
142 }
143
144 void Copy(std::string src, std::string dst) {
145 std::ifstream src_stream(src, std::ios::binary);
146 std::ofstream dst_stream(dst, std::ios::binary);
147
148 dst_stream << src_stream.rdbuf();
149 }
150
151 // Returns the directory where the pre-compiled core.art can be found.
152 // TODO: We should factor out this into common tests somewhere rather than
153 // re-hardcoding it here (This was copied originally from the elf writer
154 // test).
155 std::string GetImageDirectory() {
156 if (IsHost()) {
157 const char* host_dir = getenv("ANDROID_HOST_OUT");
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700158 CHECK(host_dir != nullptr);
Richard Uhler66d874d2015-01-15 09:37:19 -0800159 return std::string(host_dir) + "/framework";
160 } else {
161 return std::string("/data/art-test");
162 }
163 }
164
165 std::string GetImageLocation() {
166 return GetImageDirectory() + "/core.art";
167 }
168
169 std::string GetImageFile() {
170 return GetImageDirectory() + "/" + GetInstructionSetString(kRuntimeISA)
171 + "/core.art";
172 }
173
174 std::string GetDexSrc1() {
175 return GetTestDexFileName("Main");
176 }
177
178 // Returns the path to a dex file equivalent to GetDexSrc1, but with the dex
179 // file stripped.
180 std::string GetStrippedDexSrc1() {
181 return GetTestDexFileName("MainStripped");
182 }
183
184 std::string GetMultiDexSrc1() {
185 return GetTestDexFileName("MultiDex");
186 }
187
Richard Uhler67ff7d12015-05-14 13:21:13 -0700188 // Returns the path to a multidex file equivalent to GetMultiDexSrc2, but
189 // with the contents of the secondary dex file changed.
190 std::string GetMultiDexSrc2() {
191 return GetTestDexFileName("MultiDexModifiedSecondary");
192 }
193
Richard Uhler66d874d2015-01-15 09:37:19 -0800194 std::string GetDexSrc2() {
195 return GetTestDexFileName("Nested");
196 }
197
198 // Scratch directory, for dex and odex files (oat files will go in the
199 // dalvik cache).
200 std::string GetScratchDir() {
201 return scratch_dir_;
202 }
203
Richard Uhler63434112015-03-16 14:32:16 -0700204 // Odex directory is the subdirectory in the scratch directory where odex
Richard Uhler66d874d2015-01-15 09:37:19 -0800205 // files should be located.
Richard Uhler63434112015-03-16 14:32:16 -0700206 std::string GetOdexDir() {
207 return odex_dir_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800208 }
209
210 // Generate an odex file for the purposes of test.
211 // If pic is true, generates a PIC odex.
Richard Uhler94f5bda2015-07-22 08:25:11 -0700212 // The generated odex file will be un-relocated.
Richard Uhler66d874d2015-01-15 09:37:19 -0800213 void GenerateOdexForTest(const std::string& dex_location,
214 const std::string& odex_location,
215 bool pic = false) {
216 // For this operation, we temporarily redirect the dalvik cache so dex2oat
217 // doesn't find the relocated image file.
218 std::string android_data_tmp = GetScratchDir() + "AndroidDataTmp";
219 setenv("ANDROID_DATA", android_data_tmp.c_str(), 1);
220 std::vector<std::string> args;
221 args.push_back("--dex-file=" + dex_location);
222 args.push_back("--oat-file=" + odex_location);
223 if (pic) {
224 args.push_back("--compile-pic");
225 } else {
226 args.push_back("--include-patch-information");
Richard Uhler05dd8a62015-03-10 10:02:23 -0700227
228 // We need to use the quick compiler to generate non-PIC code, because
229 // the optimizing compiler always generates PIC.
230 args.push_back("--compiler-backend=Quick");
Richard Uhler66d874d2015-01-15 09:37:19 -0800231 }
232 args.push_back("--runtime-arg");
233 args.push_back("-Xnorelocate");
234 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700235 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, outof(error_msg))) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800236 setenv("ANDROID_DATA", android_data_.c_str(), 1);
Richard Uhler94f5bda2015-07-22 08:25:11 -0700237
238 // Verify the odex file was generated as expected.
239 std::unique_ptr<OatFile> odex_file(OatFile::Open(
240 odex_location.c_str(), odex_location.c_str(), nullptr, nullptr,
Igor Murashkina315f5c2015-07-31 17:35:52 -0700241 false, dex_location.c_str(), outof(error_msg)));
Richard Uhler94f5bda2015-07-22 08:25:11 -0700242 ASSERT_TRUE(odex_file.get() != nullptr) << error_msg;
243
244 if (!pic) {
245 DiagnoseFlakyTestFailure(*odex_file);
246 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800247 }
248
249 void GeneratePicOdexForTest(const std::string& dex_location,
250 const std::string& odex_location) {
251 GenerateOdexForTest(dex_location, odex_location, true);
252 }
253
254 private:
255 // Reserve memory around where the image will be loaded so other memory
256 // won't conflict when it comes time to load the image.
257 // This can be called with an already loaded image to reserve the space
258 // around it.
259 void ReserveImageSpace() {
260 MemMap::Init();
261
262 // Ensure a chunk of memory is reserved for the image space.
263 uintptr_t reservation_start = ART_BASE_ADDRESS + ART_BASE_ADDRESS_MIN_DELTA;
264 uintptr_t reservation_end = ART_BASE_ADDRESS + ART_BASE_ADDRESS_MAX_DELTA
Hiroshi Yamauchi3dbf2342015-03-17 16:01:11 -0700265 // Include the main space that has to come right after the
266 // image in case of the GSS collector.
267 + 384 * MB;
Richard Uhler66d874d2015-01-15 09:37:19 -0800268
Richard Uhler66d874d2015-01-15 09:37:19 -0800269 std::unique_ptr<BacktraceMap> map(BacktraceMap::Create(getpid(), true));
270 ASSERT_TRUE(map.get() != nullptr) << "Failed to build process map";
271 for (BacktraceMap::const_iterator it = map->begin();
272 reservation_start < reservation_end && it != map->end(); ++it) {
Richard Uhler3efe9792015-03-30 16:18:03 -0700273 ReserveImageSpaceChunk(reservation_start, std::min(it->start, reservation_end));
274 reservation_start = std::max(reservation_start, it->end);
275 }
276 ReserveImageSpaceChunk(reservation_start, reservation_end);
277 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800278
Richard Uhler3efe9792015-03-30 16:18:03 -0700279 // Reserve a chunk of memory for the image space in the given range.
280 // Only has effect for chunks with a positive number of bytes.
281 void ReserveImageSpaceChunk(uintptr_t start, uintptr_t end) {
282 if (start < end) {
283 std::string error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800284 image_reservation_.push_back(std::unique_ptr<MemMap>(
285 MemMap::MapAnonymous("image reservation",
Richard Uhler3efe9792015-03-30 16:18:03 -0700286 reinterpret_cast<uint8_t*>(start), end - start,
Igor Murashkina315f5c2015-07-31 17:35:52 -0700287 PROT_NONE, false, false, outof(error_msg))));
Richard Uhler66d874d2015-01-15 09:37:19 -0800288 ASSERT_TRUE(image_reservation_.back().get() != nullptr) << error_msg;
289 LOG(INFO) << "Reserved space for image " <<
290 reinterpret_cast<void*>(image_reservation_.back()->Begin()) << "-" <<
291 reinterpret_cast<void*>(image_reservation_.back()->End());
Richard Uhler66d874d2015-01-15 09:37:19 -0800292 }
293 }
294
295
296 // Unreserve any memory reserved by ReserveImageSpace. This should be called
297 // before the image is loaded.
298 void UnreserveImageSpace() {
299 image_reservation_.clear();
300 }
301
302 std::string scratch_dir_;
Richard Uhler63434112015-03-16 14:32:16 -0700303 std::string odex_oat_dir_;
304 std::string odex_dir_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800305 std::vector<std::unique_ptr<MemMap>> image_reservation_;
306};
307
308class OatFileAssistantNoDex2OatTest : public OatFileAssistantTest {
309 public:
310 virtual void SetUpRuntimeOptions(RuntimeOptions* options) {
311 OatFileAssistantTest::SetUpRuntimeOptions(options);
312 options->push_back(std::make_pair("-Xnodex2oat", nullptr));
313 }
314};
315
316// Generate an oat file for the purposes of test, as opposed to testing
317// generation of oat files.
318static void GenerateOatForTest(const char* dex_location) {
319 OatFileAssistant oat_file_assistant(dex_location, kRuntimeISA, false);
320
321 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700322 ASSERT_TRUE(oat_file_assistant.GenerateOatFile(outof(error_msg))) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800323}
324
325// Case: We have a DEX file, but no OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700326// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800327TEST_F(OatFileAssistantTest, DexNoOat) {
328 std::string dex_location = GetScratchDir() + "/DexNoOat.jar";
329 Copy(GetDexSrc1(), dex_location);
330
331 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
332
Richard Uhler95abd042015-03-24 09:51:28 -0700333 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800334
335 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
336 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
337 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
338 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
339 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700340 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OdexFileStatus());
Richard Uhler66d874d2015-01-15 09:37:19 -0800341 EXPECT_FALSE(oat_file_assistant.OatFileExists());
342 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
343 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
344 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700345 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OatFileStatus());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700346 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800347}
348
349// Case: We have no DEX file and no OAT file.
Richard Uhler9b994ea2015-06-24 08:44:19 -0700350// Expect: Status is kNoDexOptNeeded. Loading should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800351TEST_F(OatFileAssistantTest, NoDexNoOat) {
352 std::string dex_location = GetScratchDir() + "/NoDexNoOat.jar";
353
354 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
355
Richard Uhler9b994ea2015-06-24 08:44:19 -0700356 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
357 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
358
359 // Trying to make the oat file up to date should not fail or crash.
360 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700361 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(outof(error_msg)));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700362
363 // Trying to get the best oat file should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800364 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
365 EXPECT_EQ(nullptr, oat_file.get());
366}
367
368// Case: We have a DEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700369// Expect: The status is kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800370TEST_F(OatFileAssistantTest, OatUpToDate) {
371 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
372 Copy(GetDexSrc1(), dex_location);
373 GenerateOatForTest(dex_location.c_str());
374
375 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
376
Richard Uhler95abd042015-03-24 09:51:28 -0700377 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800378 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
379 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
380 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
381 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
382 EXPECT_TRUE(oat_file_assistant.OatFileExists());
383 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
384 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
385 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700386 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700387 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800388}
389
390// Case: We have a MultiDEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700391// Expect: The status is kNoDexOptNeeded and we load all dex files.
Richard Uhler66d874d2015-01-15 09:37:19 -0800392TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) {
393 std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar";
394 Copy(GetMultiDexSrc1(), dex_location);
395 GenerateOatForTest(dex_location.c_str());
396
Richard Uhlere5fed032015-03-18 08:21:11 -0700397 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler95abd042015-03-24 09:51:28 -0700398 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700399 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700400
401 // Verify we can load both dex files.
Richard Uhlere5fed032015-03-18 08:21:11 -0700402 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
Richard Uhler66d874d2015-01-15 09:37:19 -0800403 ASSERT_TRUE(oat_file.get() != nullptr);
404 EXPECT_TRUE(oat_file->IsExecutable());
405 std::vector<std::unique_ptr<const DexFile>> dex_files;
Richard Uhlere5fed032015-03-18 08:21:11 -0700406 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
407 EXPECT_EQ(2u, dex_files.size());
408}
409
Richard Uhler67ff7d12015-05-14 13:21:13 -0700410// Case: We have a MultiDEX file where the secondary dex file is out of date.
411// Expect: The status is kDex2OatNeeded.
412TEST_F(OatFileAssistantTest, MultiDexSecondaryOutOfDate) {
413 std::string dex_location = GetScratchDir() + "/MultiDexSecondaryOutOfDate.jar";
414
415 // Compile code for GetMultiDexSrc1.
416 Copy(GetMultiDexSrc1(), dex_location);
417 GenerateOatForTest(dex_location.c_str());
418
419 // Now overwrite the dex file with GetMultiDexSrc2 so the secondary checksum
420 // is out of date.
421 Copy(GetMultiDexSrc2(), dex_location);
422
423 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
424 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700425 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler67ff7d12015-05-14 13:21:13 -0700426}
427
Richard Uhlere5fed032015-03-18 08:21:11 -0700428// Case: We have a MultiDEX file and up-to-date OAT file for it with relative
429// encoded dex locations.
Richard Uhler95abd042015-03-24 09:51:28 -0700430// Expect: The oat file status is kNoDexOptNeeded.
Richard Uhlere5fed032015-03-18 08:21:11 -0700431TEST_F(OatFileAssistantTest, RelativeEncodedDexLocation) {
432 std::string dex_location = GetScratchDir() + "/RelativeEncodedDexLocation.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700433 std::string oat_location = GetOdexDir() + "/RelativeEncodedDexLocation.oat";
Richard Uhlere5fed032015-03-18 08:21:11 -0700434
435 // Create the dex file
436 Copy(GetMultiDexSrc1(), dex_location);
437
438 // Create the oat file with relative encoded dex location.
439 std::vector<std::string> args;
440 args.push_back("--dex-file=" + dex_location);
441 args.push_back("--dex-location=" + std::string("RelativeEncodedDexLocation.jar"));
442 args.push_back("--oat-file=" + oat_location);
443
444 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700445 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, outof(error_msg))) << error_msg;
Richard Uhlere5fed032015-03-18 08:21:11 -0700446
447 // Verify we can load both dex files.
448 OatFileAssistant oat_file_assistant(dex_location.c_str(),
449 oat_location.c_str(),
450 kRuntimeISA, true);
451 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
452 ASSERT_TRUE(oat_file.get() != nullptr);
453 EXPECT_TRUE(oat_file->IsExecutable());
454 std::vector<std::unique_ptr<const DexFile>> dex_files;
455 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
Richard Uhler66d874d2015-01-15 09:37:19 -0800456 EXPECT_EQ(2u, dex_files.size());
457}
458
Richard Uhler95abd042015-03-24 09:51:28 -0700459// Case: We have a DEX file and out-of-date OAT file.
460// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800461TEST_F(OatFileAssistantTest, OatOutOfDate) {
462 std::string dex_location = GetScratchDir() + "/OatOutOfDate.jar";
463
464 // We create a dex, generate an oat for it, then overwrite the dex with a
465 // different dex to make the oat out of date.
466 Copy(GetDexSrc1(), dex_location);
467 GenerateOatForTest(dex_location.c_str());
468 Copy(GetDexSrc2(), dex_location);
469
470 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler95abd042015-03-24 09:51:28 -0700471 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800472
473 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
474 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
475 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
476 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
477 EXPECT_TRUE(oat_file_assistant.OatFileExists());
478 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
479 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700480 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800481}
482
483// Case: We have a DEX file and an ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700484// Expect: The status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800485TEST_F(OatFileAssistantTest, DexOdexNoOat) {
486 std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700487 std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800488
489 // Create the dex and odex files
490 Copy(GetDexSrc1(), dex_location);
491 GenerateOdexForTest(dex_location, odex_location);
492
493 // Verify the status.
494 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
495
Richard Uhler95abd042015-03-24 09:51:28 -0700496 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800497
498 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
499 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
500 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
501 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
502 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
Richard Uhler66d874d2015-01-15 09:37:19 -0800503 EXPECT_FALSE(oat_file_assistant.OatFileExists());
504 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
505 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700506 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler5f946da2015-07-17 12:28:32 -0700507
508 // We should still be able to get the non-executable odex file to run from.
509 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
510 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhler2639e8e2015-07-20 09:40:34 -0700511
512 DiagnoseFlakyTestFailure(*oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -0800513}
514
515// Case: We have a stripped DEX file and an ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700516// Expect: The status is kPatchOatNeeded
Richard Uhler66d874d2015-01-15 09:37:19 -0800517TEST_F(OatFileAssistantTest, StrippedDexOdexNoOat) {
518 std::string dex_location = GetScratchDir() + "/StrippedDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700519 std::string odex_location = GetOdexDir() + "/StrippedDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800520
521 // Create the dex and odex files
522 Copy(GetDexSrc1(), dex_location);
523 GenerateOdexForTest(dex_location, odex_location);
524
525 // Strip the dex file
526 Copy(GetStrippedDexSrc1(), dex_location);
527
528 // Verify the status.
529 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
530
Richard Uhler95abd042015-03-24 09:51:28 -0700531 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800532
533 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
534 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
535 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
536 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
537 EXPECT_FALSE(oat_file_assistant.OatFileExists());
538 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
539 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700540 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800541
542 // Make the oat file up to date.
543 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700544 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(outof(error_msg))) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800545
Richard Uhler95abd042015-03-24 09:51:28 -0700546 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800547
548 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
549 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
550 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
551 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
552 EXPECT_TRUE(oat_file_assistant.OatFileExists());
553 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
554 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700555 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800556
557 // Verify we can load the dex files from it.
558 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
559 ASSERT_TRUE(oat_file.get() != nullptr);
560 EXPECT_TRUE(oat_file->IsExecutable());
561 std::vector<std::unique_ptr<const DexFile>> dex_files;
562 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
563 EXPECT_EQ(1u, dex_files.size());
564}
565
Richard Uhler95abd042015-03-24 09:51:28 -0700566// Case: We have a stripped DEX file, an ODEX file, and an out-of-date OAT file.
567// Expect: The status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800568TEST_F(OatFileAssistantTest, StrippedDexOdexOat) {
569 std::string dex_location = GetScratchDir() + "/StrippedDexOdexOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700570 std::string odex_location = GetOdexDir() + "/StrippedDexOdexOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800571
572 // Create the oat file from a different dex file so it looks out of date.
573 Copy(GetDexSrc2(), dex_location);
574 GenerateOatForTest(dex_location.c_str());
575
576 // Create the odex file
577 Copy(GetDexSrc1(), dex_location);
578 GenerateOdexForTest(dex_location, odex_location);
579
580 // Strip the dex file.
581 Copy(GetStrippedDexSrc1(), dex_location);
582
583 // Verify the status.
584 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
585
Richard Uhler95abd042015-03-24 09:51:28 -0700586 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800587
588 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
589 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
590 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
591 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
592 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
593 EXPECT_TRUE(oat_file_assistant.OatFileExists());
594 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
595 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700596 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800597
598 // Make the oat file up to date.
599 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700600 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(outof(error_msg))) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800601
Richard Uhler95abd042015-03-24 09:51:28 -0700602 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800603
604 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
605 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
606 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
607 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
608 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
609 EXPECT_TRUE(oat_file_assistant.OatFileExists());
610 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
611 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
612 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700613 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800614
615 // Verify we can load the dex files from it.
616 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
617 ASSERT_TRUE(oat_file.get() != nullptr);
618 EXPECT_TRUE(oat_file->IsExecutable());
619 std::vector<std::unique_ptr<const DexFile>> dex_files;
620 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
621 EXPECT_EQ(1u, dex_files.size());
622}
623
Richard Uhler9b994ea2015-06-24 08:44:19 -0700624// Case: We have a stripped (or resource-only) DEX file, no ODEX file and no
625// OAT file. Expect: The status is kNoDexOptNeeded.
626TEST_F(OatFileAssistantTest, ResourceOnlyDex) {
627 std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar";
628
629 Copy(GetStrippedDexSrc1(), dex_location);
630
631 // Verify the status.
632 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
633
634 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
635
636 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
637 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
638 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
639 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
640 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
641 EXPECT_FALSE(oat_file_assistant.OatFileExists());
642 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
643 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
644 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
645
646 // Make the oat file up to date. This should have no effect.
647 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700648 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(outof(error_msg))) << error_msg;
Richard Uhler9b994ea2015-06-24 08:44:19 -0700649
650 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
651
652 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
653 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
654 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
655 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
656 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
657 EXPECT_FALSE(oat_file_assistant.OatFileExists());
658 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
659 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
660 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
661}
662
Richard Uhler95abd042015-03-24 09:51:28 -0700663// Case: We have a DEX file, no ODEX file and an OAT file that needs
664// relocation.
665// Expect: The status is kSelfPatchOatNeeded.
666TEST_F(OatFileAssistantTest, SelfRelocation) {
667 std::string dex_location = GetScratchDir() + "/SelfRelocation.jar";
668 std::string oat_location = GetOdexDir() + "/SelfRelocation.oat";
669
670 // Create the dex and odex files
671 Copy(GetDexSrc1(), dex_location);
672 GenerateOdexForTest(dex_location, oat_location);
673
674 OatFileAssistant oat_file_assistant(dex_location.c_str(),
675 oat_location.c_str(), kRuntimeISA, true);
676
677 EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
678
679 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
680 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
681 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
682 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
683 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
684 EXPECT_TRUE(oat_file_assistant.OatFileExists());
685 EXPECT_TRUE(oat_file_assistant.OatFileNeedsRelocation());
686 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
687 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700688 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700689
690 // Make the oat file up to date.
691 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700692 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(outof(error_msg))) << error_msg;
Richard Uhler95abd042015-03-24 09:51:28 -0700693
694 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
695
696 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
697 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
698 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
699 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
700 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
701 EXPECT_TRUE(oat_file_assistant.OatFileExists());
702 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
703 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
704 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700705 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700706
707 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
708 ASSERT_TRUE(oat_file.get() != nullptr);
709 EXPECT_TRUE(oat_file->IsExecutable());
710 std::vector<std::unique_ptr<const DexFile>> dex_files;
711 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
712 EXPECT_EQ(1u, dex_files.size());
713}
714
Richard Uhler66d874d2015-01-15 09:37:19 -0800715// Case: We have a DEX file, an ODEX file and an OAT file, where the ODEX and
716// OAT files both have patch delta of 0.
Richard Uhler95abd042015-03-24 09:51:28 -0700717// Expect: It shouldn't crash, and status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800718TEST_F(OatFileAssistantTest, OdexOatOverlap) {
719 std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700720 std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex";
721 std::string oat_location = GetOdexDir() + "/OdexOatOverlap.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -0800722
723 // Create the dex and odex files
724 Copy(GetDexSrc1(), dex_location);
725 GenerateOdexForTest(dex_location, odex_location);
726
727 // Create the oat file by copying the odex so they are located in the same
728 // place in memory.
729 Copy(odex_location, oat_location);
730
731 // Verify things don't go bad.
732 OatFileAssistant oat_file_assistant(dex_location.c_str(),
733 oat_location.c_str(), kRuntimeISA, true);
734
Richard Uhler95abd042015-03-24 09:51:28 -0700735 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800736
737 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
738 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
739 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
740 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
741 EXPECT_TRUE(oat_file_assistant.OatFileExists());
742 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
743 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700744 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800745
746 // Things aren't relocated, so it should fall back to interpreted.
747 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
748 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhlerf16d5722015-05-11 09:32:47 -0700749
Richard Uhler66d874d2015-01-15 09:37:19 -0800750 EXPECT_FALSE(oat_file->IsExecutable());
751 std::vector<std::unique_ptr<const DexFile>> dex_files;
752 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
753 EXPECT_EQ(1u, dex_files.size());
Richard Uhlerf16d5722015-05-11 09:32:47 -0700754
Richard Uhler2639e8e2015-07-20 09:40:34 -0700755 DiagnoseFlakyTestFailure(*oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -0800756}
757
758// Case: We have a DEX file and a PIC ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700759// Expect: The status is kNoDexOptNeeded, because PIC needs no relocation.
Richard Uhler66d874d2015-01-15 09:37:19 -0800760TEST_F(OatFileAssistantTest, DexPicOdexNoOat) {
761 std::string dex_location = GetScratchDir() + "/DexPicOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700762 std::string odex_location = GetOdexDir() + "/DexPicOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800763
764 // Create the dex and odex files
765 Copy(GetDexSrc1(), dex_location);
766 GeneratePicOdexForTest(dex_location, odex_location);
767
768 // Verify the status.
769 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
770
Richard Uhler95abd042015-03-24 09:51:28 -0700771 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800772
773 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
774 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
775 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
776 EXPECT_TRUE(oat_file_assistant.OdexFileIsUpToDate());
777 EXPECT_FALSE(oat_file_assistant.OatFileExists());
778 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
779 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700780 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800781}
782
783// Case: We have a DEX file and up-to-date OAT file for it.
784// Expect: We should load an executable dex file.
785TEST_F(OatFileAssistantTest, LoadOatUpToDate) {
786 std::string dex_location = GetScratchDir() + "/LoadOatUpToDate.jar";
787
788 Copy(GetDexSrc1(), dex_location);
789 GenerateOatForTest(dex_location.c_str());
790
791 // Load the oat using an oat file assistant.
792 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
793
794 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
795 ASSERT_TRUE(oat_file.get() != nullptr);
796 EXPECT_TRUE(oat_file->IsExecutable());
797 std::vector<std::unique_ptr<const DexFile>> dex_files;
798 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
799 EXPECT_EQ(1u, dex_files.size());
800}
801
802// Case: We have a DEX file and up-to-date OAT file for it.
803// Expect: Loading non-executable should load the oat non-executable.
804TEST_F(OatFileAssistantTest, LoadNoExecOatUpToDate) {
805 std::string dex_location = GetScratchDir() + "/LoadNoExecOatUpToDate.jar";
806
807 Copy(GetDexSrc1(), dex_location);
808 GenerateOatForTest(dex_location.c_str());
809
810 // Load the oat using an oat file assistant.
811 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
812
813 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
814 ASSERT_TRUE(oat_file.get() != nullptr);
815 EXPECT_FALSE(oat_file->IsExecutable());
816 std::vector<std::unique_ptr<const DexFile>> dex_files;
817 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
818 EXPECT_EQ(1u, dex_files.size());
819}
820
821// Case: We have a DEX file.
822// Expect: We should load an executable dex file from an alternative oat
823// location.
824TEST_F(OatFileAssistantTest, LoadDexNoAlternateOat) {
825 std::string dex_location = GetScratchDir() + "/LoadDexNoAlternateOat.jar";
826 std::string oat_location = GetScratchDir() + "/LoadDexNoAlternateOat.oat";
827
828 Copy(GetDexSrc1(), dex_location);
829
830 OatFileAssistant oat_file_assistant(
831 dex_location.c_str(), oat_location.c_str(), kRuntimeISA, true);
832 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700833 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(outof(error_msg))) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800834
835 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
836 ASSERT_TRUE(oat_file.get() != nullptr);
837 EXPECT_TRUE(oat_file->IsExecutable());
838 std::vector<std::unique_ptr<const DexFile>> dex_files;
839 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
840 EXPECT_EQ(1u, dex_files.size());
841
842 EXPECT_TRUE(OS::FileExists(oat_location.c_str()));
843
844 // Verify it didn't create an oat in the default location.
845 OatFileAssistant ofm(dex_location.c_str(), kRuntimeISA, false);
846 EXPECT_FALSE(ofm.OatFileExists());
847}
848
Richard Uhler66d874d2015-01-15 09:37:19 -0800849// Turn an absolute path into a path relative to the current working
850// directory.
851static std::string MakePathRelative(std::string target) {
852 char buf[MAXPATHLEN];
853 std::string cwd = getcwd(buf, MAXPATHLEN);
854
855 // Split the target and cwd paths into components.
856 std::vector<std::string> target_path;
857 std::vector<std::string> cwd_path;
858 Split(target, '/', &target_path);
859 Split(cwd, '/', &cwd_path);
860
861 // Reverse the path components, so we can use pop_back().
862 std::reverse(target_path.begin(), target_path.end());
863 std::reverse(cwd_path.begin(), cwd_path.end());
864
865 // Drop the common prefix of the paths. Because we reversed the path
866 // components, this becomes the common suffix of target_path and cwd_path.
867 while (!target_path.empty() && !cwd_path.empty()
868 && target_path.back() == cwd_path.back()) {
869 target_path.pop_back();
870 cwd_path.pop_back();
871 }
872
873 // For each element of the remaining cwd_path, add '..' to the beginning
874 // of the target path. Because we reversed the path components, we add to
875 // the end of target_path.
876 for (unsigned int i = 0; i < cwd_path.size(); i++) {
877 target_path.push_back("..");
878 }
879
880 // Reverse again to get the right path order, and join to get the result.
881 std::reverse(target_path.begin(), target_path.end());
882 return Join(target_path, '/');
883}
884
885// Case: Non-absolute path to Dex location.
886// Expect: Not sure, but it shouldn't crash.
887TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) {
888 std::string abs_dex_location = GetScratchDir() + "/NonAbsoluteDexLocation.jar";
889 Copy(GetDexSrc1(), abs_dex_location);
890
891 std::string dex_location = MakePathRelative(abs_dex_location);
892 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
893
894 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler95abd042015-03-24 09:51:28 -0700895 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800896 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
897 EXPECT_FALSE(oat_file_assistant.OatFileExists());
898 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
899 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
900 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
901 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
902}
903
904// Case: Very short, non-existent Dex location.
Richard Uhler9b994ea2015-06-24 08:44:19 -0700905// Expect: kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800906TEST_F(OatFileAssistantTest, ShortDexLocation) {
907 std::string dex_location = "/xx";
908
909 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
910
911 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700912 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800913 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
914 EXPECT_FALSE(oat_file_assistant.OatFileExists());
915 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
916 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
917 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
918 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700919 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800920
Richard Uhler9b994ea2015-06-24 08:44:19 -0700921 // Trying to make it up to date should have no effect.
Richard Uhler66d874d2015-01-15 09:37:19 -0800922 std::string error_msg;
Igor Murashkina315f5c2015-07-31 17:35:52 -0700923 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(outof(error_msg)));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700924 EXPECT_TRUE(error_msg.empty());
Richard Uhler66d874d2015-01-15 09:37:19 -0800925}
926
927// Case: Non-standard extension for dex file.
Richard Uhler95abd042015-03-24 09:51:28 -0700928// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800929TEST_F(OatFileAssistantTest, LongDexExtension) {
930 std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx";
931 Copy(GetDexSrc1(), dex_location);
932
933 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
934
Richard Uhler95abd042015-03-24 09:51:28 -0700935 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800936
937 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
938 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
939 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
940 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
941 EXPECT_FALSE(oat_file_assistant.OatFileExists());
942 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
943 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
944}
945
946// A task to generate a dex location. Used by the RaceToGenerate test.
947class RaceGenerateTask : public Task {
948 public:
949 explicit RaceGenerateTask(const std::string& dex_location, const std::string& oat_location)
950 : dex_location_(dex_location), oat_location_(oat_location),
951 loaded_oat_file_(nullptr)
952 {}
953
954 void Run(Thread* self) {
955 UNUSED(self);
956
957 // Load the dex files, and save a pointer to the loaded oat file, so that
958 // we can verify only one oat file was loaded for the dex location.
959 ClassLinker* linker = Runtime::Current()->GetClassLinker();
960 std::vector<std::unique_ptr<const DexFile>> dex_files;
961 std::vector<std::string> error_msgs;
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700962 dex_files = linker->OpenDexFilesFromOat(dex_location_.c_str(),
963 oat_location_.c_str(),
964 outof(error_msgs));
Richard Uhler66d874d2015-01-15 09:37:19 -0800965 CHECK(!dex_files.empty()) << Join(error_msgs, '\n');
Richard Uhler07b3c232015-03-31 15:57:54 -0700966 CHECK(dex_files[0]->GetOatDexFile() != nullptr) << dex_files[0]->GetLocation();
967 loaded_oat_file_ = dex_files[0]->GetOatDexFile()->GetOatFile();
Richard Uhler66d874d2015-01-15 09:37:19 -0800968 }
969
970 const OatFile* GetLoadedOatFile() const {
971 return loaded_oat_file_;
972 }
973
974 private:
975 std::string dex_location_;
976 std::string oat_location_;
977 const OatFile* loaded_oat_file_;
978};
979
980// Test the case where multiple processes race to generate an oat file.
981// This simulates multiple processes using multiple threads.
982//
983// We want only one Oat file to be loaded when there is a race to load, to
984// avoid using up the virtual memory address space.
985TEST_F(OatFileAssistantTest, RaceToGenerate) {
986 std::string dex_location = GetScratchDir() + "/RaceToGenerate.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700987 std::string oat_location = GetOdexDir() + "/RaceToGenerate.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -0800988
989 // We use the lib core dex file, because it's large, and hopefully should
990 // take a while to generate.
991 Copy(GetLibCoreDexFileName(), dex_location);
992
993 const int kNumThreads = 32;
994 Thread* self = Thread::Current();
995 ThreadPool thread_pool("Oat file assistant test thread pool", kNumThreads);
996 std::vector<std::unique_ptr<RaceGenerateTask>> tasks;
997 for (int i = 0; i < kNumThreads; i++) {
998 std::unique_ptr<RaceGenerateTask> task(new RaceGenerateTask(dex_location, oat_location));
999 thread_pool.AddTask(self, task.get());
1000 tasks.push_back(std::move(task));
1001 }
1002 thread_pool.StartWorkers(self);
1003 thread_pool.Wait(self, true, false);
1004
1005 // Verify every task got the same pointer.
1006 const OatFile* expected = tasks[0]->GetLoadedOatFile();
1007 for (auto& task : tasks) {
1008 EXPECT_EQ(expected, task->GetLoadedOatFile());
1009 }
1010}
1011
1012// Case: We have a DEX file and an ODEX file, no OAT file, and dex2oat is
1013// disabled.
1014// Expect: We should load the odex file non-executable.
1015TEST_F(OatFileAssistantNoDex2OatTest, LoadDexOdexNoOat) {
1016 std::string dex_location = GetScratchDir() + "/LoadDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001017 std::string odex_location = GetOdexDir() + "/LoadDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001018
1019 // Create the dex and odex files
1020 Copy(GetDexSrc1(), dex_location);
1021 GenerateOdexForTest(dex_location, odex_location);
1022
1023 // Load the oat using an executable oat file assistant.
1024 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
1025
1026 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1027 ASSERT_TRUE(oat_file.get() != nullptr);
1028 EXPECT_FALSE(oat_file->IsExecutable());
1029 std::vector<std::unique_ptr<const DexFile>> dex_files;
1030 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1031 EXPECT_EQ(1u, dex_files.size());
1032}
1033
1034// Case: We have a MultiDEX file and an ODEX file, no OAT file, and dex2oat is
1035// disabled.
1036// Expect: We should load the odex file non-executable.
1037TEST_F(OatFileAssistantNoDex2OatTest, LoadMultiDexOdexNoOat) {
1038 std::string dex_location = GetScratchDir() + "/LoadMultiDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001039 std::string odex_location = GetOdexDir() + "/LoadMultiDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001040
1041 // Create the dex and odex files
1042 Copy(GetMultiDexSrc1(), dex_location);
1043 GenerateOdexForTest(dex_location, odex_location);
1044
1045 // Load the oat using an executable oat file assistant.
1046 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
1047
1048 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1049 ASSERT_TRUE(oat_file.get() != nullptr);
1050 EXPECT_FALSE(oat_file->IsExecutable());
1051 std::vector<std::unique_ptr<const DexFile>> dex_files;
1052 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1053 EXPECT_EQ(2u, dex_files.size());
1054}
1055
1056TEST(OatFileAssistantUtilsTest, DexFilenameToOdexFilename) {
1057 std::string error_msg;
1058 std::string odex_file;
1059
1060 EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkina315f5c2015-07-31 17:35:52 -07001061 "/foo/bar/baz.jar", kArm, &odex_file, outof(error_msg))) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001062 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001063
1064 EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkina315f5c2015-07-31 17:35:52 -07001065 "/foo/bar/baz.funnyext", kArm, &odex_file, outof(error_msg))) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001066 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001067
1068 EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkina315f5c2015-07-31 17:35:52 -07001069 "nopath.jar", kArm, &odex_file, outof(error_msg)));
Richard Uhler66d874d2015-01-15 09:37:19 -08001070 EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkina315f5c2015-07-31 17:35:52 -07001071 "/foo/bar/baz_noext", kArm, &odex_file, outof(error_msg)));
Richard Uhler66d874d2015-01-15 09:37:19 -08001072}
1073
Richard Uhler23cedd22015-04-08 13:17:29 -07001074// Verify the dexopt status values from dalvik.system.DexFile
1075// match the OatFileAssistant::DexOptStatus values.
1076TEST_F(OatFileAssistantTest, DexOptStatusValues) {
1077 ScopedObjectAccess soa(Thread::Current());
1078 StackHandleScope<1> hs(soa.Self());
1079 ClassLinker* linker = Runtime::Current()->GetClassLinker();
1080 Handle<mirror::Class> dexfile(
1081 hs.NewHandle(linker->FindSystemClass(soa.Self(), "Ldalvik/system/DexFile;")));
1082 ASSERT_FALSE(dexfile.Get() == nullptr);
1083 linker->EnsureInitialized(soa.Self(), dexfile, true, true);
1084
Mathieu Chartierc7853442015-03-27 14:35:38 -07001085 ArtField* no_dexopt_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001086 soa.Self(), dexfile, "NO_DEXOPT_NEEDED", "I");
1087 ASSERT_FALSE(no_dexopt_needed == nullptr);
1088 EXPECT_EQ(no_dexopt_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1089 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, no_dexopt_needed->GetInt(dexfile.Get()));
1090
Mathieu Chartierc7853442015-03-27 14:35:38 -07001091 ArtField* dex2oat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001092 soa.Self(), dexfile, "DEX2OAT_NEEDED", "I");
1093 ASSERT_FALSE(dex2oat_needed == nullptr);
1094 EXPECT_EQ(dex2oat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1095 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, dex2oat_needed->GetInt(dexfile.Get()));
1096
Mathieu Chartierc7853442015-03-27 14:35:38 -07001097 ArtField* patchoat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001098 soa.Self(), dexfile, "PATCHOAT_NEEDED", "I");
1099 ASSERT_FALSE(patchoat_needed == nullptr);
1100 EXPECT_EQ(patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1101 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, patchoat_needed->GetInt(dexfile.Get()));
1102
Mathieu Chartierc7853442015-03-27 14:35:38 -07001103 ArtField* self_patchoat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001104 soa.Self(), dexfile, "SELF_PATCHOAT_NEEDED", "I");
1105 ASSERT_FALSE(self_patchoat_needed == nullptr);
1106 EXPECT_EQ(self_patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1107 EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded, self_patchoat_needed->GetInt(dexfile.Get()));
1108}
Richard Uhler66d874d2015-01-15 09:37:19 -08001109
1110// TODO: More Tests:
1111// * Test class linker falls back to unquickened dex for DexNoOat
1112// * Test class linker falls back to unquickened dex for MultiDexNoOat
Richard Uhler66d874d2015-01-15 09:37:19 -08001113// * Test using secondary isa
1114// * Test with profiling info?
1115// * Test for status of oat while oat is being generated (how?)
1116// * Test case where 32 and 64 bit boot class paths differ,
1117// and we ask IsInBootClassPath for a class in exactly one of the 32 or
1118// 64 bit boot class paths.
1119// * Test unexpected scenarios (?):
1120// - Dex is stripped, don't have odex.
1121// - Oat file corrupted after status check, before reload unexecutable
1122// because it's unrelocated and no dex2oat
1123
1124} // namespace art