blob: 634e048280b1e304c8e3bfefd111360cde139d3a [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"
Vladimir Marko3481ba22015-04-13 12:22:36 +010029#include "class_linker-inl.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080030#include "common_runtime_test.h"
Andreas Gampebb9c6b12015-03-29 13:56:36 -070031#include "compiler_callbacks.h"
Richard Uhlerf16d5722015-05-11 09:32:47 -070032#include "gc/space/image_space.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080033#include "mem_map.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070034#include "oat_file_manager.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080035#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
42class OatFileAssistantTest : public CommonRuntimeTest {
43 public:
44 virtual void SetUp() {
45 ReserveImageSpace();
46 CommonRuntimeTest::SetUp();
47
48 // Create a scratch directory to work from.
49 scratch_dir_ = android_data_ + "/OatFileAssistantTest";
50 ASSERT_EQ(0, mkdir(scratch_dir_.c_str(), 0700));
51
Richard Uhler63434112015-03-16 14:32:16 -070052 // Create a subdirectory in scratch for odex files.
53 odex_oat_dir_ = scratch_dir_ + "/oat";
54 ASSERT_EQ(0, mkdir(odex_oat_dir_.c_str(), 0700));
55
56 odex_dir_ = odex_oat_dir_ + "/" + std::string(GetInstructionSetString(kRuntimeISA));
57 ASSERT_EQ(0, mkdir(odex_dir_.c_str(), 0700));
58
Richard Uhler66d874d2015-01-15 09:37:19 -080059
60 // Verify the environment is as we expect
61 uint32_t checksum;
62 std::string error_msg;
63 ASSERT_TRUE(OS::FileExists(GetImageFile().c_str()))
64 << "Expected pre-compiled boot image to be at: " << GetImageFile();
65 ASSERT_TRUE(OS::FileExists(GetDexSrc1().c_str()))
66 << "Expected dex file to be at: " << GetDexSrc1();
67 ASSERT_TRUE(OS::FileExists(GetStrippedDexSrc1().c_str()))
68 << "Expected stripped dex file to be at: " << GetStrippedDexSrc1();
Igor Murashkinb1d8c312015-08-04 11:18:43 -070069 ASSERT_FALSE(DexFile::GetChecksum(GetStrippedDexSrc1().c_str(), &checksum, &error_msg))
Richard Uhler66d874d2015-01-15 09:37:19 -080070 << "Expected stripped dex file to be stripped: " << GetStrippedDexSrc1();
Richard Uhler66d874d2015-01-15 09:37:19 -080071 ASSERT_TRUE(OS::FileExists(GetDexSrc2().c_str()))
72 << "Expected dex file to be at: " << GetDexSrc2();
Richard Uhler67ff7d12015-05-14 13:21:13 -070073
74 // GetMultiDexSrc2 should have the same primary dex checksum as
75 // GetMultiDexSrc1, but a different secondary dex checksum.
76 std::vector<std::unique_ptr<const DexFile>> multi1;
77 ASSERT_TRUE(DexFile::Open(GetMultiDexSrc1().c_str(),
Igor Murashkinb1d8c312015-08-04 11:18:43 -070078 GetMultiDexSrc1().c_str(), &error_msg, &multi1)) << error_msg;
Richard Uhler67ff7d12015-05-14 13:21:13 -070079 ASSERT_GT(multi1.size(), 1u);
80
81 std::vector<std::unique_ptr<const DexFile>> multi2;
82 ASSERT_TRUE(DexFile::Open(GetMultiDexSrc2().c_str(),
Igor Murashkinb1d8c312015-08-04 11:18:43 -070083 GetMultiDexSrc2().c_str(), &error_msg, &multi2)) << error_msg;
Richard Uhler67ff7d12015-05-14 13:21:13 -070084 ASSERT_GT(multi2.size(), 1u);
85
86 ASSERT_EQ(multi1[0]->GetLocationChecksum(), multi2[0]->GetLocationChecksum());
87 ASSERT_NE(multi1[1]->GetLocationChecksum(), multi2[1]->GetLocationChecksum());
Richard Uhler66d874d2015-01-15 09:37:19 -080088 }
89
90 virtual void SetUpRuntimeOptions(RuntimeOptions* options) {
Richard Uhler892fc962015-03-10 16:57:05 +000091 // options->push_back(std::make_pair("-verbose:oat", nullptr));
Richard Uhler66d874d2015-01-15 09:37:19 -080092
93 // Set up the image location.
94 options->push_back(std::make_pair("-Ximage:" + GetImageLocation(),
95 nullptr));
96 // Make sure compilercallbacks are not set so that relocation will be
97 // enabled.
Andreas Gampebb9c6b12015-03-29 13:56:36 -070098 callbacks_.reset();
Richard Uhler66d874d2015-01-15 09:37:19 -080099 }
100
101 virtual void PreRuntimeCreate() {
102 UnreserveImageSpace();
103 }
104
105 virtual void PostRuntimeCreate() {
106 ReserveImageSpace();
107 }
108
109 virtual void TearDown() {
Richard Uhler63434112015-03-16 14:32:16 -0700110 ClearDirectory(odex_dir_.c_str());
111 ASSERT_EQ(0, rmdir(odex_dir_.c_str()));
112
113 ClearDirectory(odex_oat_dir_.c_str());
114 ASSERT_EQ(0, rmdir(odex_oat_dir_.c_str()));
Richard Uhler66d874d2015-01-15 09:37:19 -0800115
116 ClearDirectory(scratch_dir_.c_str());
117 ASSERT_EQ(0, rmdir(scratch_dir_.c_str()));
118
119 CommonRuntimeTest::TearDown();
120 }
121
122 void Copy(std::string src, std::string dst) {
123 std::ifstream src_stream(src, std::ios::binary);
124 std::ofstream dst_stream(dst, std::ios::binary);
125
126 dst_stream << src_stream.rdbuf();
127 }
128
129 // Returns the directory where the pre-compiled core.art can be found.
130 // TODO: We should factor out this into common tests somewhere rather than
131 // re-hardcoding it here (This was copied originally from the elf writer
132 // test).
133 std::string GetImageDirectory() {
134 if (IsHost()) {
135 const char* host_dir = getenv("ANDROID_HOST_OUT");
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700136 CHECK(host_dir != nullptr);
Richard Uhler66d874d2015-01-15 09:37:19 -0800137 return std::string(host_dir) + "/framework";
138 } else {
139 return std::string("/data/art-test");
140 }
141 }
142
143 std::string GetImageLocation() {
144 return GetImageDirectory() + "/core.art";
145 }
146
147 std::string GetImageFile() {
148 return GetImageDirectory() + "/" + GetInstructionSetString(kRuntimeISA)
149 + "/core.art";
150 }
151
152 std::string GetDexSrc1() {
153 return GetTestDexFileName("Main");
154 }
155
156 // Returns the path to a dex file equivalent to GetDexSrc1, but with the dex
157 // file stripped.
158 std::string GetStrippedDexSrc1() {
159 return GetTestDexFileName("MainStripped");
160 }
161
162 std::string GetMultiDexSrc1() {
163 return GetTestDexFileName("MultiDex");
164 }
165
Richard Uhler67ff7d12015-05-14 13:21:13 -0700166 // Returns the path to a multidex file equivalent to GetMultiDexSrc2, but
167 // with the contents of the secondary dex file changed.
168 std::string GetMultiDexSrc2() {
169 return GetTestDexFileName("MultiDexModifiedSecondary");
170 }
171
Richard Uhler66d874d2015-01-15 09:37:19 -0800172 std::string GetDexSrc2() {
173 return GetTestDexFileName("Nested");
174 }
175
176 // Scratch directory, for dex and odex files (oat files will go in the
177 // dalvik cache).
178 std::string GetScratchDir() {
179 return scratch_dir_;
180 }
181
Richard Uhler63434112015-03-16 14:32:16 -0700182 // Odex directory is the subdirectory in the scratch directory where odex
Richard Uhler66d874d2015-01-15 09:37:19 -0800183 // files should be located.
Richard Uhler63434112015-03-16 14:32:16 -0700184 std::string GetOdexDir() {
185 return odex_dir_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800186 }
187
Richard Uhler93aa2102015-08-10 14:47:41 -0700188 // Generate a non-PIC odex file for the purposes of test.
Richard Uhler94f5bda2015-07-22 08:25:11 -0700189 // The generated odex file will be un-relocated.
Richard Uhler66d874d2015-01-15 09:37:19 -0800190 void GenerateOdexForTest(const std::string& dex_location,
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000191 const std::string& odex_location,
192 CompilerFilter::Filter filter) {
Richard Uhler93aa2102015-08-10 14:47:41 -0700193 // To generate an un-relocated odex file, we first compile a relocated
194 // version of the file, then manually call patchoat to make it look as if
195 // it is unrelocated.
196 std::string relocated_odex_location = odex_location + ".relocated";
197 std::vector<std::string> args;
198 args.push_back("--dex-file=" + dex_location);
199 args.push_back("--oat-file=" + relocated_odex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000200 args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter));
Richard Uhler93aa2102015-08-10 14:47:41 -0700201
202 // We need to use the quick compiler to generate non-PIC code, because
203 // the optimizing compiler always generates PIC.
204 args.push_back("--compiler-backend=Quick");
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000205 args.push_back("--include-patch-information");
Richard Uhler93aa2102015-08-10 14:47:41 -0700206
207 std::string error_msg;
208 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
209
210 // Use patchoat to unrelocate the relocated odex file.
211 Runtime* runtime = Runtime::Current();
212 std::vector<std::string> argv;
213 argv.push_back(runtime->GetPatchoatExecutable());
214 argv.push_back("--instruction-set=" + std::string(GetInstructionSetString(kRuntimeISA)));
215 argv.push_back("--input-oat-file=" + relocated_odex_location);
216 argv.push_back("--output-oat-file=" + odex_location);
217 argv.push_back("--base-offset-delta=0x00008000");
218 std::string command_line(Join(argv, ' '));
219 ASSERT_TRUE(Exec(argv, &error_msg)) << error_msg;
220
221 // Verify the odex file was generated as expected and really is
222 // unrelocated.
Mathieu Chartierbcb6a722016-03-08 16:49:58 -0800223 std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
224 odex_location.c_str(),
225 nullptr,
226 nullptr,
227 false,
228 /*low_4gb*/false,
229 dex_location.c_str(),
230 &error_msg));
Richard Uhler93aa2102015-08-10 14:47:41 -0700231 ASSERT_TRUE(odex_file.get() != nullptr) << error_msg;
Richard Uhler93aa2102015-08-10 14:47:41 -0700232 EXPECT_FALSE(odex_file->IsPic());
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000233 EXPECT_EQ(filter, odex_file->GetCompilerFilter());
234
235 if (CompilerFilter::IsCompilationEnabled(filter)) {
236 const std::vector<gc::space::ImageSpace*> image_spaces =
237 runtime->GetHeap()->GetBootImageSpaces();
238 ASSERT_TRUE(!image_spaces.empty() && image_spaces[0] != nullptr);
239 const ImageHeader& image_header = image_spaces[0]->GetImageHeader();
240 const OatHeader& oat_header = odex_file->GetOatHeader();
241 EXPECT_EQ(image_header.GetOatChecksum(), oat_header.GetImageFileLocationOatChecksum());
242 EXPECT_NE(reinterpret_cast<uintptr_t>(image_header.GetOatDataBegin()),
243 oat_header.GetImageFileLocationOatDataBegin());
244 EXPECT_NE(image_header.GetPatchDelta(), oat_header.GetImagePatchDelta());
245 }
Richard Uhler93aa2102015-08-10 14:47:41 -0700246 }
247
248 void GeneratePicOdexForTest(const std::string& dex_location,
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000249 const std::string& odex_location,
250 CompilerFilter::Filter filter) {
Richard Uhler93aa2102015-08-10 14:47:41 -0700251 // Temporarily redirect the dalvik cache so dex2oat doesn't find the
252 // relocated image file.
Richard Uhler66d874d2015-01-15 09:37:19 -0800253 std::string android_data_tmp = GetScratchDir() + "AndroidDataTmp";
254 setenv("ANDROID_DATA", android_data_tmp.c_str(), 1);
255 std::vector<std::string> args;
256 args.push_back("--dex-file=" + dex_location);
257 args.push_back("--oat-file=" + odex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000258 args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter));
Richard Uhler93aa2102015-08-10 14:47:41 -0700259 args.push_back("--compile-pic");
Richard Uhler66d874d2015-01-15 09:37:19 -0800260 args.push_back("--runtime-arg");
261 args.push_back("-Xnorelocate");
262 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700263 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800264 setenv("ANDROID_DATA", android_data_.c_str(), 1);
Richard Uhler94f5bda2015-07-22 08:25:11 -0700265
266 // Verify the odex file was generated as expected.
Mathieu Chartierbcb6a722016-03-08 16:49:58 -0800267 std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
268 odex_location.c_str(),
269 nullptr,
270 nullptr,
271 false,
272 /*low_4gb*/false,
273 dex_location.c_str(),
274 &error_msg));
Richard Uhler94f5bda2015-07-22 08:25:11 -0700275 ASSERT_TRUE(odex_file.get() != nullptr) << error_msg;
Richard Uhler93aa2102015-08-10 14:47:41 -0700276 EXPECT_TRUE(odex_file->IsPic());
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000277 EXPECT_EQ(filter, odex_file->GetCompilerFilter());
Calin Juravled91b8a22016-02-18 18:47:37 +0000278 }
David Brazdilce4b0ba2016-01-28 15:05:49 +0000279
Richard Uhler66d874d2015-01-15 09:37:19 -0800280 private:
281 // Reserve memory around where the image will be loaded so other memory
282 // won't conflict when it comes time to load the image.
283 // This can be called with an already loaded image to reserve the space
284 // around it.
285 void ReserveImageSpace() {
286 MemMap::Init();
287
288 // Ensure a chunk of memory is reserved for the image space.
289 uintptr_t reservation_start = ART_BASE_ADDRESS + ART_BASE_ADDRESS_MIN_DELTA;
290 uintptr_t reservation_end = ART_BASE_ADDRESS + ART_BASE_ADDRESS_MAX_DELTA
Hiroshi Yamauchi3dbf2342015-03-17 16:01:11 -0700291 // Include the main space that has to come right after the
292 // image in case of the GSS collector.
293 + 384 * MB;
Richard Uhler66d874d2015-01-15 09:37:19 -0800294
Richard Uhler66d874d2015-01-15 09:37:19 -0800295 std::unique_ptr<BacktraceMap> map(BacktraceMap::Create(getpid(), true));
296 ASSERT_TRUE(map.get() != nullptr) << "Failed to build process map";
297 for (BacktraceMap::const_iterator it = map->begin();
298 reservation_start < reservation_end && it != map->end(); ++it) {
Richard Uhler3efe9792015-03-30 16:18:03 -0700299 ReserveImageSpaceChunk(reservation_start, std::min(it->start, reservation_end));
300 reservation_start = std::max(reservation_start, it->end);
301 }
302 ReserveImageSpaceChunk(reservation_start, reservation_end);
303 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800304
Richard Uhler3efe9792015-03-30 16:18:03 -0700305 // Reserve a chunk of memory for the image space in the given range.
306 // Only has effect for chunks with a positive number of bytes.
307 void ReserveImageSpaceChunk(uintptr_t start, uintptr_t end) {
308 if (start < end) {
309 std::string error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800310 image_reservation_.push_back(std::unique_ptr<MemMap>(
311 MemMap::MapAnonymous("image reservation",
Richard Uhler3efe9792015-03-30 16:18:03 -0700312 reinterpret_cast<uint8_t*>(start), end - start,
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700313 PROT_NONE, false, false, &error_msg)));
Richard Uhler66d874d2015-01-15 09:37:19 -0800314 ASSERT_TRUE(image_reservation_.back().get() != nullptr) << error_msg;
315 LOG(INFO) << "Reserved space for image " <<
316 reinterpret_cast<void*>(image_reservation_.back()->Begin()) << "-" <<
317 reinterpret_cast<void*>(image_reservation_.back()->End());
Richard Uhler66d874d2015-01-15 09:37:19 -0800318 }
319 }
320
321
322 // Unreserve any memory reserved by ReserveImageSpace. This should be called
323 // before the image is loaded.
324 void UnreserveImageSpace() {
325 image_reservation_.clear();
326 }
327
328 std::string scratch_dir_;
Richard Uhler63434112015-03-16 14:32:16 -0700329 std::string odex_oat_dir_;
330 std::string odex_dir_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800331 std::vector<std::unique_ptr<MemMap>> image_reservation_;
332};
333
334class OatFileAssistantNoDex2OatTest : public OatFileAssistantTest {
335 public:
336 virtual void SetUpRuntimeOptions(RuntimeOptions* options) {
337 OatFileAssistantTest::SetUpRuntimeOptions(options);
338 options->push_back(std::make_pair("-Xnodex2oat", nullptr));
339 }
340};
341
342// Generate an oat file for the purposes of test, as opposed to testing
343// generation of oat files.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000344static void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter) {
345 // Use an oat file assistant to find the proper oat location.
346 OatFileAssistant ofa(dex_location, kRuntimeISA, false, false);
347 const std::string* oat_location = ofa.OatFileName();
348 ASSERT_TRUE(oat_location != nullptr);
Richard Uhler66d874d2015-01-15 09:37:19 -0800349
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000350 std::vector<std::string> args;
351 args.push_back("--dex-file=" + std::string(dex_location));
352 args.push_back("--oat-file=" + *oat_location);
353 args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter));
354 args.push_back("--runtime-arg");
355 args.push_back("-Xnorelocate");
Richard Uhler66d874d2015-01-15 09:37:19 -0800356 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000357 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
358
359 // Verify the oat file was generated as expected.
360 std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location->c_str(),
361 oat_location->c_str(),
362 nullptr,
363 nullptr,
364 false,
365 /*low_4gb*/false,
366 dex_location,
367 &error_msg));
368 ASSERT_TRUE(oat_file.get() != nullptr) << error_msg;
369 EXPECT_EQ(filter, oat_file->GetCompilerFilter());
Richard Uhler66d874d2015-01-15 09:37:19 -0800370}
371
372// Case: We have a DEX file, but no OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700373// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800374TEST_F(OatFileAssistantTest, DexNoOat) {
375 std::string dex_location = GetScratchDir() + "/DexNoOat.jar";
376 Copy(GetDexSrc1(), dex_location);
377
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000378 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800379
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000380 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
381 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
382 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
383 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
384 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
385 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile));
386 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
387 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800388
389 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
390 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
391 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
392 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
393 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700394 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OdexFileStatus());
Richard Uhler66d874d2015-01-15 09:37:19 -0800395 EXPECT_FALSE(oat_file_assistant.OatFileExists());
396 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
397 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
398 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700399 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OatFileStatus());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700400 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800401}
402
403// Case: We have no DEX file and no OAT file.
Richard Uhler9b994ea2015-06-24 08:44:19 -0700404// Expect: Status is kNoDexOptNeeded. Loading should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800405TEST_F(OatFileAssistantTest, NoDexNoOat) {
406 std::string dex_location = GetScratchDir() + "/NoDexNoOat.jar";
407
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000408 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800409
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000410 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
411 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700412 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
413
414 // Trying to make the oat file up to date should not fail or crash.
415 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000416 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(CompilerFilter::kSpeed, &error_msg));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700417
418 // Trying to get the best oat file should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800419 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
420 EXPECT_EQ(nullptr, oat_file.get());
421}
422
423// Case: We have a DEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700424// Expect: The status is kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800425TEST_F(OatFileAssistantTest, OatUpToDate) {
426 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
427 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000428 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800429
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000430 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800431
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000432 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
433 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
434 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
435 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
436 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
437 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
438 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
439 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
440
Richard Uhler66d874d2015-01-15 09:37:19 -0800441 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
442 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
443 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
444 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
445 EXPECT_TRUE(oat_file_assistant.OatFileExists());
446 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
447 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
448 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700449 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700450 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800451}
452
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000453// Case: We have a DEX file and speed-profile OAT file for it.
454// Expect: The status is kNoDexOptNeeded if the profile hasn't changed.
455TEST_F(OatFileAssistantTest, ProfileOatUpToDate) {
456 std::string dex_location = GetScratchDir() + "/ProfileOatUpToDate.jar";
457 Copy(GetDexSrc1(), dex_location);
458 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile);
459
460 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
461
462 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
463 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile));
464 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
465 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
466
467 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
468 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
469 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
470 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
471 EXPECT_TRUE(oat_file_assistant.OatFileExists());
472 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
473 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
474 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
475 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
476 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
477}
478
479// Case: We have a DEX file and speed-profile OAT file for it.
480// Expect: The status is kNoDex2OatNeeded if the profile has changed.
481TEST_F(OatFileAssistantTest, ProfileOatOutOfDate) {
482 std::string dex_location = GetScratchDir() + "/ProfileOatOutOfDate.jar";
483 Copy(GetDexSrc1(), dex_location);
484 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile);
485
486 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true, false);
487
488 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
489 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile));
490 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
491 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
492
493 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
494 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
495 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
496 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
497 EXPECT_TRUE(oat_file_assistant.OatFileExists());
498 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
499 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
500 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
501 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OatFileStatus());
502 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
503}
504
Richard Uhler66d874d2015-01-15 09:37:19 -0800505// Case: We have a MultiDEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700506// Expect: The status is kNoDexOptNeeded and we load all dex files.
Richard Uhler66d874d2015-01-15 09:37:19 -0800507TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) {
508 std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar";
509 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000510 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800511
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000512 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
513 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
514 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700515 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700516
517 // Verify we can load both dex files.
Richard Uhlere5fed032015-03-18 08:21:11 -0700518 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
Richard Uhler66d874d2015-01-15 09:37:19 -0800519 ASSERT_TRUE(oat_file.get() != nullptr);
520 EXPECT_TRUE(oat_file->IsExecutable());
521 std::vector<std::unique_ptr<const DexFile>> dex_files;
Richard Uhlere5fed032015-03-18 08:21:11 -0700522 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
523 EXPECT_EQ(2u, dex_files.size());
524}
525
Richard Uhler67ff7d12015-05-14 13:21:13 -0700526// Case: We have a MultiDEX file where the secondary dex file is out of date.
527// Expect: The status is kDex2OatNeeded.
528TEST_F(OatFileAssistantTest, MultiDexSecondaryOutOfDate) {
529 std::string dex_location = GetScratchDir() + "/MultiDexSecondaryOutOfDate.jar";
530
531 // Compile code for GetMultiDexSrc1.
532 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000533 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler67ff7d12015-05-14 13:21:13 -0700534
535 // Now overwrite the dex file with GetMultiDexSrc2 so the secondary checksum
536 // is out of date.
537 Copy(GetMultiDexSrc2(), dex_location);
538
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000539 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
540 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
541 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700542 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler67ff7d12015-05-14 13:21:13 -0700543}
544
Richard Uhlere5fed032015-03-18 08:21:11 -0700545// Case: We have a MultiDEX file and up-to-date OAT file for it with relative
546// encoded dex locations.
Richard Uhler95abd042015-03-24 09:51:28 -0700547// Expect: The oat file status is kNoDexOptNeeded.
Richard Uhlere5fed032015-03-18 08:21:11 -0700548TEST_F(OatFileAssistantTest, RelativeEncodedDexLocation) {
549 std::string dex_location = GetScratchDir() + "/RelativeEncodedDexLocation.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700550 std::string oat_location = GetOdexDir() + "/RelativeEncodedDexLocation.oat";
Richard Uhlere5fed032015-03-18 08:21:11 -0700551
552 // Create the dex file
553 Copy(GetMultiDexSrc1(), dex_location);
554
555 // Create the oat file with relative encoded dex location.
556 std::vector<std::string> args;
557 args.push_back("--dex-file=" + dex_location);
558 args.push_back("--dex-location=" + std::string("RelativeEncodedDexLocation.jar"));
559 args.push_back("--oat-file=" + oat_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000560 args.push_back("--compiler-filter=speed");
Richard Uhlere5fed032015-03-18 08:21:11 -0700561
562 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700563 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
Richard Uhlere5fed032015-03-18 08:21:11 -0700564
565 // Verify we can load both dex files.
566 OatFileAssistant oat_file_assistant(dex_location.c_str(),
567 oat_location.c_str(),
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000568 kRuntimeISA, false, true);
Richard Uhlere5fed032015-03-18 08:21:11 -0700569 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
570 ASSERT_TRUE(oat_file.get() != nullptr);
571 EXPECT_TRUE(oat_file->IsExecutable());
572 std::vector<std::unique_ptr<const DexFile>> dex_files;
573 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
Richard Uhler66d874d2015-01-15 09:37:19 -0800574 EXPECT_EQ(2u, dex_files.size());
575}
576
Richard Uhler95abd042015-03-24 09:51:28 -0700577// Case: We have a DEX file and out-of-date OAT file.
578// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800579TEST_F(OatFileAssistantTest, OatOutOfDate) {
580 std::string dex_location = GetScratchDir() + "/OatOutOfDate.jar";
581
582 // We create a dex, generate an oat for it, then overwrite the dex with a
583 // different dex to make the oat out of date.
584 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000585 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800586 Copy(GetDexSrc2(), dex_location);
587
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000588 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
589 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
590 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
591 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
592 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800593
594 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
595 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
596 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
597 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
598 EXPECT_TRUE(oat_file_assistant.OatFileExists());
599 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
600 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700601 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800602}
603
604// Case: We have a DEX file and an ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700605// Expect: The status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800606TEST_F(OatFileAssistantTest, DexOdexNoOat) {
607 std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700608 std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800609
610 // Create the dex and odex files
611 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000612 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800613
614 // Verify the status.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000615 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800616
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000617 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
618 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
619 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded,
620 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800621
622 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
623 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
624 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
625 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
626 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
Richard Uhler66d874d2015-01-15 09:37:19 -0800627 EXPECT_FALSE(oat_file_assistant.OatFileExists());
628 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
629 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700630 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler5f946da2015-07-17 12:28:32 -0700631
632 // We should still be able to get the non-executable odex file to run from.
633 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
634 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhler66d874d2015-01-15 09:37:19 -0800635}
636
637// Case: We have a stripped DEX file and an ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700638// Expect: The status is kPatchOatNeeded
Richard Uhler66d874d2015-01-15 09:37:19 -0800639TEST_F(OatFileAssistantTest, StrippedDexOdexNoOat) {
640 std::string dex_location = GetScratchDir() + "/StrippedDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700641 std::string odex_location = GetOdexDir() + "/StrippedDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800642
643 // Create the dex and odex files
644 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000645 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800646
647 // Strip the dex file
648 Copy(GetStrippedDexSrc1(), dex_location);
649
650 // Verify the status.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000651 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800652
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000653 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded,
654 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800655
656 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
657 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
658 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
659 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
660 EXPECT_FALSE(oat_file_assistant.OatFileExists());
661 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
662 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700663 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800664
665 // Make the oat file up to date.
666 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000667 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(CompilerFilter::kSpeed, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800668
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000669 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
670 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800671
672 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
673 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
674 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
675 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
676 EXPECT_TRUE(oat_file_assistant.OatFileExists());
677 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
678 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700679 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800680
681 // Verify we can load the dex files from it.
682 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
683 ASSERT_TRUE(oat_file.get() != nullptr);
684 EXPECT_TRUE(oat_file->IsExecutable());
685 std::vector<std::unique_ptr<const DexFile>> dex_files;
686 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
687 EXPECT_EQ(1u, dex_files.size());
688}
689
Richard Uhler95abd042015-03-24 09:51:28 -0700690// Case: We have a stripped DEX file, an ODEX file, and an out-of-date OAT file.
691// Expect: The status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800692TEST_F(OatFileAssistantTest, StrippedDexOdexOat) {
693 std::string dex_location = GetScratchDir() + "/StrippedDexOdexOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700694 std::string odex_location = GetOdexDir() + "/StrippedDexOdexOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800695
696 // Create the oat file from a different dex file so it looks out of date.
697 Copy(GetDexSrc2(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000698 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800699
700 // Create the odex file
701 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000702 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800703
704 // Strip the dex file.
705 Copy(GetStrippedDexSrc1(), dex_location);
706
707 // Verify the status.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000708 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800709
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000710 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
711 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
712 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded,
713 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
714 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, // Can't run dex2oat because dex file is stripped.
715 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
Richard Uhler66d874d2015-01-15 09:37:19 -0800716
717 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
718 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
719 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
720 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
721 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
722 EXPECT_TRUE(oat_file_assistant.OatFileExists());
723 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
724 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700725 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800726
727 // Make the oat file up to date.
728 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000729 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(CompilerFilter::kSpeed, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800730
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000731 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
732 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
733 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, // Can't run dex2oat because dex file is stripped.
734 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
Richard Uhler66d874d2015-01-15 09:37:19 -0800735
736 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
737 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
738 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
739 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
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.OatFileNeedsRelocation());
744 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700745 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800746
747 // Verify we can load the dex files from it.
748 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
749 ASSERT_TRUE(oat_file.get() != nullptr);
750 EXPECT_TRUE(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());
754}
755
Richard Uhler9b994ea2015-06-24 08:44:19 -0700756// Case: We have a stripped (or resource-only) DEX file, no ODEX file and no
757// OAT file. Expect: The status is kNoDexOptNeeded.
758TEST_F(OatFileAssistantTest, ResourceOnlyDex) {
759 std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar";
760
761 Copy(GetStrippedDexSrc1(), dex_location);
762
763 // Verify the status.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000764 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler9b994ea2015-06-24 08:44:19 -0700765
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000766 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
767 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
768 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
769 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
770 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
771 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700772
773 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
774 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
775 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
776 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
777 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
778 EXPECT_FALSE(oat_file_assistant.OatFileExists());
779 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
780 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
781 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
782
783 // Make the oat file up to date. This should have no effect.
784 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000785 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(CompilerFilter::kSpeed, &error_msg)) << error_msg;
Richard Uhler9b994ea2015-06-24 08:44:19 -0700786
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000787 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
788 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700789
790 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
791 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
792 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
793 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
794 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
795 EXPECT_FALSE(oat_file_assistant.OatFileExists());
796 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
797 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
798 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
799}
800
Richard Uhler95abd042015-03-24 09:51:28 -0700801// Case: We have a DEX file, no ODEX file and an OAT file that needs
802// relocation.
803// Expect: The status is kSelfPatchOatNeeded.
804TEST_F(OatFileAssistantTest, SelfRelocation) {
805 std::string dex_location = GetScratchDir() + "/SelfRelocation.jar";
806 std::string oat_location = GetOdexDir() + "/SelfRelocation.oat";
807
808 // Create the dex and odex files
809 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000810 GenerateOdexForTest(dex_location, oat_location, CompilerFilter::kSpeed);
Richard Uhler95abd042015-03-24 09:51:28 -0700811
812 OatFileAssistant oat_file_assistant(dex_location.c_str(),
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000813 oat_location.c_str(), kRuntimeISA, false, true);
Richard Uhler95abd042015-03-24 09:51:28 -0700814
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000815 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
816 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
817 EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded,
818 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
819 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
820 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
Richard Uhler95abd042015-03-24 09:51:28 -0700821
822 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
823 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
824 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
825 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
826 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
827 EXPECT_TRUE(oat_file_assistant.OatFileExists());
828 EXPECT_TRUE(oat_file_assistant.OatFileNeedsRelocation());
829 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
830 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700831 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700832
833 // Make the oat file up to date.
834 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000835 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(CompilerFilter::kSpeed, &error_msg)) << error_msg;
Richard Uhler95abd042015-03-24 09:51:28 -0700836
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000837 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
838 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler95abd042015-03-24 09:51:28 -0700839
840 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
841 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
842 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
843 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
844 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
845 EXPECT_TRUE(oat_file_assistant.OatFileExists());
846 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
847 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
848 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700849 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700850
851 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
852 ASSERT_TRUE(oat_file.get() != nullptr);
853 EXPECT_TRUE(oat_file->IsExecutable());
854 std::vector<std::unique_ptr<const DexFile>> dex_files;
855 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
856 EXPECT_EQ(1u, dex_files.size());
857}
858
Richard Uhler66d874d2015-01-15 09:37:19 -0800859// Case: We have a DEX file, an ODEX file and an OAT file, where the ODEX and
860// OAT files both have patch delta of 0.
Richard Uhler95abd042015-03-24 09:51:28 -0700861// Expect: It shouldn't crash, and status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800862TEST_F(OatFileAssistantTest, OdexOatOverlap) {
863 std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700864 std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex";
865 std::string oat_location = GetOdexDir() + "/OdexOatOverlap.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -0800866
867 // Create the dex and odex files
868 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000869 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800870
871 // Create the oat file by copying the odex so they are located in the same
872 // place in memory.
873 Copy(odex_location, oat_location);
874
875 // Verify things don't go bad.
876 OatFileAssistant oat_file_assistant(dex_location.c_str(),
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000877 oat_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800878
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000879 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded,
880 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800881
882 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
883 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
884 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
885 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
886 EXPECT_TRUE(oat_file_assistant.OatFileExists());
887 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
888 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700889 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800890
891 // Things aren't relocated, so it should fall back to interpreted.
892 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
893 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhlerf16d5722015-05-11 09:32:47 -0700894
Richard Uhler66d874d2015-01-15 09:37:19 -0800895 EXPECT_FALSE(oat_file->IsExecutable());
896 std::vector<std::unique_ptr<const DexFile>> dex_files;
897 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
898 EXPECT_EQ(1u, dex_files.size());
899}
900
901// Case: We have a DEX file and a PIC ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700902// Expect: The status is kNoDexOptNeeded, because PIC needs no relocation.
Richard Uhler66d874d2015-01-15 09:37:19 -0800903TEST_F(OatFileAssistantTest, DexPicOdexNoOat) {
904 std::string dex_location = GetScratchDir() + "/DexPicOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700905 std::string odex_location = GetOdexDir() + "/DexPicOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800906
907 // Create the dex and odex files
908 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000909 GeneratePicOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800910
911 // Verify the status.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000912 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800913
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000914 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
915 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
916 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
917 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
Richard Uhler66d874d2015-01-15 09:37:19 -0800918
919 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
920 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
921 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
922 EXPECT_TRUE(oat_file_assistant.OdexFileIsUpToDate());
923 EXPECT_FALSE(oat_file_assistant.OatFileExists());
924 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
925 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700926 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800927}
928
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000929// Case: We have a DEX file and a VerifyAtRuntime ODEX file, but no OAT file.
930// Expect: The status is kNoDexOptNeeded, because VerifyAtRuntime contains no code.
931TEST_F(OatFileAssistantTest, DexVerifyAtRuntimeOdexNoOat) {
932 std::string dex_location = GetScratchDir() + "/DexVerifyAtRuntimeOdexNoOat.jar";
933 std::string odex_location = GetOdexDir() + "/DexVerifyAtRuntimeOdexNoOat.odex";
David Brazdilce4b0ba2016-01-28 15:05:49 +0000934
935 // Create the dex and odex files
936 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000937 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kVerifyAtRuntime);
David Brazdilce4b0ba2016-01-28 15:05:49 +0000938
939 // Verify the status.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000940 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
David Brazdilce4b0ba2016-01-28 15:05:49 +0000941
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000942 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
943 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
944 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
945 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
David Brazdilce4b0ba2016-01-28 15:05:49 +0000946
947 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
948 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
949 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
950 EXPECT_TRUE(oat_file_assistant.OdexFileIsUpToDate());
951 EXPECT_FALSE(oat_file_assistant.OatFileExists());
952 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
953 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
954 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
955}
956
Richard Uhler66d874d2015-01-15 09:37:19 -0800957// Case: We have a DEX file and up-to-date OAT file for it.
958// Expect: We should load an executable dex file.
959TEST_F(OatFileAssistantTest, LoadOatUpToDate) {
960 std::string dex_location = GetScratchDir() + "/LoadOatUpToDate.jar";
961
962 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000963 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800964
965 // Load the oat using an oat file assistant.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000966 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
967
968 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
969 ASSERT_TRUE(oat_file.get() != nullptr);
970 EXPECT_TRUE(oat_file->IsExecutable());
971 std::vector<std::unique_ptr<const DexFile>> dex_files;
972 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
973 EXPECT_EQ(1u, dex_files.size());
974}
975
976// Case: We have a DEX file and up-to-date interpret-only OAT file for it.
977// Expect: We should still load the oat file as executable.
978TEST_F(OatFileAssistantTest, LoadExecInterpretOnlyOatUpToDate) {
979 std::string dex_location = GetScratchDir() + "/LoadExecInterpretOnlyOatUpToDate.jar";
980
981 Copy(GetDexSrc1(), dex_location);
982 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kInterpretOnly);
983
984 // Load the oat using an oat file assistant.
985 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800986
987 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
988 ASSERT_TRUE(oat_file.get() != nullptr);
989 EXPECT_TRUE(oat_file->IsExecutable());
990 std::vector<std::unique_ptr<const DexFile>> dex_files;
991 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
992 EXPECT_EQ(1u, dex_files.size());
993}
994
995// Case: We have a DEX file and up-to-date OAT file for it.
996// Expect: Loading non-executable should load the oat non-executable.
997TEST_F(OatFileAssistantTest, LoadNoExecOatUpToDate) {
998 std::string dex_location = GetScratchDir() + "/LoadNoExecOatUpToDate.jar";
999
1000 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001001 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001002
1003 // Load the oat using an oat file assistant.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001004 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
Richard Uhler66d874d2015-01-15 09:37:19 -08001005
1006 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1007 ASSERT_TRUE(oat_file.get() != nullptr);
1008 EXPECT_FALSE(oat_file->IsExecutable());
1009 std::vector<std::unique_ptr<const DexFile>> dex_files;
1010 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1011 EXPECT_EQ(1u, dex_files.size());
1012}
1013
1014// Case: We have a DEX file.
1015// Expect: We should load an executable dex file from an alternative oat
1016// location.
1017TEST_F(OatFileAssistantTest, LoadDexNoAlternateOat) {
1018 std::string dex_location = GetScratchDir() + "/LoadDexNoAlternateOat.jar";
1019 std::string oat_location = GetScratchDir() + "/LoadDexNoAlternateOat.oat";
1020
1021 Copy(GetDexSrc1(), dex_location);
1022
1023 OatFileAssistant oat_file_assistant(
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001024 dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001025 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001026 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(CompilerFilter::kSpeed, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -08001027
1028 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1029 ASSERT_TRUE(oat_file.get() != nullptr);
1030 EXPECT_TRUE(oat_file->IsExecutable());
1031 std::vector<std::unique_ptr<const DexFile>> dex_files;
1032 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1033 EXPECT_EQ(1u, dex_files.size());
1034
1035 EXPECT_TRUE(OS::FileExists(oat_location.c_str()));
1036
1037 // Verify it didn't create an oat in the default location.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001038 OatFileAssistant ofm(dex_location.c_str(), kRuntimeISA, false, false);
Richard Uhler66d874d2015-01-15 09:37:19 -08001039 EXPECT_FALSE(ofm.OatFileExists());
1040}
1041
Richard Uhler8327cf72015-10-13 16:34:59 -07001042// Case: We have a DEX file but can't write the oat file.
1043// Expect: We should fail to make the oat file up to date.
1044TEST_F(OatFileAssistantTest, LoadDexUnwriteableAlternateOat) {
1045 std::string dex_location = GetScratchDir() + "/LoadDexUnwriteableAlternateOat.jar";
1046
1047 // Make the oat location unwritable by inserting some non-existent
1048 // intermediate directories.
1049 std::string oat_location = GetScratchDir() + "/foo/bar/LoadDexUnwriteableAlternateOat.oat";
1050
1051 Copy(GetDexSrc1(), dex_location);
1052
1053 OatFileAssistant oat_file_assistant(
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001054 dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true);
Richard Uhler8327cf72015-10-13 16:34:59 -07001055 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001056 ASSERT_FALSE(oat_file_assistant.MakeUpToDate(CompilerFilter::kSpeed, &error_msg));
Richard Uhler8327cf72015-10-13 16:34:59 -07001057
1058 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1059 ASSERT_TRUE(oat_file.get() == nullptr);
1060}
1061
1062// Case: We don't have a DEX file and can't write the oat file.
1063// Expect: We should fail to generate the oat file without crashing.
1064TEST_F(OatFileAssistantTest, GenNoDex) {
1065 std::string dex_location = GetScratchDir() + "/GenNoDex.jar";
1066 std::string oat_location = GetScratchDir() + "/GenNoDex.oat";
1067
1068 OatFileAssistant oat_file_assistant(
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001069 dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true);
Richard Uhler8327cf72015-10-13 16:34:59 -07001070 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001071 ASSERT_FALSE(oat_file_assistant.GenerateOatFile(CompilerFilter::kSpeed, &error_msg));
Richard Uhler8327cf72015-10-13 16:34:59 -07001072}
1073
Richard Uhler66d874d2015-01-15 09:37:19 -08001074// Turn an absolute path into a path relative to the current working
1075// directory.
1076static std::string MakePathRelative(std::string target) {
1077 char buf[MAXPATHLEN];
1078 std::string cwd = getcwd(buf, MAXPATHLEN);
1079
1080 // Split the target and cwd paths into components.
1081 std::vector<std::string> target_path;
1082 std::vector<std::string> cwd_path;
1083 Split(target, '/', &target_path);
1084 Split(cwd, '/', &cwd_path);
1085
1086 // Reverse the path components, so we can use pop_back().
1087 std::reverse(target_path.begin(), target_path.end());
1088 std::reverse(cwd_path.begin(), cwd_path.end());
1089
1090 // Drop the common prefix of the paths. Because we reversed the path
1091 // components, this becomes the common suffix of target_path and cwd_path.
1092 while (!target_path.empty() && !cwd_path.empty()
1093 && target_path.back() == cwd_path.back()) {
1094 target_path.pop_back();
1095 cwd_path.pop_back();
1096 }
1097
1098 // For each element of the remaining cwd_path, add '..' to the beginning
1099 // of the target path. Because we reversed the path components, we add to
1100 // the end of target_path.
1101 for (unsigned int i = 0; i < cwd_path.size(); i++) {
1102 target_path.push_back("..");
1103 }
1104
1105 // Reverse again to get the right path order, and join to get the result.
1106 std::reverse(target_path.begin(), target_path.end());
1107 return Join(target_path, '/');
1108}
1109
1110// Case: Non-absolute path to Dex location.
1111// Expect: Not sure, but it shouldn't crash.
1112TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) {
1113 std::string abs_dex_location = GetScratchDir() + "/NonAbsoluteDexLocation.jar";
1114 Copy(GetDexSrc1(), abs_dex_location);
1115
1116 std::string dex_location = MakePathRelative(abs_dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001117 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001118
1119 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001120 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
1121 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -08001122 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
1123 EXPECT_FALSE(oat_file_assistant.OatFileExists());
1124 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
1125 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
1126 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
1127 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
1128}
1129
1130// Case: Very short, non-existent Dex location.
Richard Uhler9b994ea2015-06-24 08:44:19 -07001131// Expect: kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -08001132TEST_F(OatFileAssistantTest, ShortDexLocation) {
1133 std::string dex_location = "/xx";
1134
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001135 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001136
1137 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001138 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
1139 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -08001140 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
1141 EXPECT_FALSE(oat_file_assistant.OatFileExists());
1142 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
1143 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
1144 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
1145 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -07001146 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -08001147
Richard Uhler9b994ea2015-06-24 08:44:19 -07001148 // Trying to make it up to date should have no effect.
Richard Uhler66d874d2015-01-15 09:37:19 -08001149 std::string error_msg;
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001150 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(CompilerFilter::kSpeed, &error_msg));
Richard Uhler9b994ea2015-06-24 08:44:19 -07001151 EXPECT_TRUE(error_msg.empty());
Richard Uhler66d874d2015-01-15 09:37:19 -08001152}
1153
1154// Case: Non-standard extension for dex file.
Richard Uhler95abd042015-03-24 09:51:28 -07001155// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -08001156TEST_F(OatFileAssistantTest, LongDexExtension) {
1157 std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx";
1158 Copy(GetDexSrc1(), dex_location);
1159
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001160 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false);
Richard Uhler66d874d2015-01-15 09:37:19 -08001161
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001162 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
1163 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -08001164
1165 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
1166 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
1167 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
1168 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
1169 EXPECT_FALSE(oat_file_assistant.OatFileExists());
1170 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
1171 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
1172}
1173
1174// A task to generate a dex location. Used by the RaceToGenerate test.
1175class RaceGenerateTask : public Task {
1176 public:
1177 explicit RaceGenerateTask(const std::string& dex_location, const std::string& oat_location)
1178 : dex_location_(dex_location), oat_location_(oat_location),
1179 loaded_oat_file_(nullptr)
1180 {}
1181
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001182 void Run(Thread* self ATTRIBUTE_UNUSED) {
Richard Uhler66d874d2015-01-15 09:37:19 -08001183 // Load the dex files, and save a pointer to the loaded oat file, so that
1184 // we can verify only one oat file was loaded for the dex location.
Richard Uhler66d874d2015-01-15 09:37:19 -08001185 std::vector<std::unique_ptr<const DexFile>> dex_files;
1186 std::vector<std::string> error_msgs;
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001187 const OatFile* oat_file = nullptr;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001188 dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat(
1189 dex_location_.c_str(),
1190 oat_location_.c_str(),
Mathieu Chartierfbc31082016-01-24 11:59:56 -08001191 /*class_loader*/nullptr,
1192 /*dex_elements*/nullptr,
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001193 &oat_file,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001194 &error_msgs);
Richard Uhler66d874d2015-01-15 09:37:19 -08001195 CHECK(!dex_files.empty()) << Join(error_msgs, '\n');
Richard Uhler07b3c232015-03-31 15:57:54 -07001196 CHECK(dex_files[0]->GetOatDexFile() != nullptr) << dex_files[0]->GetLocation();
1197 loaded_oat_file_ = dex_files[0]->GetOatDexFile()->GetOatFile();
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001198 CHECK_EQ(loaded_oat_file_, oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001199 }
1200
1201 const OatFile* GetLoadedOatFile() const {
1202 return loaded_oat_file_;
1203 }
1204
1205 private:
1206 std::string dex_location_;
1207 std::string oat_location_;
1208 const OatFile* loaded_oat_file_;
1209};
1210
1211// Test the case where multiple processes race to generate an oat file.
1212// This simulates multiple processes using multiple threads.
1213//
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001214// We want unique Oat files to be loaded even when there is a race to load.
1215// TODO: The test case no longer tests locking the way it was intended since we now get multiple
1216// copies of the same Oat files mapped at different locations.
Richard Uhler66d874d2015-01-15 09:37:19 -08001217TEST_F(OatFileAssistantTest, RaceToGenerate) {
1218 std::string dex_location = GetScratchDir() + "/RaceToGenerate.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001219 std::string oat_location = GetOdexDir() + "/RaceToGenerate.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -08001220
1221 // We use the lib core dex file, because it's large, and hopefully should
1222 // take a while to generate.
Narayan Kamathd1ef4362015-11-12 11:49:06 +00001223 Copy(GetLibCoreDexFileNames()[0], dex_location);
Richard Uhler66d874d2015-01-15 09:37:19 -08001224
1225 const int kNumThreads = 32;
1226 Thread* self = Thread::Current();
1227 ThreadPool thread_pool("Oat file assistant test thread pool", kNumThreads);
1228 std::vector<std::unique_ptr<RaceGenerateTask>> tasks;
1229 for (int i = 0; i < kNumThreads; i++) {
1230 std::unique_ptr<RaceGenerateTask> task(new RaceGenerateTask(dex_location, oat_location));
1231 thread_pool.AddTask(self, task.get());
1232 tasks.push_back(std::move(task));
1233 }
1234 thread_pool.StartWorkers(self);
1235 thread_pool.Wait(self, true, false);
1236
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001237 // Verify every task got a unique oat file.
1238 std::set<const OatFile*> oat_files;
Richard Uhler66d874d2015-01-15 09:37:19 -08001239 for (auto& task : tasks) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001240 const OatFile* oat_file = task->GetLoadedOatFile();
1241 EXPECT_TRUE(oat_files.find(oat_file) == oat_files.end());
1242 oat_files.insert(oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001243 }
1244}
1245
1246// Case: We have a DEX file and an ODEX file, no OAT file, and dex2oat is
1247// disabled.
1248// Expect: We should load the odex file non-executable.
1249TEST_F(OatFileAssistantNoDex2OatTest, LoadDexOdexNoOat) {
1250 std::string dex_location = GetScratchDir() + "/LoadDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001251 std::string odex_location = GetOdexDir() + "/LoadDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001252
1253 // Create the dex and odex files
1254 Copy(GetDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001255 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001256
1257 // Load the oat using an executable oat file assistant.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001258 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001259
1260 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1261 ASSERT_TRUE(oat_file.get() != nullptr);
1262 EXPECT_FALSE(oat_file->IsExecutable());
1263 std::vector<std::unique_ptr<const DexFile>> dex_files;
1264 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1265 EXPECT_EQ(1u, dex_files.size());
1266}
1267
1268// Case: We have a MultiDEX file and an ODEX file, no OAT file, and dex2oat is
1269// disabled.
1270// Expect: We should load the odex file non-executable.
1271TEST_F(OatFileAssistantNoDex2OatTest, LoadMultiDexOdexNoOat) {
1272 std::string dex_location = GetScratchDir() + "/LoadMultiDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001273 std::string odex_location = GetOdexDir() + "/LoadMultiDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001274
1275 // Create the dex and odex files
1276 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001277 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001278
1279 // Load the oat using an executable oat file assistant.
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001280 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001281
1282 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1283 ASSERT_TRUE(oat_file.get() != nullptr);
1284 EXPECT_FALSE(oat_file->IsExecutable());
1285 std::vector<std::unique_ptr<const DexFile>> dex_files;
1286 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1287 EXPECT_EQ(2u, dex_files.size());
1288}
1289
1290TEST(OatFileAssistantUtilsTest, DexFilenameToOdexFilename) {
1291 std::string error_msg;
1292 std::string odex_file;
1293
1294 EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001295 "/foo/bar/baz.jar", kArm, &odex_file, &error_msg)) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001296 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001297
1298 EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001299 "/foo/bar/baz.funnyext", kArm, &odex_file, &error_msg)) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001300 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001301
1302 EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001303 "nopath.jar", kArm, &odex_file, &error_msg));
Richard Uhler66d874d2015-01-15 09:37:19 -08001304 EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001305 "/foo/bar/baz_noext", kArm, &odex_file, &error_msg));
Richard Uhler66d874d2015-01-15 09:37:19 -08001306}
1307
Richard Uhler23cedd22015-04-08 13:17:29 -07001308// Verify the dexopt status values from dalvik.system.DexFile
1309// match the OatFileAssistant::DexOptStatus values.
1310TEST_F(OatFileAssistantTest, DexOptStatusValues) {
1311 ScopedObjectAccess soa(Thread::Current());
1312 StackHandleScope<1> hs(soa.Self());
1313 ClassLinker* linker = Runtime::Current()->GetClassLinker();
1314 Handle<mirror::Class> dexfile(
1315 hs.NewHandle(linker->FindSystemClass(soa.Self(), "Ldalvik/system/DexFile;")));
1316 ASSERT_FALSE(dexfile.Get() == nullptr);
1317 linker->EnsureInitialized(soa.Self(), dexfile, true, true);
1318
Mathieu Chartierc7853442015-03-27 14:35:38 -07001319 ArtField* no_dexopt_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001320 soa.Self(), dexfile, "NO_DEXOPT_NEEDED", "I");
1321 ASSERT_FALSE(no_dexopt_needed == nullptr);
1322 EXPECT_EQ(no_dexopt_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1323 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, no_dexopt_needed->GetInt(dexfile.Get()));
1324
Mathieu Chartierc7853442015-03-27 14:35:38 -07001325 ArtField* dex2oat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001326 soa.Self(), dexfile, "DEX2OAT_NEEDED", "I");
1327 ASSERT_FALSE(dex2oat_needed == nullptr);
1328 EXPECT_EQ(dex2oat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1329 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, dex2oat_needed->GetInt(dexfile.Get()));
1330
Mathieu Chartierc7853442015-03-27 14:35:38 -07001331 ArtField* patchoat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001332 soa.Self(), dexfile, "PATCHOAT_NEEDED", "I");
1333 ASSERT_FALSE(patchoat_needed == nullptr);
1334 EXPECT_EQ(patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1335 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, patchoat_needed->GetInt(dexfile.Get()));
1336
Mathieu Chartierc7853442015-03-27 14:35:38 -07001337 ArtField* self_patchoat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001338 soa.Self(), dexfile, "SELF_PATCHOAT_NEEDED", "I");
1339 ASSERT_FALSE(self_patchoat_needed == nullptr);
1340 EXPECT_EQ(self_patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1341 EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded, self_patchoat_needed->GetInt(dexfile.Get()));
1342}
Richard Uhler66d874d2015-01-15 09:37:19 -08001343
1344// TODO: More Tests:
Andreas Gampe7bcfcb82016-03-23 15:31:51 +00001345// * Image checksum change is out of date for kIntepretOnly, but not
1346// kVerifyAtRuntime. But target of kVerifyAtRuntime still says current
1347// kInterpretOnly is out of date.
Richard Uhler66d874d2015-01-15 09:37:19 -08001348// * Test class linker falls back to unquickened dex for DexNoOat
1349// * Test class linker falls back to unquickened dex for MultiDexNoOat
Richard Uhler66d874d2015-01-15 09:37:19 -08001350// * Test using secondary isa
Richard Uhler66d874d2015-01-15 09:37:19 -08001351// * Test for status of oat while oat is being generated (how?)
1352// * Test case where 32 and 64 bit boot class paths differ,
1353// and we ask IsInBootClassPath for a class in exactly one of the 32 or
1354// 64 bit boot class paths.
1355// * Test unexpected scenarios (?):
1356// - Dex is stripped, don't have odex.
1357// - Oat file corrupted after status check, before reload unexecutable
1358// because it's unrelocated and no dex2oat
Calin Juravled91b8a22016-02-18 18:47:37 +00001359// * Test unrelocated specific target compilation type can be relocated to
1360// make it up to date.
Richard Uhler66d874d2015-01-15 09:37:19 -08001361
1362} // namespace art