blob: 03ad2d5ac8e3eb10b81420f98dcd67749ff535ef [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"
34#include "os.h"
Richard Uhler23cedd22015-04-08 13:17:29 -070035#include "scoped_thread_state_change.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080036#include "thread-inl.h"
37#include "utils.h"
38
39namespace art {
40
Richard Uhler94f5bda2015-07-22 08:25:11 -070041// Some tests very occasionally fail: we expect to have an unrelocated non-pic
42// odex file that is reported as needing relocation, but it is reported
43// instead as being up to date (b/22599792).
44//
45// This function adds extra checks for diagnosing why the given oat file is
46// reported up to date, when it should be non-pic needing relocation.
47// These extra diagnostics checks should be removed once b/22599792 has been
48// resolved.
49static void DiagnoseFlakyTestFailure(const OatFile& oat_file) {
50 Runtime* runtime = Runtime::Current();
51 const gc::space::ImageSpace* image_space = runtime->GetHeap()->GetImageSpace();
52 ASSERT_TRUE(image_space != nullptr);
53 const ImageHeader& image_header = image_space->GetImageHeader();
54 const OatHeader& oat_header = oat_file.GetOatHeader();
55 EXPECT_FALSE(oat_file.IsPic());
56 EXPECT_EQ(image_header.GetOatChecksum(), oat_header.GetImageFileLocationOatChecksum());
57 EXPECT_NE(reinterpret_cast<uintptr_t>(image_header.GetOatDataBegin()),
58 oat_header.GetImageFileLocationOatDataBegin());
59 EXPECT_NE(image_header.GetPatchDelta(), oat_header.GetImagePatchDelta());
60}
61
62
Richard Uhler66d874d2015-01-15 09:37:19 -080063class OatFileAssistantTest : public CommonRuntimeTest {
64 public:
65 virtual void SetUp() {
66 ReserveImageSpace();
67 CommonRuntimeTest::SetUp();
68
69 // Create a scratch directory to work from.
70 scratch_dir_ = android_data_ + "/OatFileAssistantTest";
71 ASSERT_EQ(0, mkdir(scratch_dir_.c_str(), 0700));
72
Richard Uhler63434112015-03-16 14:32:16 -070073 // Create a subdirectory in scratch for odex files.
74 odex_oat_dir_ = scratch_dir_ + "/oat";
75 ASSERT_EQ(0, mkdir(odex_oat_dir_.c_str(), 0700));
76
77 odex_dir_ = odex_oat_dir_ + "/" + std::string(GetInstructionSetString(kRuntimeISA));
78 ASSERT_EQ(0, mkdir(odex_dir_.c_str(), 0700));
79
Richard Uhler66d874d2015-01-15 09:37:19 -080080
81 // Verify the environment is as we expect
82 uint32_t checksum;
83 std::string error_msg;
84 ASSERT_TRUE(OS::FileExists(GetImageFile().c_str()))
85 << "Expected pre-compiled boot image to be at: " << GetImageFile();
86 ASSERT_TRUE(OS::FileExists(GetDexSrc1().c_str()))
87 << "Expected dex file to be at: " << GetDexSrc1();
88 ASSERT_TRUE(OS::FileExists(GetStrippedDexSrc1().c_str()))
89 << "Expected stripped dex file to be at: " << GetStrippedDexSrc1();
Igor Murashkinb1d8c312015-08-04 11:18:43 -070090 ASSERT_FALSE(DexFile::GetChecksum(GetStrippedDexSrc1().c_str(), &checksum, &error_msg))
Richard Uhler66d874d2015-01-15 09:37:19 -080091 << "Expected stripped dex file to be stripped: " << GetStrippedDexSrc1();
Richard Uhler66d874d2015-01-15 09:37:19 -080092 ASSERT_TRUE(OS::FileExists(GetDexSrc2().c_str()))
93 << "Expected dex file to be at: " << GetDexSrc2();
Richard Uhler67ff7d12015-05-14 13:21:13 -070094
95 // GetMultiDexSrc2 should have the same primary dex checksum as
96 // GetMultiDexSrc1, but a different secondary dex checksum.
97 std::vector<std::unique_ptr<const DexFile>> multi1;
98 ASSERT_TRUE(DexFile::Open(GetMultiDexSrc1().c_str(),
Igor Murashkinb1d8c312015-08-04 11:18:43 -070099 GetMultiDexSrc1().c_str(), &error_msg, &multi1)) << error_msg;
Richard Uhler67ff7d12015-05-14 13:21:13 -0700100 ASSERT_GT(multi1.size(), 1u);
101
102 std::vector<std::unique_ptr<const DexFile>> multi2;
103 ASSERT_TRUE(DexFile::Open(GetMultiDexSrc2().c_str(),
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700104 GetMultiDexSrc2().c_str(), &error_msg, &multi2)) << error_msg;
Richard Uhler67ff7d12015-05-14 13:21:13 -0700105 ASSERT_GT(multi2.size(), 1u);
106
107 ASSERT_EQ(multi1[0]->GetLocationChecksum(), multi2[0]->GetLocationChecksum());
108 ASSERT_NE(multi1[1]->GetLocationChecksum(), multi2[1]->GetLocationChecksum());
Richard Uhler66d874d2015-01-15 09:37:19 -0800109 }
110
111 virtual void SetUpRuntimeOptions(RuntimeOptions* options) {
Richard Uhler892fc962015-03-10 16:57:05 +0000112 // options->push_back(std::make_pair("-verbose:oat", nullptr));
Richard Uhler66d874d2015-01-15 09:37:19 -0800113
114 // Set up the image location.
115 options->push_back(std::make_pair("-Ximage:" + GetImageLocation(),
116 nullptr));
117 // Make sure compilercallbacks are not set so that relocation will be
118 // enabled.
Andreas Gampebb9c6b12015-03-29 13:56:36 -0700119 callbacks_.reset();
Richard Uhler66d874d2015-01-15 09:37:19 -0800120 }
121
122 virtual void PreRuntimeCreate() {
123 UnreserveImageSpace();
124 }
125
126 virtual void PostRuntimeCreate() {
127 ReserveImageSpace();
128 }
129
130 virtual void TearDown() {
Richard Uhler63434112015-03-16 14:32:16 -0700131 ClearDirectory(odex_dir_.c_str());
132 ASSERT_EQ(0, rmdir(odex_dir_.c_str()));
133
134 ClearDirectory(odex_oat_dir_.c_str());
135 ASSERT_EQ(0, rmdir(odex_oat_dir_.c_str()));
Richard Uhler66d874d2015-01-15 09:37:19 -0800136
137 ClearDirectory(scratch_dir_.c_str());
138 ASSERT_EQ(0, rmdir(scratch_dir_.c_str()));
139
140 CommonRuntimeTest::TearDown();
141 }
142
143 void Copy(std::string src, std::string dst) {
144 std::ifstream src_stream(src, std::ios::binary);
145 std::ofstream dst_stream(dst, std::ios::binary);
146
147 dst_stream << src_stream.rdbuf();
148 }
149
150 // Returns the directory where the pre-compiled core.art can be found.
151 // TODO: We should factor out this into common tests somewhere rather than
152 // re-hardcoding it here (This was copied originally from the elf writer
153 // test).
154 std::string GetImageDirectory() {
155 if (IsHost()) {
156 const char* host_dir = getenv("ANDROID_HOST_OUT");
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700157 CHECK(host_dir != nullptr);
Richard Uhler66d874d2015-01-15 09:37:19 -0800158 return std::string(host_dir) + "/framework";
159 } else {
160 return std::string("/data/art-test");
161 }
162 }
163
164 std::string GetImageLocation() {
165 return GetImageDirectory() + "/core.art";
166 }
167
168 std::string GetImageFile() {
169 return GetImageDirectory() + "/" + GetInstructionSetString(kRuntimeISA)
170 + "/core.art";
171 }
172
173 std::string GetDexSrc1() {
174 return GetTestDexFileName("Main");
175 }
176
177 // Returns the path to a dex file equivalent to GetDexSrc1, but with the dex
178 // file stripped.
179 std::string GetStrippedDexSrc1() {
180 return GetTestDexFileName("MainStripped");
181 }
182
183 std::string GetMultiDexSrc1() {
184 return GetTestDexFileName("MultiDex");
185 }
186
Richard Uhler67ff7d12015-05-14 13:21:13 -0700187 // Returns the path to a multidex file equivalent to GetMultiDexSrc2, but
188 // with the contents of the secondary dex file changed.
189 std::string GetMultiDexSrc2() {
190 return GetTestDexFileName("MultiDexModifiedSecondary");
191 }
192
Richard Uhler66d874d2015-01-15 09:37:19 -0800193 std::string GetDexSrc2() {
194 return GetTestDexFileName("Nested");
195 }
196
197 // Scratch directory, for dex and odex files (oat files will go in the
198 // dalvik cache).
199 std::string GetScratchDir() {
200 return scratch_dir_;
201 }
202
Richard Uhler63434112015-03-16 14:32:16 -0700203 // Odex directory is the subdirectory in the scratch directory where odex
Richard Uhler66d874d2015-01-15 09:37:19 -0800204 // files should be located.
Richard Uhler63434112015-03-16 14:32:16 -0700205 std::string GetOdexDir() {
206 return odex_dir_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800207 }
208
209 // Generate an odex file for the purposes of test.
210 // If pic is true, generates a PIC odex.
Richard Uhler94f5bda2015-07-22 08:25:11 -0700211 // The generated odex file will be un-relocated.
Richard Uhler66d874d2015-01-15 09:37:19 -0800212 void GenerateOdexForTest(const std::string& dex_location,
213 const std::string& odex_location,
214 bool pic = false) {
215 // For this operation, we temporarily redirect the dalvik cache so dex2oat
216 // doesn't find the relocated image file.
217 std::string android_data_tmp = GetScratchDir() + "AndroidDataTmp";
218 setenv("ANDROID_DATA", android_data_tmp.c_str(), 1);
219 std::vector<std::string> args;
220 args.push_back("--dex-file=" + dex_location);
221 args.push_back("--oat-file=" + odex_location);
222 if (pic) {
223 args.push_back("--compile-pic");
224 } else {
225 args.push_back("--include-patch-information");
Richard Uhler05dd8a62015-03-10 10:02:23 -0700226
227 // We need to use the quick compiler to generate non-PIC code, because
228 // the optimizing compiler always generates PIC.
229 args.push_back("--compiler-backend=Quick");
Richard Uhler66d874d2015-01-15 09:37:19 -0800230 }
231 args.push_back("--runtime-arg");
232 args.push_back("-Xnorelocate");
233 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700234 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800235 setenv("ANDROID_DATA", android_data_.c_str(), 1);
Richard Uhler94f5bda2015-07-22 08:25:11 -0700236
237 // Verify the odex file was generated as expected.
238 std::unique_ptr<OatFile> odex_file(OatFile::Open(
239 odex_location.c_str(), odex_location.c_str(), nullptr, nullptr,
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700240 false, dex_location.c_str(), &error_msg));
Richard Uhler94f5bda2015-07-22 08:25:11 -0700241 ASSERT_TRUE(odex_file.get() != nullptr) << error_msg;
242
243 if (!pic) {
244 DiagnoseFlakyTestFailure(*odex_file);
245 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800246 }
247
248 void GeneratePicOdexForTest(const std::string& dex_location,
249 const std::string& odex_location) {
250 GenerateOdexForTest(dex_location, odex_location, true);
251 }
252
253 private:
254 // Reserve memory around where the image will be loaded so other memory
255 // won't conflict when it comes time to load the image.
256 // This can be called with an already loaded image to reserve the space
257 // around it.
258 void ReserveImageSpace() {
259 MemMap::Init();
260
261 // Ensure a chunk of memory is reserved for the image space.
262 uintptr_t reservation_start = ART_BASE_ADDRESS + ART_BASE_ADDRESS_MIN_DELTA;
263 uintptr_t reservation_end = ART_BASE_ADDRESS + ART_BASE_ADDRESS_MAX_DELTA
Hiroshi Yamauchi3dbf2342015-03-17 16:01:11 -0700264 // Include the main space that has to come right after the
265 // image in case of the GSS collector.
266 + 384 * MB;
Richard Uhler66d874d2015-01-15 09:37:19 -0800267
Richard Uhler66d874d2015-01-15 09:37:19 -0800268 std::unique_ptr<BacktraceMap> map(BacktraceMap::Create(getpid(), true));
269 ASSERT_TRUE(map.get() != nullptr) << "Failed to build process map";
270 for (BacktraceMap::const_iterator it = map->begin();
271 reservation_start < reservation_end && it != map->end(); ++it) {
Richard Uhler3efe9792015-03-30 16:18:03 -0700272 ReserveImageSpaceChunk(reservation_start, std::min(it->start, reservation_end));
273 reservation_start = std::max(reservation_start, it->end);
274 }
275 ReserveImageSpaceChunk(reservation_start, reservation_end);
276 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800277
Richard Uhler3efe9792015-03-30 16:18:03 -0700278 // Reserve a chunk of memory for the image space in the given range.
279 // Only has effect for chunks with a positive number of bytes.
280 void ReserveImageSpaceChunk(uintptr_t start, uintptr_t end) {
281 if (start < end) {
282 std::string error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800283 image_reservation_.push_back(std::unique_ptr<MemMap>(
284 MemMap::MapAnonymous("image reservation",
Richard Uhler3efe9792015-03-30 16:18:03 -0700285 reinterpret_cast<uint8_t*>(start), end - start,
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700286 PROT_NONE, false, false, &error_msg)));
Richard Uhler66d874d2015-01-15 09:37:19 -0800287 ASSERT_TRUE(image_reservation_.back().get() != nullptr) << error_msg;
288 LOG(INFO) << "Reserved space for image " <<
289 reinterpret_cast<void*>(image_reservation_.back()->Begin()) << "-" <<
290 reinterpret_cast<void*>(image_reservation_.back()->End());
Richard Uhler66d874d2015-01-15 09:37:19 -0800291 }
292 }
293
294
295 // Unreserve any memory reserved by ReserveImageSpace. This should be called
296 // before the image is loaded.
297 void UnreserveImageSpace() {
298 image_reservation_.clear();
299 }
300
301 std::string scratch_dir_;
Richard Uhler63434112015-03-16 14:32:16 -0700302 std::string odex_oat_dir_;
303 std::string odex_dir_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800304 std::vector<std::unique_ptr<MemMap>> image_reservation_;
305};
306
307class OatFileAssistantNoDex2OatTest : public OatFileAssistantTest {
308 public:
309 virtual void SetUpRuntimeOptions(RuntimeOptions* options) {
310 OatFileAssistantTest::SetUpRuntimeOptions(options);
311 options->push_back(std::make_pair("-Xnodex2oat", nullptr));
312 }
313};
314
315// Generate an oat file for the purposes of test, as opposed to testing
316// generation of oat files.
317static void GenerateOatForTest(const char* dex_location) {
318 OatFileAssistant oat_file_assistant(dex_location, kRuntimeISA, false);
319
320 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700321 ASSERT_TRUE(oat_file_assistant.GenerateOatFile(&error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800322}
323
324// Case: We have a DEX file, but no OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700325// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800326TEST_F(OatFileAssistantTest, DexNoOat) {
327 std::string dex_location = GetScratchDir() + "/DexNoOat.jar";
328 Copy(GetDexSrc1(), dex_location);
329
330 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
331
Richard Uhler95abd042015-03-24 09:51:28 -0700332 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800333
334 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
335 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
336 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
337 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
338 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700339 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OdexFileStatus());
Richard Uhler66d874d2015-01-15 09:37:19 -0800340 EXPECT_FALSE(oat_file_assistant.OatFileExists());
341 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
342 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
343 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700344 EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OatFileStatus());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700345 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800346}
347
348// Case: We have no DEX file and no OAT file.
Richard Uhler9b994ea2015-06-24 08:44:19 -0700349// Expect: Status is kNoDexOptNeeded. Loading should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800350TEST_F(OatFileAssistantTest, NoDexNoOat) {
351 std::string dex_location = GetScratchDir() + "/NoDexNoOat.jar";
352
353 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
354
Richard Uhler9b994ea2015-06-24 08:44:19 -0700355 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
356 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
357
358 // Trying to make the oat file up to date should not fail or crash.
359 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700360 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(&error_msg));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700361
362 // Trying to get the best oat file should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800363 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
364 EXPECT_EQ(nullptr, oat_file.get());
365}
366
367// Case: We have a DEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700368// Expect: The status is kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800369TEST_F(OatFileAssistantTest, OatUpToDate) {
370 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
371 Copy(GetDexSrc1(), dex_location);
372 GenerateOatForTest(dex_location.c_str());
373
374 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
375
Richard Uhler95abd042015-03-24 09:51:28 -0700376 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800377 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
378 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
379 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
380 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
381 EXPECT_TRUE(oat_file_assistant.OatFileExists());
382 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
383 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
384 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler95abd042015-03-24 09:51:28 -0700385 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700386 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800387}
388
389// Case: We have a MultiDEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700390// Expect: The status is kNoDexOptNeeded and we load all dex files.
Richard Uhler66d874d2015-01-15 09:37:19 -0800391TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) {
392 std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar";
393 Copy(GetMultiDexSrc1(), dex_location);
394 GenerateOatForTest(dex_location.c_str());
395
Richard Uhlere5fed032015-03-18 08:21:11 -0700396 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler95abd042015-03-24 09:51:28 -0700397 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700398 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700399
400 // Verify we can load both dex files.
Richard Uhlere5fed032015-03-18 08:21:11 -0700401 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
Richard Uhler66d874d2015-01-15 09:37:19 -0800402 ASSERT_TRUE(oat_file.get() != nullptr);
403 EXPECT_TRUE(oat_file->IsExecutable());
404 std::vector<std::unique_ptr<const DexFile>> dex_files;
Richard Uhlere5fed032015-03-18 08:21:11 -0700405 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
406 EXPECT_EQ(2u, dex_files.size());
407}
408
Richard Uhler67ff7d12015-05-14 13:21:13 -0700409// Case: We have a MultiDEX file where the secondary dex file is out of date.
410// Expect: The status is kDex2OatNeeded.
411TEST_F(OatFileAssistantTest, MultiDexSecondaryOutOfDate) {
412 std::string dex_location = GetScratchDir() + "/MultiDexSecondaryOutOfDate.jar";
413
414 // Compile code for GetMultiDexSrc1.
415 Copy(GetMultiDexSrc1(), dex_location);
416 GenerateOatForTest(dex_location.c_str());
417
418 // Now overwrite the dex file with GetMultiDexSrc2 so the secondary checksum
419 // is out of date.
420 Copy(GetMultiDexSrc2(), dex_location);
421
422 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
423 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700424 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler67ff7d12015-05-14 13:21:13 -0700425}
426
Richard Uhlere5fed032015-03-18 08:21:11 -0700427// Case: We have a MultiDEX file and up-to-date OAT file for it with relative
428// encoded dex locations.
Richard Uhler95abd042015-03-24 09:51:28 -0700429// Expect: The oat file status is kNoDexOptNeeded.
Richard Uhlere5fed032015-03-18 08:21:11 -0700430TEST_F(OatFileAssistantTest, RelativeEncodedDexLocation) {
431 std::string dex_location = GetScratchDir() + "/RelativeEncodedDexLocation.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700432 std::string oat_location = GetOdexDir() + "/RelativeEncodedDexLocation.oat";
Richard Uhlere5fed032015-03-18 08:21:11 -0700433
434 // Create the dex file
435 Copy(GetMultiDexSrc1(), dex_location);
436
437 // Create the oat file with relative encoded dex location.
438 std::vector<std::string> args;
439 args.push_back("--dex-file=" + dex_location);
440 args.push_back("--dex-location=" + std::string("RelativeEncodedDexLocation.jar"));
441 args.push_back("--oat-file=" + oat_location);
442
443 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700444 ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
Richard Uhlere5fed032015-03-18 08:21:11 -0700445
446 // Verify we can load both dex files.
447 OatFileAssistant oat_file_assistant(dex_location.c_str(),
448 oat_location.c_str(),
449 kRuntimeISA, true);
450 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
451 ASSERT_TRUE(oat_file.get() != nullptr);
452 EXPECT_TRUE(oat_file->IsExecutable());
453 std::vector<std::unique_ptr<const DexFile>> dex_files;
454 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
Richard Uhler66d874d2015-01-15 09:37:19 -0800455 EXPECT_EQ(2u, dex_files.size());
456}
457
Richard Uhler95abd042015-03-24 09:51:28 -0700458// Case: We have a DEX file and out-of-date OAT file.
459// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800460TEST_F(OatFileAssistantTest, OatOutOfDate) {
461 std::string dex_location = GetScratchDir() + "/OatOutOfDate.jar";
462
463 // We create a dex, generate an oat for it, then overwrite the dex with a
464 // different dex to make the oat out of date.
465 Copy(GetDexSrc1(), dex_location);
466 GenerateOatForTest(dex_location.c_str());
467 Copy(GetDexSrc2(), dex_location);
468
469 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler95abd042015-03-24 09:51:28 -0700470 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800471
472 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
473 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
474 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
475 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
476 EXPECT_TRUE(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 Uhler66d874d2015-01-15 09:37:19 -0800480}
481
482// Case: We have a DEX file and an ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700483// Expect: The status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800484TEST_F(OatFileAssistantTest, DexOdexNoOat) {
485 std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700486 std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800487
488 // Create the dex and odex files
489 Copy(GetDexSrc1(), dex_location);
490 GenerateOdexForTest(dex_location, odex_location);
491
492 // Verify the status.
493 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
494
Richard Uhler95abd042015-03-24 09:51:28 -0700495 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800496
497 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
498 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
499 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
500 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
501 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
Richard Uhler66d874d2015-01-15 09:37:19 -0800502 EXPECT_FALSE(oat_file_assistant.OatFileExists());
503 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
504 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700505 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler5f946da2015-07-17 12:28:32 -0700506
507 // We should still be able to get the non-executable odex file to run from.
508 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
509 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhler2639e8e2015-07-20 09:40:34 -0700510
511 DiagnoseFlakyTestFailure(*oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -0800512}
513
514// Case: We have a stripped DEX file and an ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700515// Expect: The status is kPatchOatNeeded
Richard Uhler66d874d2015-01-15 09:37:19 -0800516TEST_F(OatFileAssistantTest, StrippedDexOdexNoOat) {
517 std::string dex_location = GetScratchDir() + "/StrippedDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700518 std::string odex_location = GetOdexDir() + "/StrippedDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800519
520 // Create the dex and odex files
521 Copy(GetDexSrc1(), dex_location);
522 GenerateOdexForTest(dex_location, odex_location);
523
524 // Strip the dex file
525 Copy(GetStrippedDexSrc1(), dex_location);
526
527 // Verify the status.
528 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
529
Richard Uhler95abd042015-03-24 09:51:28 -0700530 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800531
532 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
533 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
534 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
535 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
536 EXPECT_FALSE(oat_file_assistant.OatFileExists());
537 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
538 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700539 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800540
541 // Make the oat file up to date.
542 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700543 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800544
Richard Uhler95abd042015-03-24 09:51:28 -0700545 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800546
547 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
548 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
549 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
550 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
551 EXPECT_TRUE(oat_file_assistant.OatFileExists());
552 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
553 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700554 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800555
556 // Verify we can load the dex files from it.
557 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
558 ASSERT_TRUE(oat_file.get() != nullptr);
559 EXPECT_TRUE(oat_file->IsExecutable());
560 std::vector<std::unique_ptr<const DexFile>> dex_files;
561 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
562 EXPECT_EQ(1u, dex_files.size());
563}
564
Richard Uhler95abd042015-03-24 09:51:28 -0700565// Case: We have a stripped DEX file, an ODEX file, and an out-of-date OAT file.
566// Expect: The status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800567TEST_F(OatFileAssistantTest, StrippedDexOdexOat) {
568 std::string dex_location = GetScratchDir() + "/StrippedDexOdexOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700569 std::string odex_location = GetOdexDir() + "/StrippedDexOdexOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800570
571 // Create the oat file from a different dex file so it looks out of date.
572 Copy(GetDexSrc2(), dex_location);
573 GenerateOatForTest(dex_location.c_str());
574
575 // Create the odex file
576 Copy(GetDexSrc1(), dex_location);
577 GenerateOdexForTest(dex_location, odex_location);
578
579 // Strip the dex file.
580 Copy(GetStrippedDexSrc1(), dex_location);
581
582 // Verify the status.
583 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
584
Richard Uhler95abd042015-03-24 09:51:28 -0700585 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800586
587 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
588 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
589 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
590 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
591 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
592 EXPECT_TRUE(oat_file_assistant.OatFileExists());
593 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
594 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700595 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800596
597 // Make the oat file up to date.
598 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700599 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800600
Richard Uhler95abd042015-03-24 09:51:28 -0700601 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800602
603 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
604 EXPECT_TRUE(oat_file_assistant.OdexFileExists());
605 EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate());
606 EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation());
607 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
608 EXPECT_TRUE(oat_file_assistant.OatFileExists());
609 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
610 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
611 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700612 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800613
614 // Verify we can load the dex files from it.
615 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
616 ASSERT_TRUE(oat_file.get() != nullptr);
617 EXPECT_TRUE(oat_file->IsExecutable());
618 std::vector<std::unique_ptr<const DexFile>> dex_files;
619 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
620 EXPECT_EQ(1u, dex_files.size());
621}
622
Richard Uhler9b994ea2015-06-24 08:44:19 -0700623// Case: We have a stripped (or resource-only) DEX file, no ODEX file and no
624// OAT file. Expect: The status is kNoDexOptNeeded.
625TEST_F(OatFileAssistantTest, ResourceOnlyDex) {
626 std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar";
627
628 Copy(GetStrippedDexSrc1(), dex_location);
629
630 // Verify the status.
631 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
632
633 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
634
635 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
636 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
637 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
638 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
639 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
640 EXPECT_FALSE(oat_file_assistant.OatFileExists());
641 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
642 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
643 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
644
645 // Make the oat file up to date. This should have no effect.
646 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700647 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg;
Richard Uhler9b994ea2015-06-24 08:44:19 -0700648
649 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
650
651 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
652 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
653 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
654 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
655 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
656 EXPECT_FALSE(oat_file_assistant.OatFileExists());
657 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
658 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
659 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
660}
661
Richard Uhler95abd042015-03-24 09:51:28 -0700662// Case: We have a DEX file, no ODEX file and an OAT file that needs
663// relocation.
664// Expect: The status is kSelfPatchOatNeeded.
665TEST_F(OatFileAssistantTest, SelfRelocation) {
666 std::string dex_location = GetScratchDir() + "/SelfRelocation.jar";
667 std::string oat_location = GetOdexDir() + "/SelfRelocation.oat";
668
669 // Create the dex and odex files
670 Copy(GetDexSrc1(), dex_location);
671 GenerateOdexForTest(dex_location, oat_location);
672
673 OatFileAssistant oat_file_assistant(dex_location.c_str(),
674 oat_location.c_str(), kRuntimeISA, true);
675
676 EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
677
678 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
679 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
680 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
681 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
682 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
683 EXPECT_TRUE(oat_file_assistant.OatFileExists());
684 EXPECT_TRUE(oat_file_assistant.OatFileNeedsRelocation());
685 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
686 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700687 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700688
689 // Make the oat file up to date.
690 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700691 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg;
Richard Uhler95abd042015-03-24 09:51:28 -0700692
693 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
694
695 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
696 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
697 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
698 EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation());
699 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
700 EXPECT_TRUE(oat_file_assistant.OatFileExists());
701 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
702 EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation());
703 EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700704 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700705
706 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
707 ASSERT_TRUE(oat_file.get() != nullptr);
708 EXPECT_TRUE(oat_file->IsExecutable());
709 std::vector<std::unique_ptr<const DexFile>> dex_files;
710 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
711 EXPECT_EQ(1u, dex_files.size());
712}
713
Richard Uhler66d874d2015-01-15 09:37:19 -0800714// Case: We have a DEX file, an ODEX file and an OAT file, where the ODEX and
715// OAT files both have patch delta of 0.
Richard Uhler95abd042015-03-24 09:51:28 -0700716// Expect: It shouldn't crash, and status is kPatchOatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800717TEST_F(OatFileAssistantTest, OdexOatOverlap) {
718 std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700719 std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex";
720 std::string oat_location = GetOdexDir() + "/OdexOatOverlap.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -0800721
722 // Create the dex and odex files
723 Copy(GetDexSrc1(), dex_location);
724 GenerateOdexForTest(dex_location, odex_location);
725
726 // Create the oat file by copying the odex so they are located in the same
727 // place in memory.
728 Copy(odex_location, oat_location);
729
730 // Verify things don't go bad.
731 OatFileAssistant oat_file_assistant(dex_location.c_str(),
732 oat_location.c_str(), kRuntimeISA, true);
733
Richard Uhler95abd042015-03-24 09:51:28 -0700734 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded());
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_FALSE(oat_file_assistant.OdexFileIsUpToDate());
740 EXPECT_TRUE(oat_file_assistant.OatFileExists());
741 EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate());
742 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700743 EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800744
745 // Things aren't relocated, so it should fall back to interpreted.
746 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
747 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhlerf16d5722015-05-11 09:32:47 -0700748
Richard Uhler66d874d2015-01-15 09:37:19 -0800749 EXPECT_FALSE(oat_file->IsExecutable());
750 std::vector<std::unique_ptr<const DexFile>> dex_files;
751 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
752 EXPECT_EQ(1u, dex_files.size());
Richard Uhlerf16d5722015-05-11 09:32:47 -0700753
Richard Uhler2639e8e2015-07-20 09:40:34 -0700754 DiagnoseFlakyTestFailure(*oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -0800755}
756
757// Case: We have a DEX file and a PIC ODEX file, but no OAT file.
Richard Uhler95abd042015-03-24 09:51:28 -0700758// Expect: The status is kNoDexOptNeeded, because PIC needs no relocation.
Richard Uhler66d874d2015-01-15 09:37:19 -0800759TEST_F(OatFileAssistantTest, DexPicOdexNoOat) {
760 std::string dex_location = GetScratchDir() + "/DexPicOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700761 std::string odex_location = GetOdexDir() + "/DexPicOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800762
763 // Create the dex and odex files
764 Copy(GetDexSrc1(), dex_location);
765 GeneratePicOdexForTest(dex_location, odex_location);
766
767 // Verify the status.
768 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
769
Richard Uhler95abd042015-03-24 09:51:28 -0700770 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
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_TRUE(oat_file_assistant.OdexFileIsUpToDate());
776 EXPECT_FALSE(oat_file_assistant.OatFileExists());
777 EXPECT_TRUE(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
782// Case: We have a DEX file and up-to-date OAT file for it.
783// Expect: We should load an executable dex file.
784TEST_F(OatFileAssistantTest, LoadOatUpToDate) {
785 std::string dex_location = GetScratchDir() + "/LoadOatUpToDate.jar";
786
787 Copy(GetDexSrc1(), dex_location);
788 GenerateOatForTest(dex_location.c_str());
789
790 // Load the oat using an oat file assistant.
791 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
792
793 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
794 ASSERT_TRUE(oat_file.get() != nullptr);
795 EXPECT_TRUE(oat_file->IsExecutable());
796 std::vector<std::unique_ptr<const DexFile>> dex_files;
797 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
798 EXPECT_EQ(1u, dex_files.size());
799}
800
801// Case: We have a DEX file and up-to-date OAT file for it.
802// Expect: Loading non-executable should load the oat non-executable.
803TEST_F(OatFileAssistantTest, LoadNoExecOatUpToDate) {
804 std::string dex_location = GetScratchDir() + "/LoadNoExecOatUpToDate.jar";
805
806 Copy(GetDexSrc1(), dex_location);
807 GenerateOatForTest(dex_location.c_str());
808
809 // Load the oat using an oat file assistant.
810 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
811
812 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
813 ASSERT_TRUE(oat_file.get() != nullptr);
814 EXPECT_FALSE(oat_file->IsExecutable());
815 std::vector<std::unique_ptr<const DexFile>> dex_files;
816 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
817 EXPECT_EQ(1u, dex_files.size());
818}
819
820// Case: We have a DEX file.
821// Expect: We should load an executable dex file from an alternative oat
822// location.
823TEST_F(OatFileAssistantTest, LoadDexNoAlternateOat) {
824 std::string dex_location = GetScratchDir() + "/LoadDexNoAlternateOat.jar";
825 std::string oat_location = GetScratchDir() + "/LoadDexNoAlternateOat.oat";
826
827 Copy(GetDexSrc1(), dex_location);
828
829 OatFileAssistant oat_file_assistant(
830 dex_location.c_str(), oat_location.c_str(), kRuntimeISA, true);
831 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700832 ASSERT_TRUE(oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800833
834 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
835 ASSERT_TRUE(oat_file.get() != nullptr);
836 EXPECT_TRUE(oat_file->IsExecutable());
837 std::vector<std::unique_ptr<const DexFile>> dex_files;
838 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
839 EXPECT_EQ(1u, dex_files.size());
840
841 EXPECT_TRUE(OS::FileExists(oat_location.c_str()));
842
843 // Verify it didn't create an oat in the default location.
844 OatFileAssistant ofm(dex_location.c_str(), kRuntimeISA, false);
845 EXPECT_FALSE(ofm.OatFileExists());
846}
847
Richard Uhler66d874d2015-01-15 09:37:19 -0800848// Turn an absolute path into a path relative to the current working
849// directory.
850static std::string MakePathRelative(std::string target) {
851 char buf[MAXPATHLEN];
852 std::string cwd = getcwd(buf, MAXPATHLEN);
853
854 // Split the target and cwd paths into components.
855 std::vector<std::string> target_path;
856 std::vector<std::string> cwd_path;
857 Split(target, '/', &target_path);
858 Split(cwd, '/', &cwd_path);
859
860 // Reverse the path components, so we can use pop_back().
861 std::reverse(target_path.begin(), target_path.end());
862 std::reverse(cwd_path.begin(), cwd_path.end());
863
864 // Drop the common prefix of the paths. Because we reversed the path
865 // components, this becomes the common suffix of target_path and cwd_path.
866 while (!target_path.empty() && !cwd_path.empty()
867 && target_path.back() == cwd_path.back()) {
868 target_path.pop_back();
869 cwd_path.pop_back();
870 }
871
872 // For each element of the remaining cwd_path, add '..' to the beginning
873 // of the target path. Because we reversed the path components, we add to
874 // the end of target_path.
875 for (unsigned int i = 0; i < cwd_path.size(); i++) {
876 target_path.push_back("..");
877 }
878
879 // Reverse again to get the right path order, and join to get the result.
880 std::reverse(target_path.begin(), target_path.end());
881 return Join(target_path, '/');
882}
883
884// Case: Non-absolute path to Dex location.
885// Expect: Not sure, but it shouldn't crash.
886TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) {
887 std::string abs_dex_location = GetScratchDir() + "/NonAbsoluteDexLocation.jar";
888 Copy(GetDexSrc1(), abs_dex_location);
889
890 std::string dex_location = MakePathRelative(abs_dex_location);
891 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
892
893 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler95abd042015-03-24 09:51:28 -0700894 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800895 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
896 EXPECT_FALSE(oat_file_assistant.OatFileExists());
897 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
898 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
899 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
900 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
901}
902
903// Case: Very short, non-existent Dex location.
Richard Uhler9b994ea2015-06-24 08:44:19 -0700904// Expect: kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800905TEST_F(OatFileAssistantTest, ShortDexLocation) {
906 std::string dex_location = "/xx";
907
908 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
909
910 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700911 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800912 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
913 EXPECT_FALSE(oat_file_assistant.OatFileExists());
914 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
915 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
916 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
917 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700918 EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800919
Richard Uhler9b994ea2015-06-24 08:44:19 -0700920 // Trying to make it up to date should have no effect.
Richard Uhler66d874d2015-01-15 09:37:19 -0800921 std::string error_msg;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700922 EXPECT_TRUE(oat_file_assistant.MakeUpToDate(&error_msg));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700923 EXPECT_TRUE(error_msg.empty());
Richard Uhler66d874d2015-01-15 09:37:19 -0800924}
925
926// Case: Non-standard extension for dex file.
Richard Uhler95abd042015-03-24 09:51:28 -0700927// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800928TEST_F(OatFileAssistantTest, LongDexExtension) {
929 std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx";
930 Copy(GetDexSrc1(), dex_location);
931
932 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
933
Richard Uhler95abd042015-03-24 09:51:28 -0700934 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded());
Richard Uhler66d874d2015-01-15 09:37:19 -0800935
936 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
937 EXPECT_FALSE(oat_file_assistant.OdexFileExists());
938 EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate());
939 EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate());
940 EXPECT_FALSE(oat_file_assistant.OatFileExists());
941 EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate());
942 EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate());
943}
944
945// A task to generate a dex location. Used by the RaceToGenerate test.
946class RaceGenerateTask : public Task {
947 public:
948 explicit RaceGenerateTask(const std::string& dex_location, const std::string& oat_location)
949 : dex_location_(dex_location), oat_location_(oat_location),
950 loaded_oat_file_(nullptr)
951 {}
952
953 void Run(Thread* self) {
954 UNUSED(self);
955
956 // Load the dex files, and save a pointer to the loaded oat file, so that
957 // we can verify only one oat file was loaded for the dex location.
958 ClassLinker* linker = Runtime::Current()->GetClassLinker();
959 std::vector<std::unique_ptr<const DexFile>> dex_files;
960 std::vector<std::string> error_msgs;
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700961 dex_files = linker->OpenDexFilesFromOat(dex_location_.c_str(), oat_location_.c_str(), &error_msgs);
Richard Uhler66d874d2015-01-15 09:37:19 -0800962 CHECK(!dex_files.empty()) << Join(error_msgs, '\n');
Richard Uhler07b3c232015-03-31 15:57:54 -0700963 CHECK(dex_files[0]->GetOatDexFile() != nullptr) << dex_files[0]->GetLocation();
964 loaded_oat_file_ = dex_files[0]->GetOatDexFile()->GetOatFile();
Richard Uhler66d874d2015-01-15 09:37:19 -0800965 }
966
967 const OatFile* GetLoadedOatFile() const {
968 return loaded_oat_file_;
969 }
970
971 private:
972 std::string dex_location_;
973 std::string oat_location_;
974 const OatFile* loaded_oat_file_;
975};
976
977// Test the case where multiple processes race to generate an oat file.
978// This simulates multiple processes using multiple threads.
979//
980// We want only one Oat file to be loaded when there is a race to load, to
981// avoid using up the virtual memory address space.
982TEST_F(OatFileAssistantTest, RaceToGenerate) {
983 std::string dex_location = GetScratchDir() + "/RaceToGenerate.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700984 std::string oat_location = GetOdexDir() + "/RaceToGenerate.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -0800985
986 // We use the lib core dex file, because it's large, and hopefully should
987 // take a while to generate.
988 Copy(GetLibCoreDexFileName(), dex_location);
989
990 const int kNumThreads = 32;
991 Thread* self = Thread::Current();
992 ThreadPool thread_pool("Oat file assistant test thread pool", kNumThreads);
993 std::vector<std::unique_ptr<RaceGenerateTask>> tasks;
994 for (int i = 0; i < kNumThreads; i++) {
995 std::unique_ptr<RaceGenerateTask> task(new RaceGenerateTask(dex_location, oat_location));
996 thread_pool.AddTask(self, task.get());
997 tasks.push_back(std::move(task));
998 }
999 thread_pool.StartWorkers(self);
1000 thread_pool.Wait(self, true, false);
1001
1002 // Verify every task got the same pointer.
1003 const OatFile* expected = tasks[0]->GetLoadedOatFile();
1004 for (auto& task : tasks) {
1005 EXPECT_EQ(expected, task->GetLoadedOatFile());
1006 }
1007}
1008
1009// Case: We have a DEX file and an ODEX file, no OAT file, and dex2oat is
1010// disabled.
1011// Expect: We should load the odex file non-executable.
1012TEST_F(OatFileAssistantNoDex2OatTest, LoadDexOdexNoOat) {
1013 std::string dex_location = GetScratchDir() + "/LoadDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001014 std::string odex_location = GetOdexDir() + "/LoadDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001015
1016 // Create the dex and odex files
1017 Copy(GetDexSrc1(), dex_location);
1018 GenerateOdexForTest(dex_location, odex_location);
1019
1020 // Load the oat using an executable oat file assistant.
1021 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
1022
1023 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1024 ASSERT_TRUE(oat_file.get() != nullptr);
1025 EXPECT_FALSE(oat_file->IsExecutable());
1026 std::vector<std::unique_ptr<const DexFile>> dex_files;
1027 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1028 EXPECT_EQ(1u, dex_files.size());
1029}
1030
1031// Case: We have a MultiDEX file and an ODEX file, no OAT file, and dex2oat is
1032// disabled.
1033// Expect: We should load the odex file non-executable.
1034TEST_F(OatFileAssistantNoDex2OatTest, LoadMultiDexOdexNoOat) {
1035 std::string dex_location = GetScratchDir() + "/LoadMultiDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001036 std::string odex_location = GetOdexDir() + "/LoadMultiDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001037
1038 // Create the dex and odex files
1039 Copy(GetMultiDexSrc1(), dex_location);
1040 GenerateOdexForTest(dex_location, odex_location);
1041
1042 // Load the oat using an executable oat file assistant.
1043 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
1044
1045 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1046 ASSERT_TRUE(oat_file.get() != nullptr);
1047 EXPECT_FALSE(oat_file->IsExecutable());
1048 std::vector<std::unique_ptr<const DexFile>> dex_files;
1049 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1050 EXPECT_EQ(2u, dex_files.size());
1051}
1052
1053TEST(OatFileAssistantUtilsTest, DexFilenameToOdexFilename) {
1054 std::string error_msg;
1055 std::string odex_file;
1056
1057 EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001058 "/foo/bar/baz.jar", kArm, &odex_file, &error_msg)) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001059 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001060
1061 EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001062 "/foo/bar/baz.funnyext", kArm, &odex_file, &error_msg)) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001063 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001064
1065 EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001066 "nopath.jar", kArm, &odex_file, &error_msg));
Richard Uhler66d874d2015-01-15 09:37:19 -08001067 EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001068 "/foo/bar/baz_noext", kArm, &odex_file, &error_msg));
Richard Uhler66d874d2015-01-15 09:37:19 -08001069}
1070
Richard Uhler23cedd22015-04-08 13:17:29 -07001071// Verify the dexopt status values from dalvik.system.DexFile
1072// match the OatFileAssistant::DexOptStatus values.
1073TEST_F(OatFileAssistantTest, DexOptStatusValues) {
1074 ScopedObjectAccess soa(Thread::Current());
1075 StackHandleScope<1> hs(soa.Self());
1076 ClassLinker* linker = Runtime::Current()->GetClassLinker();
1077 Handle<mirror::Class> dexfile(
1078 hs.NewHandle(linker->FindSystemClass(soa.Self(), "Ldalvik/system/DexFile;")));
1079 ASSERT_FALSE(dexfile.Get() == nullptr);
1080 linker->EnsureInitialized(soa.Self(), dexfile, true, true);
1081
Mathieu Chartierc7853442015-03-27 14:35:38 -07001082 ArtField* no_dexopt_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001083 soa.Self(), dexfile, "NO_DEXOPT_NEEDED", "I");
1084 ASSERT_FALSE(no_dexopt_needed == nullptr);
1085 EXPECT_EQ(no_dexopt_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1086 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, no_dexopt_needed->GetInt(dexfile.Get()));
1087
Mathieu Chartierc7853442015-03-27 14:35:38 -07001088 ArtField* dex2oat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001089 soa.Self(), dexfile, "DEX2OAT_NEEDED", "I");
1090 ASSERT_FALSE(dex2oat_needed == nullptr);
1091 EXPECT_EQ(dex2oat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1092 EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, dex2oat_needed->GetInt(dexfile.Get()));
1093
Mathieu Chartierc7853442015-03-27 14:35:38 -07001094 ArtField* patchoat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001095 soa.Self(), dexfile, "PATCHOAT_NEEDED", "I");
1096 ASSERT_FALSE(patchoat_needed == nullptr);
1097 EXPECT_EQ(patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1098 EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, patchoat_needed->GetInt(dexfile.Get()));
1099
Mathieu Chartierc7853442015-03-27 14:35:38 -07001100 ArtField* self_patchoat_needed = mirror::Class::FindStaticField(
Richard Uhler23cedd22015-04-08 13:17:29 -07001101 soa.Self(), dexfile, "SELF_PATCHOAT_NEEDED", "I");
1102 ASSERT_FALSE(self_patchoat_needed == nullptr);
1103 EXPECT_EQ(self_patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1104 EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded, self_patchoat_needed->GetInt(dexfile.Get()));
1105}
Richard Uhler66d874d2015-01-15 09:37:19 -08001106
1107// TODO: More Tests:
1108// * Test class linker falls back to unquickened dex for DexNoOat
1109// * Test class linker falls back to unquickened dex for MultiDexNoOat
Richard Uhler66d874d2015-01-15 09:37:19 -08001110// * Test using secondary isa
1111// * Test with profiling info?
1112// * Test for status of oat while oat is being generated (how?)
1113// * Test case where 32 and 64 bit boot class paths differ,
1114// and we ask IsInBootClassPath for a class in exactly one of the 32 or
1115// 64 bit boot class paths.
1116// * Test unexpected scenarios (?):
1117// - Dex is stripped, don't have odex.
1118// - Oat file corrupted after status check, before reload unexecutable
1119// because it's unrelocated and no dex2oat
1120
1121} // namespace art