blob: 39848b4afeeedd759d56cc465746e9894ee02a7c [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
Richard Uhler66d874d2015-01-15 09:37:19 -080017#include <algorithm>
18#include <fstream>
19#include <string>
20#include <vector>
21#include <sys/param.h>
22
23#include <backtrace/BacktraceMap.h>
24#include <gtest/gtest.h>
25
Mathieu Chartierc7853442015-03-27 14:35:38 -070026#include "art_field-inl.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010027#include "class_linker-inl.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080028#include "common_runtime_test.h"
Andreas Gampebb9c6b12015-03-29 13:56:36 -070029#include "compiler_callbacks.h"
Andreas Gampee1459ae2016-06-29 09:36:30 -070030#include "dex2oat_environment_test.h"
Richard Uhlerf16d5722015-05-11 09:32:47 -070031#include "gc/space/image_space.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080032#include "mem_map.h"
Andreas Gampee1459ae2016-06-29 09:36:30 -070033#include "oat_file_assistant.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
Andreas Gampee1459ae2016-06-29 09:36:30 -070042class OatFileAssistantTest : public Dex2oatEnvironmentTest {
Richard Uhler66d874d2015-01-15 09:37:19 -080043 public:
Andreas Gampee1459ae2016-06-29 09:36:30 -070044 virtual void SetUp() OVERRIDE {
Richard Uhler66d874d2015-01-15 09:37:19 -080045 ReserveImageSpace();
Andreas Gampee1459ae2016-06-29 09:36:30 -070046 Dex2oatEnvironmentTest::SetUp();
Richard Uhler66d874d2015-01-15 09:37:19 -080047 }
48
Richard Uhlera48403e2016-04-26 10:24:38 -070049 // Pre-Relocate the image to a known non-zero offset so we don't have to
50 // deal with the runtime randomly relocating the image by 0 and messing up
51 // the expected results of the tests.
52 bool PreRelocateImage(std::string* error_msg) {
53 std::string image;
54 if (!GetCachedImageFile(&image, error_msg)) {
55 return false;
56 }
57
58 std::string patchoat = GetAndroidRoot();
59 patchoat += kIsDebugBuild ? "/bin/patchoatd" : "/bin/patchoat";
60
61 std::vector<std::string> argv;
62 argv.push_back(patchoat);
63 argv.push_back("--input-image-location=" + GetImageLocation());
64 argv.push_back("--output-image-file=" + image);
65 argv.push_back("--instruction-set=" + std::string(GetInstructionSetString(kRuntimeISA)));
66 argv.push_back("--base-offset-delta=0x00008000");
67 return Exec(argv, error_msg);
68 }
69
Richard Uhler66d874d2015-01-15 09:37:19 -080070 virtual void PreRuntimeCreate() {
Richard Uhlera48403e2016-04-26 10:24:38 -070071 std::string error_msg;
72 ASSERT_TRUE(PreRelocateImage(&error_msg)) << error_msg;
73
Richard Uhler66d874d2015-01-15 09:37:19 -080074 UnreserveImageSpace();
75 }
76
Andreas Gampee1459ae2016-06-29 09:36:30 -070077 virtual void PostRuntimeCreate() OVERRIDE {
Richard Uhler66d874d2015-01-15 09:37:19 -080078 ReserveImageSpace();
79 }
80
Richard Uhler93aa2102015-08-10 14:47:41 -070081 // Generate a non-PIC odex file for the purposes of test.
Richard Uhler94f5bda2015-07-22 08:25:11 -070082 // The generated odex file will be un-relocated.
Richard Uhler66d874d2015-01-15 09:37:19 -080083 void GenerateOdexForTest(const std::string& dex_location,
Andreas Gampe29d38e72016-03-23 15:31:51 +000084 const std::string& odex_location,
Richard Uhlera48403e2016-04-26 10:24:38 -070085 CompilerFilter::Filter filter,
86 bool pic = false,
87 bool with_patch_info = true) {
88 // Temporarily redirect the dalvik cache so dex2oat doesn't find the
89 // relocated image file.
90 std::string android_data_tmp = GetScratchDir() + "AndroidDataTmp";
91 setenv("ANDROID_DATA", android_data_tmp.c_str(), 1);
Richard Uhler93aa2102015-08-10 14:47:41 -070092 std::vector<std::string> args;
93 args.push_back("--dex-file=" + dex_location);
Richard Uhlera48403e2016-04-26 10:24:38 -070094 args.push_back("--oat-file=" + odex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +000095 args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter));
Richard Uhlera48403e2016-04-26 10:24:38 -070096 args.push_back("--runtime-arg");
97 args.push_back("-Xnorelocate");
Richard Uhler93aa2102015-08-10 14:47:41 -070098
Richard Uhlera48403e2016-04-26 10:24:38 -070099 if (pic) {
100 args.push_back("--compile-pic");
101 }
102
103 if (with_patch_info) {
104 args.push_back("--include-patch-information");
105 }
Richard Uhler93aa2102015-08-10 14:47:41 -0700106
107 std::string error_msg;
108 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
Richard Uhlera48403e2016-04-26 10:24:38 -0700109 setenv("ANDROID_DATA", android_data_.c_str(), 1);
Richard Uhler93aa2102015-08-10 14:47:41 -0700110
111 // Verify the odex file was generated as expected and really is
112 // unrelocated.
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800113 std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
114 odex_location.c_str(),
115 nullptr,
116 nullptr,
117 false,
118 /*low_4gb*/false,
119 dex_location.c_str(),
120 &error_msg));
Richard Uhler93aa2102015-08-10 14:47:41 -0700121 ASSERT_TRUE(odex_file.get() != nullptr) << error_msg;
Richard Uhlera48403e2016-04-26 10:24:38 -0700122 EXPECT_EQ(pic, odex_file->IsPic());
123 EXPECT_EQ(with_patch_info, odex_file->HasPatchInfo());
Andreas Gampe29d38e72016-03-23 15:31:51 +0000124 EXPECT_EQ(filter, odex_file->GetCompilerFilter());
125
Vladimir Markof6d1e0f2016-05-23 15:32:42 +0100126 if (CompilerFilter::IsBytecodeCompilationEnabled(filter)) {
Andreas Gampe29d38e72016-03-23 15:31:51 +0000127 const std::vector<gc::space::ImageSpace*> image_spaces =
Richard Uhlera48403e2016-04-26 10:24:38 -0700128 Runtime::Current()->GetHeap()->GetBootImageSpaces();
Andreas Gampe29d38e72016-03-23 15:31:51 +0000129 ASSERT_TRUE(!image_spaces.empty() && image_spaces[0] != nullptr);
130 const ImageHeader& image_header = image_spaces[0]->GetImageHeader();
131 const OatHeader& oat_header = odex_file->GetOatHeader();
Jeff Haob11ffb72016-04-07 15:40:54 -0700132 uint32_t combined_checksum = OatFileAssistant::CalculateCombinedImageChecksum();
133 EXPECT_EQ(combined_checksum, oat_header.GetImageFileLocationOatChecksum());
Andreas Gampe29d38e72016-03-23 15:31:51 +0000134 EXPECT_NE(reinterpret_cast<uintptr_t>(image_header.GetOatDataBegin()),
135 oat_header.GetImageFileLocationOatDataBegin());
136 EXPECT_NE(image_header.GetPatchDelta(), oat_header.GetImagePatchDelta());
137 }
Richard Uhler93aa2102015-08-10 14:47:41 -0700138 }
139
140 void GeneratePicOdexForTest(const std::string& dex_location,
Andreas Gampe29d38e72016-03-23 15:31:51 +0000141 const std::string& odex_location,
142 CompilerFilter::Filter filter) {
Richard Uhlera48403e2016-04-26 10:24:38 -0700143 GenerateOdexForTest(dex_location, odex_location, filter, true, false);
Calin Juravleb077e152016-02-18 18:47:37 +0000144 }
David Brazdilce4b0ba2016-01-28 15:05:49 +0000145
Richard Uhlerd1537b52016-03-29 13:27:41 -0700146 // Generate a non-PIC odex file without patch information for the purposes
147 // of test. The generated odex file will be un-relocated.
Richard Uhlerd1537b52016-03-29 13:27:41 -0700148 void GenerateNoPatchOdexForTest(const std::string& dex_location,
149 const std::string& odex_location,
150 CompilerFilter::Filter filter) {
Richard Uhlera48403e2016-04-26 10:24:38 -0700151 GenerateOdexForTest(dex_location, odex_location, filter, false, false);
Richard Uhlerd1537b52016-03-29 13:27:41 -0700152 }
153
Richard Uhler66d874d2015-01-15 09:37:19 -0800154 private:
155 // Reserve memory around where the image will be loaded so other memory
156 // won't conflict when it comes time to load the image.
157 // This can be called with an already loaded image to reserve the space
158 // around it.
159 void ReserveImageSpace() {
160 MemMap::Init();
161
162 // Ensure a chunk of memory is reserved for the image space.
Richard Uhlera48403e2016-04-26 10:24:38 -0700163 // The reservation_end includes room for the main space that has to come
164 // right after the image in case of the GSS collector.
165 uintptr_t reservation_start = ART_BASE_ADDRESS;
166 uintptr_t reservation_end = ART_BASE_ADDRESS + 384 * MB;
Richard Uhler66d874d2015-01-15 09:37:19 -0800167
Richard Uhler66d874d2015-01-15 09:37:19 -0800168 std::unique_ptr<BacktraceMap> map(BacktraceMap::Create(getpid(), true));
169 ASSERT_TRUE(map.get() != nullptr) << "Failed to build process map";
170 for (BacktraceMap::const_iterator it = map->begin();
171 reservation_start < reservation_end && it != map->end(); ++it) {
Richard Uhler3efe9792015-03-30 16:18:03 -0700172 ReserveImageSpaceChunk(reservation_start, std::min(it->start, reservation_end));
173 reservation_start = std::max(reservation_start, it->end);
174 }
175 ReserveImageSpaceChunk(reservation_start, reservation_end);
176 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800177
Richard Uhler3efe9792015-03-30 16:18:03 -0700178 // Reserve a chunk of memory for the image space in the given range.
179 // Only has effect for chunks with a positive number of bytes.
180 void ReserveImageSpaceChunk(uintptr_t start, uintptr_t end) {
181 if (start < end) {
182 std::string error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800183 image_reservation_.push_back(std::unique_ptr<MemMap>(
184 MemMap::MapAnonymous("image reservation",
Richard Uhler3efe9792015-03-30 16:18:03 -0700185 reinterpret_cast<uint8_t*>(start), end - start,
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700186 PROT_NONE, false, false, &error_msg)));
Richard Uhler66d874d2015-01-15 09:37:19 -0800187 ASSERT_TRUE(image_reservation_.back().get() != nullptr) << error_msg;
188 LOG(INFO) << "Reserved space for image " <<
189 reinterpret_cast<void*>(image_reservation_.back()->Begin()) << "-" <<
190 reinterpret_cast<void*>(image_reservation_.back()->End());
Richard Uhler66d874d2015-01-15 09:37:19 -0800191 }
192 }
193
194
195 // Unreserve any memory reserved by ReserveImageSpace. This should be called
196 // before the image is loaded.
197 void UnreserveImageSpace() {
198 image_reservation_.clear();
199 }
200
Richard Uhler66d874d2015-01-15 09:37:19 -0800201 std::vector<std::unique_ptr<MemMap>> image_reservation_;
202};
203
204class OatFileAssistantNoDex2OatTest : public OatFileAssistantTest {
205 public:
206 virtual void SetUpRuntimeOptions(RuntimeOptions* options) {
207 OatFileAssistantTest::SetUpRuntimeOptions(options);
208 options->push_back(std::make_pair("-Xnodex2oat", nullptr));
209 }
210};
211
212// Generate an oat file for the purposes of test, as opposed to testing
213// generation of oat files.
Andreas Gampe29d38e72016-03-23 15:31:51 +0000214static void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter) {
215 // Use an oat file assistant to find the proper oat location.
Richard Uhlerb81881d2016-04-19 13:08:04 -0700216 std::string oat_location;
217 std::string error_msg;
218 ASSERT_TRUE(OatFileAssistant::DexLocationToOatFilename(
219 dex_location, kRuntimeISA, &oat_location, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800220
Andreas Gampe29d38e72016-03-23 15:31:51 +0000221 std::vector<std::string> args;
222 args.push_back("--dex-file=" + std::string(dex_location));
Richard Uhlerb81881d2016-04-19 13:08:04 -0700223 args.push_back("--oat-file=" + oat_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000224 args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter));
225 args.push_back("--runtime-arg");
226 args.push_back("-Xnorelocate");
Andreas Gampe29d38e72016-03-23 15:31:51 +0000227 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
228
229 // Verify the oat file was generated as expected.
Richard Uhlerb81881d2016-04-19 13:08:04 -0700230 std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location.c_str(),
231 oat_location.c_str(),
Andreas Gampe29d38e72016-03-23 15:31:51 +0000232 nullptr,
233 nullptr,
234 false,
235 /*low_4gb*/false,
236 dex_location,
237 &error_msg));
238 ASSERT_TRUE(oat_file.get() != nullptr) << error_msg;
239 EXPECT_EQ(filter, oat_file->GetCompilerFilter());
Richard Uhler66d874d2015-01-15 09:37:19 -0800240}
241
242// Case: We have a DEX file, but no OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700243// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800244TEST_F(OatFileAssistantTest, DexNoOat) {
245 std::string dex_location = GetScratchDir() + "/DexNoOat.jar";
246 Copy(GetDexSrc1(), dex_location);
247
Richard Uhlerd1472a22016-04-15 15:18:56 -0700248 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800249
Andreas Gampe29d38e72016-03-23 15:31:51 +0000250 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
251 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
252 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
253 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
254 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
255 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile));
256 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
257 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800258
259 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
260 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
261 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
262 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
263 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700264 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OdexFileStatus());
Richard Uhler66d874d2015-01-15 09:37:19 -0800265 EXPECT_FALSE(oat_file_assistant.OatFileExists());
266 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
267 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
268 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700269 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OatFileStatus());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700270 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800271}
272
273// Case: We have no DEX file and no OAT file.
Richard Uhler9b994ea2015-06-24 08:44:19 -0700274// Expect: Status is kNoDexOptNeeded. Loading should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800275TEST_F(OatFileAssistantTest, NoDexNoOat) {
276 std::string dex_location = GetScratchDir() + "/NoDexNoOat.jar";
277
Richard Uhlerd1472a22016-04-15 15:18:56 -0700278 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800279
Andreas Gampe29d38e72016-03-23 15:31:51 +0000280 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
281 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700282 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
283
284 // Trying to make the oat file up to date should not fail or crash.
285 std::string error_msg;
Richard Uhlerd1472a22016-04-15 15:18:56 -0700286 EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, oat_file_assistant.MakeUpToDate(false, &error_msg));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700287
288 // Trying to get the best oat file should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800289 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
290 EXPECT_EQ(nullptr, oat_file.get());
291}
292
293// Case: We have a DEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700294// Expect: The status is kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800295TEST_F(OatFileAssistantTest, OatUpToDate) {
296 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
297 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000298 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800299
Richard Uhlerd1472a22016-04-15 15:18:56 -0700300 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800301
Andreas Gampe29d38e72016-03-23 15:31:51 +0000302 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
303 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
304 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
305 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
306 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
307 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
308 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
309 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
310
Richard Uhler66d874d2015-01-15 09:37:19 -0800311 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
312 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
313 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
314 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
315 EXPECT_TRUE(oat_file_assistant.OatFileExists());
316 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
317 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
318 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700319 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700320 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800321}
322
Andreas Gampe29d38e72016-03-23 15:31:51 +0000323// Case: We have a DEX file and speed-profile OAT file for it.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700324// Expect: The status is kNoDexOptNeeded if the profile hasn't changed, but
325// kDex2Oat if the profile has changed.
Andreas Gampe29d38e72016-03-23 15:31:51 +0000326TEST_F(OatFileAssistantTest, ProfileOatUpToDate) {
327 std::string dex_location = GetScratchDir() + "/ProfileOatUpToDate.jar";
328 Copy(GetDexSrc1(), dex_location);
329 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile);
330
Richard Uhlerd1472a22016-04-15 15:18:56 -0700331 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000332
333 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700334 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile, false));
Andreas Gampe29d38e72016-03-23 15:31:51 +0000335 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700336 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly, false));
337 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
338 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile, true));
339 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
340 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly, true));
Andreas Gampe29d38e72016-03-23 15:31:51 +0000341
342 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
343 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
344 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
345 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
346 EXPECT_TRUE(oat_file_assistant.OatFileExists());
347 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
348 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
349 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
350 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
351 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
352}
353
Richard Uhler66d874d2015-01-15 09:37:19 -0800354// Case: We have a MultiDEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700355// Expect: The status is kNoDexOptNeeded and we load all dex files.
Richard Uhler66d874d2015-01-15 09:37:19 -0800356TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) {
357 std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar";
358 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000359 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800360
Richard Uhlerd1472a22016-04-15 15:18:56 -0700361 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000362 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700363 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed, false));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700364 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700365
366 // Verify we can load both dex files.
Richard Uhlere5fed032015-03-18 08:21:11 -0700367 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
Richard Uhler66d874d2015-01-15 09:37:19 -0800368 ASSERT_TRUE(oat_file.get() != nullptr);
369 EXPECT_TRUE(oat_file->IsExecutable());
370 std::vector<std::unique_ptr<const DexFile>> dex_files;
Richard Uhlere5fed032015-03-18 08:21:11 -0700371 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
372 EXPECT_EQ(2u, dex_files.size());
373}
374
Richard Uhler67ff7d12015-05-14 13:21:13 -0700375// Case: We have a MultiDEX file where the secondary dex file is out of date.
376// Expect: The status is kDex2OatNeeded.
377TEST_F(OatFileAssistantTest, MultiDexSecondaryOutOfDate) {
378 std::string dex_location = GetScratchDir() + "/MultiDexSecondaryOutOfDate.jar";
379
380 // Compile code for GetMultiDexSrc1.
381 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000382 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler67ff7d12015-05-14 13:21:13 -0700383
384 // Now overwrite the dex file with GetMultiDexSrc2 so the secondary checksum
385 // is out of date.
386 Copy(GetMultiDexSrc2(), dex_location);
387
Richard Uhlerd1472a22016-04-15 15:18:56 -0700388 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000389 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700390 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed, false));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700391 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler67ff7d12015-05-14 13:21:13 -0700392}
393
Richard Uhlere5fed032015-03-18 08:21:11 -0700394// Case: We have a MultiDEX file and up-to-date OAT file for it with relative
395// encoded dex locations.
Richard Uhler95abd042015-03-24 09:51:28 -0700396// Expect: The oat file status is kNoDexOptNeeded.
Richard Uhlere5fed032015-03-18 08:21:11 -0700397TEST_F(OatFileAssistantTest, RelativeEncodedDexLocation) {
398 std::string dex_location = GetScratchDir() + "/RelativeEncodedDexLocation.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700399 std::string oat_location = GetOdexDir() + "/RelativeEncodedDexLocation.oat";
Richard Uhlere5fed032015-03-18 08:21:11 -0700400
401 // Create the dex file
402 Copy(GetMultiDexSrc1(), dex_location);
403
404 // Create the oat file with relative encoded dex location.
405 std::vector<std::string> args;
406 args.push_back("--dex-file=" + dex_location);
407 args.push_back("--dex-location=" + std::string("RelativeEncodedDexLocation.jar"));
408 args.push_back("--oat-file=" + oat_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000409 args.push_back("--compiler-filter=speed");
Richard Uhlere5fed032015-03-18 08:21:11 -0700410
411 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700412 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
Richard Uhlere5fed032015-03-18 08:21:11 -0700413
414 // Verify we can load both dex files.
415 OatFileAssistant oat_file_assistant(dex_location.c_str(),
416 oat_location.c_str(),
Richard Uhlerd1472a22016-04-15 15:18:56 -0700417 kRuntimeISA, true);
Richard Uhlere5fed032015-03-18 08:21:11 -0700418 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
419 ASSERT_TRUE(oat_file.get() != nullptr);
420 EXPECT_TRUE(oat_file->IsExecutable());
421 std::vector<std::unique_ptr<const DexFile>> dex_files;
422 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
Richard Uhler66d874d2015-01-15 09:37:19 -0800423 EXPECT_EQ(2u, dex_files.size());
424}
425
Richard Uhler95abd042015-03-24 09:51:28 -0700426// Case: We have a DEX file and out-of-date OAT file.
427// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800428TEST_F(OatFileAssistantTest, OatOutOfDate) {
429 std::string dex_location = GetScratchDir() + "/OatOutOfDate.jar";
430
431 // We create a dex, generate an oat for it, then overwrite the dex with a
432 // different dex to make the oat out of date.
433 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000434 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800435 Copy(GetDexSrc2(), dex_location);
436
Richard Uhlerd1472a22016-04-15 15:18:56 -0700437 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000438 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
439 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
440 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
441 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800442
443 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
444 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
445 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
446 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
447 EXPECT_TRUE(oat_file_assistant.OatFileExists());
448 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
449 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700450 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800451}
452
453// Case: We have a DEX file and an ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700454// Expect: The status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800455TEST_F(OatFileAssistantTest, DexOdexNoOat) {
456 std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700457 std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800458
459 // Create the dex and odex files
460 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000461 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800462
463 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700464 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800465
Andreas Gampe29d38e72016-03-23 15:31:51 +0000466 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
467 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
468 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded,
469 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800470
471 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
472 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
473 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
474 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
475 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
Richard Uhler66d874d2015-01-15 09:37:19 -0800476 EXPECT_FALSE(oat_file_assistant.OatFileExists());
477 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
478 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700479 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler5f946da2015-07-17 12:28:32 -0700480
481 // We should still be able to get the non-executable odex file to run from.
482 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
483 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhler66d874d2015-01-15 09:37:19 -0800484}
485
486// Case: We have a stripped DEX file and an ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700487// Expect: The status is kPatchOatNeeded
Richard Uhler66d874d2015-01-15 09:37:19 -0800488TEST_F(OatFileAssistantTest, StrippedDexOdexNoOat) {
489 std::string dex_location = GetScratchDir() + "/StrippedDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700490 std::string odex_location = GetOdexDir() + "/StrippedDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800491
492 // Create the dex and odex files
493 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000494 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800495
496 // Strip the dex file
497 Copy(GetStrippedDexSrc1(), dex_location);
498
499 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700500 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800501
Andreas Gampe29d38e72016-03-23 15:31:51 +0000502 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded,
503 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800504
505 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
506 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
507 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
508 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
509 EXPECT_FALSE(oat_file_assistant.OatFileExists());
510 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
511 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700512 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800513
514 // Make the oat file up to date.
515 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -0700516 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -0700517 ASSERT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700518 oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800519
Andreas Gampe29d38e72016-03-23 15:31:51 +0000520 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
521 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800522
523 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
524 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
525 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
526 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
527 EXPECT_TRUE(oat_file_assistant.OatFileExists());
528 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
529 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700530 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800531
532 // Verify we can load the dex files from it.
533 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
534 ASSERT_TRUE(oat_file.get() != nullptr);
535 EXPECT_TRUE(oat_file->IsExecutable());
536 std::vector<std::unique_ptr<const DexFile>> dex_files;
537 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
538 EXPECT_EQ(1u, dex_files.size());
539}
540
Richard Uhler95abd042015-03-24 09:51:28 -0700541// Case: We have a stripped DEX file, an ODEX file, and an out-of-date OAT file.
542// Expect: The status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800543TEST_F(OatFileAssistantTest, StrippedDexOdexOat) {
544 std::string dex_location = GetScratchDir() + "/StrippedDexOdexOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700545 std::string odex_location = GetOdexDir() + "/StrippedDexOdexOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800546
547 // Create the oat file from a different dex file so it looks out of date.
548 Copy(GetDexSrc2(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000549 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800550
551 // Create the odex file
552 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000553 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800554
555 // Strip the dex file.
556 Copy(GetStrippedDexSrc1(), dex_location);
557
558 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700559 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800560
Andreas Gampe29d38e72016-03-23 15:31:51 +0000561 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
562 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
563 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded,
564 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
565 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, // Can't run dex2oat because dex file is stripped.
566 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
Richard Uhler66d874d2015-01-15 09:37:19 -0800567
568 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
569 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
570 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
571 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
572 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
573 EXPECT_TRUE(oat_file_assistant.OatFileExists());
574 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
575 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700576 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800577
578 // Make the oat file up to date.
579 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -0700580 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -0700581 ASSERT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700582 oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800583
Andreas Gampe29d38e72016-03-23 15:31:51 +0000584 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
585 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
586 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, // Can't run dex2oat because dex file is stripped.
587 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
Richard Uhler66d874d2015-01-15 09:37:19 -0800588
589 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
590 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
591 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
592 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
593 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
594 EXPECT_TRUE(oat_file_assistant.OatFileExists());
595 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
596 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
597 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700598 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800599
600 // Verify we can load the dex files from it.
601 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
602 ASSERT_TRUE(oat_file.get() != nullptr);
603 EXPECT_TRUE(oat_file->IsExecutable());
604 std::vector<std::unique_ptr<const DexFile>> dex_files;
605 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
606 EXPECT_EQ(1u, dex_files.size());
607}
608
Richard Uhler9b994ea2015-06-24 08:44:19 -0700609// Case: We have a stripped (or resource-only) DEX file, no ODEX file and no
610// OAT file. Expect: The status is kNoDexOptNeeded.
611TEST_F(OatFileAssistantTest, ResourceOnlyDex) {
612 std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar";
613
614 Copy(GetStrippedDexSrc1(), dex_location);
615
616 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700617 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler9b994ea2015-06-24 08:44:19 -0700618
Andreas Gampe29d38e72016-03-23 15:31:51 +0000619 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
620 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
621 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
622 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
623 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
624 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700625
626 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
627 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
628 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
629 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
630 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
631 EXPECT_FALSE(oat_file_assistant.OatFileExists());
632 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
633 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
634 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
635
636 // Make the oat file up to date. This should have no effect.
637 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -0700638 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -0700639 EXPECT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700640 oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg;
Richard Uhler9b994ea2015-06-24 08:44:19 -0700641
Andreas Gampe29d38e72016-03-23 15:31:51 +0000642 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
643 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700644
645 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
646 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
647 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
648 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
649 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
650 EXPECT_FALSE(oat_file_assistant.OatFileExists());
651 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
652 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
653 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
654}
655
Richard Uhler95abd042015-03-24 09:51:28 -0700656// Case: We have a DEX file, no ODEX file and an OAT file that needs
657// relocation.
658// Expect: The status is kSelfPatchOatNeeded.
659TEST_F(OatFileAssistantTest, SelfRelocation) {
660 std::string dex_location = GetScratchDir() + "/SelfRelocation.jar";
661 std::string oat_location = GetOdexDir() + "/SelfRelocation.oat";
662
663 // Create the dex and odex files
664 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000665 GenerateOdexForTest(dex_location, oat_location, CompilerFilter::kSpeed);
Richard Uhler95abd042015-03-24 09:51:28 -0700666
667 OatFileAssistant oat_file_assistant(dex_location.c_str(),
Richard Uhlerd1472a22016-04-15 15:18:56 -0700668 oat_location.c_str(), kRuntimeISA, true);
Richard Uhler95abd042015-03-24 09:51:28 -0700669
Andreas Gampe29d38e72016-03-23 15:31:51 +0000670 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
671 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
672 EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded,
673 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
674 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
675 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
Richard Uhler95abd042015-03-24 09:51:28 -0700676
677 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
678 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
679 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
680 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
681 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
682 EXPECT_TRUE(oat_file_assistant.OatFileExists());
683 EXPECT_TRUE(oat_file_assistant.OatFileNeedsRelocation());
684 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
685 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700686 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700687
688 // Make the oat file up to date.
689 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -0700690 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -0700691 ASSERT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700692 oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg;
Richard Uhler95abd042015-03-24 09:51:28 -0700693
Andreas Gampe29d38e72016-03-23 15:31:51 +0000694 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
695 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler95abd042015-03-24 09:51:28 -0700696
697 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
698 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
699 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
700 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
701 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
702 EXPECT_TRUE(oat_file_assistant.OatFileExists());
703 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
704 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
705 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700706 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700707
708 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
709 ASSERT_TRUE(oat_file.get() != nullptr);
710 EXPECT_TRUE(oat_file->IsExecutable());
711 std::vector<std::unique_ptr<const DexFile>> dex_files;
712 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
713 EXPECT_EQ(1u, dex_files.size());
714}
715
Richard Uhlerd1537b52016-03-29 13:27:41 -0700716// Case: We have a DEX file, no ODEX file and an OAT file that needs
717// relocation but doesn't have patch info.
718// Expect: The status is kDex2OatNeeded, because we can't run patchoat.
719TEST_F(OatFileAssistantTest, NoSelfRelocation) {
720 std::string dex_location = GetScratchDir() + "/NoSelfRelocation.jar";
721 std::string oat_location = GetOdexDir() + "/NoSelfRelocation.oat";
722
723 // Create the dex and odex files
724 Copy(GetDexSrc1(), dex_location);
725 GenerateNoPatchOdexForTest(dex_location, oat_location, CompilerFilter::kSpeed);
726
727 OatFileAssistant oat_file_assistant(dex_location.c_str(),
Richard Uhlerd1472a22016-04-15 15:18:56 -0700728 oat_location.c_str(), kRuntimeISA, true);
Richard Uhlerd1537b52016-03-29 13:27:41 -0700729
730 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
731 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
732
733 // Make the oat file up to date.
734 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -0700735 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -0700736 ASSERT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700737 oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg;
Richard Uhlerd1537b52016-03-29 13:27:41 -0700738 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
739 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
740
741 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
742 ASSERT_TRUE(oat_file.get() != nullptr);
743 EXPECT_TRUE(oat_file->IsExecutable());
744 std::vector<std::unique_ptr<const DexFile>> dex_files;
745 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
746 EXPECT_EQ(1u, dex_files.size());
747}
748
Richard Uhler66d874d2015-01-15 09:37:19 -0800749// Case: We have a DEX file, an ODEX file and an OAT file, where the ODEX and
750// OAT files both have patch delta of 0.
Richard Uhler95abd042015-03-24 09:51:28 -0700751// Expect: It shouldn't crash, and status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800752TEST_F(OatFileAssistantTest, OdexOatOverlap) {
753 std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700754 std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex";
755 std::string oat_location = GetOdexDir() + "/OdexOatOverlap.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -0800756
757 // Create the dex and odex files
758 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000759 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800760
761 // Create the oat file by copying the odex so they are located in the same
762 // place in memory.
763 Copy(odex_location, oat_location);
764
765 // Verify things don't go bad.
766 OatFileAssistant oat_file_assistant(dex_location.c_str(),
Richard Uhlerd1472a22016-04-15 15:18:56 -0700767 oat_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800768
Andreas Gampe29d38e72016-03-23 15:31:51 +0000769 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded,
770 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800771
772 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
773 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
774 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
775 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
776 EXPECT_TRUE(oat_file_assistant.OatFileExists());
777 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
778 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700779 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800780
781 // Things aren't relocated, so it should fall back to interpreted.
782 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
783 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhlerf16d5722015-05-11 09:32:47 -0700784
Richard Uhler66d874d2015-01-15 09:37:19 -0800785 EXPECT_FALSE(oat_file->IsExecutable());
786 std::vector<std::unique_ptr<const DexFile>> dex_files;
787 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
788 EXPECT_EQ(1u, dex_files.size());
789}
790
791// Case: We have a DEX file and a PIC ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700792// Expect: The status is kNoDexOptNeeded, because PIC needs no relocation.
Richard Uhler66d874d2015-01-15 09:37:19 -0800793TEST_F(OatFileAssistantTest, DexPicOdexNoOat) {
794 std::string dex_location = GetScratchDir() + "/DexPicOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700795 std::string odex_location = GetOdexDir() + "/DexPicOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800796
797 // Create the dex and odex files
798 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000799 GeneratePicOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800800
801 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700802 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800803
Andreas Gampe29d38e72016-03-23 15:31:51 +0000804 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
805 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
806 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
807 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything));
Richard Uhler66d874d2015-01-15 09:37:19 -0800808
809 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
810 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
811 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
812 EXPECT_TRUE(oat_file_assistant.OdexFileIsUpToDate());
813 EXPECT_FALSE(oat_file_assistant.OatFileExists());
814 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
815 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700816 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800817}
818
Andreas Gampe29d38e72016-03-23 15:31:51 +0000819// Case: We have a DEX file and a VerifyAtRuntime ODEX file, but no OAT file.
820// Expect: The status is kNoDexOptNeeded, because VerifyAtRuntime contains no code.
821TEST_F(OatFileAssistantTest, DexVerifyAtRuntimeOdexNoOat) {
822 std::string dex_location = GetScratchDir() + "/DexVerifyAtRuntimeOdexNoOat.jar";
823 std::string odex_location = GetOdexDir() + "/DexVerifyAtRuntimeOdexNoOat.odex";
David Brazdilce4b0ba2016-01-28 15:05:49 +0000824
825 // Create the dex and odex files
826 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000827 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kVerifyAtRuntime);
David Brazdilce4b0ba2016-01-28 15:05:49 +0000828
829 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700830 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
David Brazdilce4b0ba2016-01-28 15:05:49 +0000831
Andreas Gampe29d38e72016-03-23 15:31:51 +0000832 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
833 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime));
834 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
835 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
David Brazdilce4b0ba2016-01-28 15:05:49 +0000836
837 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
838 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
839 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000840 EXPECT_TRUE(oat_file_assistant.OdexFileIsUpToDate());
David Brazdilce4b0ba2016-01-28 15:05:49 +0000841 EXPECT_FALSE(oat_file_assistant.OatFileExists());
842 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
843 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
844 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
845}
846
Richard Uhler66d874d2015-01-15 09:37:19 -0800847// Case: We have a DEX file and up-to-date OAT file for it.
848// Expect: We should load an executable dex file.
849TEST_F(OatFileAssistantTest, LoadOatUpToDate) {
850 std::string dex_location = GetScratchDir() + "/LoadOatUpToDate.jar";
851
852 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000853 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800854
855 // Load the oat using an oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700856 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000857
858 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
859 ASSERT_TRUE(oat_file.get() != nullptr);
860 EXPECT_TRUE(oat_file->IsExecutable());
861 std::vector<std::unique_ptr<const DexFile>> dex_files;
862 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
863 EXPECT_EQ(1u, dex_files.size());
864}
865
866// Case: We have a DEX file and up-to-date interpret-only OAT file for it.
867// Expect: We should still load the oat file as executable.
868TEST_F(OatFileAssistantTest, LoadExecInterpretOnlyOatUpToDate) {
869 std::string dex_location = GetScratchDir() + "/LoadExecInterpretOnlyOatUpToDate.jar";
870
871 Copy(GetDexSrc1(), dex_location);
872 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kInterpretOnly);
873
874 // Load the oat using an oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700875 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800876
877 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
878 ASSERT_TRUE(oat_file.get() != nullptr);
879 EXPECT_TRUE(oat_file->IsExecutable());
880 std::vector<std::unique_ptr<const DexFile>> dex_files;
881 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
882 EXPECT_EQ(1u, dex_files.size());
883}
884
885// Case: We have a DEX file and up-to-date OAT file for it.
886// Expect: Loading non-executable should load the oat non-executable.
887TEST_F(OatFileAssistantTest, LoadNoExecOatUpToDate) {
888 std::string dex_location = GetScratchDir() + "/LoadNoExecOatUpToDate.jar";
889
890 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000891 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800892
893 // Load the oat using an oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700894 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800895
896 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
897 ASSERT_TRUE(oat_file.get() != nullptr);
898 EXPECT_FALSE(oat_file->IsExecutable());
899 std::vector<std::unique_ptr<const DexFile>> dex_files;
900 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
901 EXPECT_EQ(1u, dex_files.size());
902}
903
904// Case: We have a DEX file.
905// Expect: We should load an executable dex file from an alternative oat
906// location.
907TEST_F(OatFileAssistantTest, LoadDexNoAlternateOat) {
908 std::string dex_location = GetScratchDir() + "/LoadDexNoAlternateOat.jar";
909 std::string oat_location = GetScratchDir() + "/LoadDexNoAlternateOat.oat";
910
911 Copy(GetDexSrc1(), dex_location);
912
913 OatFileAssistant oat_file_assistant(
Richard Uhlerd1472a22016-04-15 15:18:56 -0700914 dex_location.c_str(), oat_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800915 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -0700916 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -0700917 ASSERT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700918 oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800919
920 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
921 ASSERT_TRUE(oat_file.get() != nullptr);
922 EXPECT_TRUE(oat_file->IsExecutable());
923 std::vector<std::unique_ptr<const DexFile>> dex_files;
924 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
925 EXPECT_EQ(1u, dex_files.size());
926
927 EXPECT_TRUE(OS::FileExists(oat_location.c_str()));
928
929 // Verify it didn't create an oat in the default location.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700930 OatFileAssistant ofm(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800931 EXPECT_FALSE(ofm.OatFileExists());
932}
933
Richard Uhler8327cf72015-10-13 16:34:59 -0700934// Case: We have a DEX file but can't write the oat file.
935// Expect: We should fail to make the oat file up to date.
936TEST_F(OatFileAssistantTest, LoadDexUnwriteableAlternateOat) {
937 std::string dex_location = GetScratchDir() + "/LoadDexUnwriteableAlternateOat.jar";
938
939 // Make the oat location unwritable by inserting some non-existent
940 // intermediate directories.
941 std::string oat_location = GetScratchDir() + "/foo/bar/LoadDexUnwriteableAlternateOat.oat";
942
943 Copy(GetDexSrc1(), dex_location);
944
945 OatFileAssistant oat_file_assistant(
Richard Uhlerd1472a22016-04-15 15:18:56 -0700946 dex_location.c_str(), oat_location.c_str(), kRuntimeISA, true);
Richard Uhler8327cf72015-10-13 16:34:59 -0700947 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -0700948 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -0700949 ASSERT_EQ(OatFileAssistant::kUpdateNotAttempted,
Richard Uhlerd1472a22016-04-15 15:18:56 -0700950 oat_file_assistant.MakeUpToDate(false, &error_msg));
Richard Uhler8327cf72015-10-13 16:34:59 -0700951
952 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
953 ASSERT_TRUE(oat_file.get() == nullptr);
954}
955
956// Case: We don't have a DEX file and can't write the oat file.
957// Expect: We should fail to generate the oat file without crashing.
958TEST_F(OatFileAssistantTest, GenNoDex) {
959 std::string dex_location = GetScratchDir() + "/GenNoDex.jar";
960 std::string oat_location = GetScratchDir() + "/GenNoDex.oat";
961
962 OatFileAssistant oat_file_assistant(
Richard Uhlerd1472a22016-04-15 15:18:56 -0700963 dex_location.c_str(), oat_location.c_str(), kRuntimeISA, true);
Richard Uhler8327cf72015-10-13 16:34:59 -0700964 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -0700965 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -0700966 EXPECT_EQ(OatFileAssistant::kUpdateNotAttempted,
Richard Uhlerf4b34872016-04-13 11:03:46 -0700967 oat_file_assistant.GenerateOatFile(&error_msg));
Richard Uhler8327cf72015-10-13 16:34:59 -0700968}
969
Richard Uhler66d874d2015-01-15 09:37:19 -0800970// Turn an absolute path into a path relative to the current working
971// directory.
972static std::string MakePathRelative(std::string target) {
973 char buf[MAXPATHLEN];
974 std::string cwd = getcwd(buf, MAXPATHLEN);
975
976 // Split the target and cwd paths into components.
977 std::vector<std::string> target_path;
978 std::vector<std::string> cwd_path;
979 Split(target, '/', &target_path);
980 Split(cwd, '/', &cwd_path);
981
982 // Reverse the path components, so we can use pop_back().
983 std::reverse(target_path.begin(), target_path.end());
984 std::reverse(cwd_path.begin(), cwd_path.end());
985
986 // Drop the common prefix of the paths. Because we reversed the path
987 // components, this becomes the common suffix of target_path and cwd_path.
988 while (!target_path.empty() && !cwd_path.empty()
989 && target_path.back() == cwd_path.back()) {
990 target_path.pop_back();
991 cwd_path.pop_back();
992 }
993
994 // For each element of the remaining cwd_path, add '..' to the beginning
995 // of the target path. Because we reversed the path components, we add to
996 // the end of target_path.
997 for (unsigned int i = 0; i < cwd_path.size(); i++) {
998 target_path.push_back("..");
999 }
1000
1001 // Reverse again to get the right path order, and join to get the result.
1002 std::reverse(target_path.begin(), target_path.end());
1003 return Join(target_path, '/');
1004}
1005
1006// Case: Non-absolute path to Dex location.
1007// Expect: Not sure, but it shouldn't crash.
1008TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) {
1009 std::string abs_dex_location = GetScratchDir() + "/NonAbsoluteDexLocation.jar";
1010 Copy(GetDexSrc1(), abs_dex_location);
1011
1012 std::string dex_location = MakePathRelative(abs_dex_location);
Richard Uhlerd1472a22016-04-15 15:18:56 -07001013 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001014
1015 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Andreas Gampe29d38e72016-03-23 15:31:51 +00001016 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
1017 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -08001018 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
1019 EXPECT_FALSE(oat_file_assistant.OatFileExists());
1020 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
1021 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
1022 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
1023 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
1024}
1025
1026// Case: Very short, non-existent Dex location.
Richard Uhler9b994ea2015-06-24 08:44:19 -07001027// Expect: kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -08001028TEST_F(OatFileAssistantTest, ShortDexLocation) {
1029 std::string dex_location = "/xx";
1030
Richard Uhlerd1472a22016-04-15 15:18:56 -07001031 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001032
1033 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Andreas Gampe29d38e72016-03-23 15:31:51 +00001034 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
1035 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -08001036 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
1037 EXPECT_FALSE(oat_file_assistant.OatFileExists());
1038 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
1039 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
1040 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
1041 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -07001042 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -08001043
Richard Uhler9b994ea2015-06-24 08:44:19 -07001044 // Trying to make it up to date should have no effect.
Richard Uhler66d874d2015-01-15 09:37:19 -08001045 std::string error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -07001046 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
Richard Uhler1e860612016-03-30 12:17:55 -07001047 EXPECT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -07001048 oat_file_assistant.MakeUpToDate(false, &error_msg));
Richard Uhler9b994ea2015-06-24 08:44:19 -07001049 EXPECT_TRUE(error_msg.empty());
Richard Uhler66d874d2015-01-15 09:37:19 -08001050}
1051
1052// Case: Non-standard extension for dex file.
Richard Uhler95abd042015-03-24 09:51:28 -07001053// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -08001054TEST_F(OatFileAssistantTest, LongDexExtension) {
1055 std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx";
1056 Copy(GetDexSrc1(), dex_location);
1057
Richard Uhlerd1472a22016-04-15 15:18:56 -07001058 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -08001059
Andreas Gampe29d38e72016-03-23 15:31:51 +00001060 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
1061 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -08001062
1063 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
1064 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
1065 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
1066 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
1067 EXPECT_FALSE(oat_file_assistant.OatFileExists());
1068 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
1069 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
1070}
1071
1072// A task to generate a dex location. Used by the RaceToGenerate test.
1073class RaceGenerateTask : public Task {
1074 public:
1075 explicit RaceGenerateTask(const std::string& dex_location, const std::string& oat_location)
Jeff Haof0192c82016-03-28 20:39:50 -07001076 : dex_location_(dex_location), oat_location_(oat_location), loaded_oat_file_(nullptr)
Richard Uhler66d874d2015-01-15 09:37:19 -08001077 {}
1078
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001079 void Run(Thread* self ATTRIBUTE_UNUSED) {
Richard Uhler66d874d2015-01-15 09:37:19 -08001080 // Load the dex files, and save a pointer to the loaded oat file, so that
1081 // we can verify only one oat file was loaded for the dex location.
Richard Uhler66d874d2015-01-15 09:37:19 -08001082 std::vector<std::unique_ptr<const DexFile>> dex_files;
1083 std::vector<std::string> error_msgs;
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001084 const OatFile* oat_file = nullptr;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001085 dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat(
1086 dex_location_.c_str(),
1087 oat_location_.c_str(),
Mathieu Chartierfbc31082016-01-24 11:59:56 -08001088 /*class_loader*/nullptr,
1089 /*dex_elements*/nullptr,
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001090 &oat_file,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001091 &error_msgs);
Richard Uhler66d874d2015-01-15 09:37:19 -08001092 CHECK(!dex_files.empty()) << Join(error_msgs, '\n');
Richard Uhler07b3c232015-03-31 15:57:54 -07001093 CHECK(dex_files[0]->GetOatDexFile() != nullptr) << dex_files[0]->GetLocation();
1094 loaded_oat_file_ = dex_files[0]->GetOatDexFile()->GetOatFile();
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001095 CHECK_EQ(loaded_oat_file_, oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001096 }
1097
1098 const OatFile* GetLoadedOatFile() const {
1099 return loaded_oat_file_;
1100 }
1101
1102 private:
1103 std::string dex_location_;
1104 std::string oat_location_;
1105 const OatFile* loaded_oat_file_;
1106};
1107
1108// Test the case where multiple processes race to generate an oat file.
1109// This simulates multiple processes using multiple threads.
1110//
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001111// We want unique Oat files to be loaded even when there is a race to load.
1112// TODO: The test case no longer tests locking the way it was intended since we now get multiple
1113// copies of the same Oat files mapped at different locations.
Richard Uhler66d874d2015-01-15 09:37:19 -08001114TEST_F(OatFileAssistantTest, RaceToGenerate) {
1115 std::string dex_location = GetScratchDir() + "/RaceToGenerate.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001116 std::string oat_location = GetOdexDir() + "/RaceToGenerate.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -08001117
1118 // We use the lib core dex file, because it's large, and hopefully should
1119 // take a while to generate.
Narayan Kamathd1ef4362015-11-12 11:49:06 +00001120 Copy(GetLibCoreDexFileNames()[0], dex_location);
Richard Uhler66d874d2015-01-15 09:37:19 -08001121
1122 const int kNumThreads = 32;
1123 Thread* self = Thread::Current();
1124 ThreadPool thread_pool("Oat file assistant test thread pool", kNumThreads);
1125 std::vector<std::unique_ptr<RaceGenerateTask>> tasks;
1126 for (int i = 0; i < kNumThreads; i++) {
1127 std::unique_ptr<RaceGenerateTask> task(new RaceGenerateTask(dex_location, oat_location));
1128 thread_pool.AddTask(self, task.get());
1129 tasks.push_back(std::move(task));
1130 }
1131 thread_pool.StartWorkers(self);
1132 thread_pool.Wait(self, true, false);
1133
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001134 // Verify every task got a unique oat file.
1135 std::set<const OatFile*> oat_files;
Richard Uhler66d874d2015-01-15 09:37:19 -08001136 for (auto& task : tasks) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001137 const OatFile* oat_file = task->GetLoadedOatFile();
1138 EXPECT_TRUE(oat_files.find(oat_file) == oat_files.end());
1139 oat_files.insert(oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001140 }
1141}
1142
1143// Case: We have a DEX file and an ODEX file, no OAT file, and dex2oat is
1144// disabled.
1145// Expect: We should load the odex file non-executable.
1146TEST_F(OatFileAssistantNoDex2OatTest, LoadDexOdexNoOat) {
1147 std::string dex_location = GetScratchDir() + "/LoadDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001148 std::string odex_location = GetOdexDir() + "/LoadDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001149
1150 // Create the dex and odex files
1151 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +00001152 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001153
1154 // Load the oat using an executable oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -07001155 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001156
1157 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1158 ASSERT_TRUE(oat_file.get() != nullptr);
1159 EXPECT_FALSE(oat_file->IsExecutable());
1160 std::vector<std::unique_ptr<const DexFile>> dex_files;
1161 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1162 EXPECT_EQ(1u, dex_files.size());
1163}
1164
1165// Case: We have a MultiDEX file and an ODEX file, no OAT file, and dex2oat is
1166// disabled.
1167// Expect: We should load the odex file non-executable.
1168TEST_F(OatFileAssistantNoDex2OatTest, LoadMultiDexOdexNoOat) {
1169 std::string dex_location = GetScratchDir() + "/LoadMultiDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001170 std::string odex_location = GetOdexDir() + "/LoadMultiDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001171
1172 // Create the dex and odex files
1173 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +00001174 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001175
1176 // Load the oat using an executable oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -07001177 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001178
1179 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1180 ASSERT_TRUE(oat_file.get() != nullptr);
1181 EXPECT_FALSE(oat_file->IsExecutable());
1182 std::vector<std::unique_ptr<const DexFile>> dex_files;
1183 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1184 EXPECT_EQ(2u, dex_files.size());
1185}
1186
Richard Uhlerf4b34872016-04-13 11:03:46 -07001187TEST_F(OatFileAssistantTest, RuntimeCompilerFilterOptionUsed) {
1188 std::string dex_location = GetScratchDir() + "/RuntimeCompilerFilterOptionUsed.jar";
1189 Copy(GetDexSrc1(), dex_location);
1190
Richard Uhlerd1472a22016-04-15 15:18:56 -07001191 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhlerf4b34872016-04-13 11:03:46 -07001192
1193 std::string error_msg;
1194 Runtime::Current()->AddCompilerOption("--compiler-filter=interpret-only");
1195 EXPECT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -07001196 oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -07001197 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
1198 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
1199 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded,
1200 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
1201
1202 Runtime::Current()->AddCompilerOption("--compiler-filter=speed");
1203 EXPECT_EQ(OatFileAssistant::kUpdateSucceeded,
Richard Uhlerd1472a22016-04-15 15:18:56 -07001204 oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg;
Richard Uhlerf4b34872016-04-13 11:03:46 -07001205 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
1206 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly));
1207 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
1208 oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed));
1209
1210 Runtime::Current()->AddCompilerOption("--compiler-filter=bogus");
1211 EXPECT_EQ(OatFileAssistant::kUpdateNotAttempted,
Richard Uhlerd1472a22016-04-15 15:18:56 -07001212 oat_file_assistant.MakeUpToDate(false, &error_msg));
Richard Uhlerf4b34872016-04-13 11:03:46 -07001213}
1214
Richard Uhlerb81881d2016-04-19 13:08:04 -07001215TEST(OatFileAssistantUtilsTest, DexLocationToOdexFilename) {
Richard Uhler66d874d2015-01-15 09:37:19 -08001216 std::string error_msg;
1217 std::string odex_file;
1218
Richard Uhlerb81881d2016-04-19 13:08:04 -07001219 EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001220 "/foo/bar/baz.jar", kArm, &odex_file, &error_msg)) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001221 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001222
Richard Uhlerb81881d2016-04-19 13:08:04 -07001223 EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001224 "/foo/bar/baz.funnyext", kArm, &odex_file, &error_msg)) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001225 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001226
Richard Uhlerb81881d2016-04-19 13:08:04 -07001227 EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001228 "nopath.jar", kArm, &odex_file, &error_msg));
Richard Uhlerb81881d2016-04-19 13:08:04 -07001229 EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001230 "/foo/bar/baz_noext", kArm, &odex_file, &error_msg));
Richard Uhler66d874d2015-01-15 09:37:19 -08001231}
1232
Richard Uhler23cedd22015-04-08 13:17:29 -07001233// Verify the dexopt status values from dalvik.system.DexFile
1234// match the OatFileAssistant::DexOptStatus values.
1235TEST_F(OatFileAssistantTest, DexOptStatusValues) {
1236 ScopedObjectAccess soa(Thread::Current());
1237 StackHandleScope<1> hs(soa.Self());
1238 ClassLinker* linker = Runtime::Current()->GetClassLinker();
1239 Handle<mirror::Class> dexfile(
1240 hs.NewHandle(linker->FindSystemClass(soa.Self(), "Ldalvik/system/DexFile;")));
1241 ASSERT_FALSE(dexfile.Get() == nullptr);
1242 linker->EnsureInitialized(soa.Self(), dexfile, true, true);
1243
Mathieu Chartierc7853442015-03-27 14:35:38 -07001244 ArtField* no_dexopt_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001245 soa.Self(), dexfile, "NO_DEXOPT_NEEDED", "I");
1246 ASSERT_FALSE(no_dexopt_needed == nullptr);
1247 EXPECT_EQ(no_dexopt_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1248 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, no_dexopt_needed->GetInt(dexfile.Get()));
1249
Mathieu Chartierc7853442015-03-27 14:35:38 -07001250 ArtField* dex2oat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001251 soa.Self(), dexfile, "DEX2OAT_NEEDED", "I");
1252 ASSERT_FALSE(dex2oat_needed == nullptr);
1253 EXPECT_EQ(dex2oat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1254 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, dex2oat_needed->GetInt(dexfile.Get()));
1255
Mathieu Chartierc7853442015-03-27 14:35:38 -07001256 ArtField* patchoat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001257 soa.Self(), dexfile, "PATCHOAT_NEEDED", "I");
1258 ASSERT_FALSE(patchoat_needed == nullptr);
1259 EXPECT_EQ(patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1260 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, patchoat_needed->GetInt(dexfile.Get()));
1261
Mathieu Chartierc7853442015-03-27 14:35:38 -07001262 ArtField* self_patchoat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001263 soa.Self(), dexfile, "SELF_PATCHOAT_NEEDED", "I");
1264 ASSERT_FALSE(self_patchoat_needed == nullptr);
1265 EXPECT_EQ(self_patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1266 EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded, self_patchoat_needed->GetInt(dexfile.Get()));
1267}
Richard Uhler66d874d2015-01-15 09:37:19 -08001268
1269// TODO: More Tests:
Andreas Gampe29d38e72016-03-23 15:31:51 +00001270// * Image checksum change is out of date for kIntepretOnly, but not
1271// kVerifyAtRuntime. But target of kVerifyAtRuntime still says current
1272// kInterpretOnly is out of date.
Richard Uhler66d874d2015-01-15 09:37:19 -08001273// * Test class linker falls back to unquickened dex for DexNoOat
1274// * Test class linker falls back to unquickened dex for MultiDexNoOat
Richard Uhler66d874d2015-01-15 09:37:19 -08001275// * Test using secondary isa
Richard Uhler66d874d2015-01-15 09:37:19 -08001276// * Test for status of oat while oat is being generated (how?)
1277// * Test case where 32 and 64 bit boot class paths differ,
1278// and we ask IsInBootClassPath for a class in exactly one of the 32 or
1279// 64 bit boot class paths.
1280// * Test unexpected scenarios (?):
1281// - Dex is stripped, don't have odex.
1282// - Oat file corrupted after status check, before reload unexecutable
1283// because it's unrelocated and no dex2oat
Calin Juravleb077e152016-02-18 18:47:37 +00001284// * Test unrelocated specific target compilation type can be relocated to
1285// make it up to date.
Richard Uhler66d874d2015-01-15 09:37:19 -08001286
1287} // namespace art