Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1 | /* |
| 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 17 | #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 Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 26 | #include "art_field-inl.h" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 27 | #include "class_linker-inl.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 28 | #include "common_runtime_test.h" |
Andreas Gampe | bb9c6b1 | 2015-03-29 13:56:36 -0700 | [diff] [blame] | 29 | #include "compiler_callbacks.h" |
Andreas Gampe | e1459ae | 2016-06-29 09:36:30 -0700 | [diff] [blame^] | 30 | #include "dex2oat_environment_test.h" |
Richard Uhler | f16d572 | 2015-05-11 09:32:47 -0700 | [diff] [blame] | 31 | #include "gc/space/image_space.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 32 | #include "mem_map.h" |
Andreas Gampe | e1459ae | 2016-06-29 09:36:30 -0700 | [diff] [blame^] | 33 | #include "oat_file_assistant.h" |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 34 | #include "oat_file_manager.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 35 | #include "os.h" |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 36 | #include "scoped_thread_state_change.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 37 | #include "thread-inl.h" |
| 38 | #include "utils.h" |
| 39 | |
| 40 | namespace art { |
| 41 | |
Andreas Gampe | e1459ae | 2016-06-29 09:36:30 -0700 | [diff] [blame^] | 42 | class OatFileAssistantTest : public Dex2oatEnvironmentTest { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 43 | public: |
Andreas Gampe | e1459ae | 2016-06-29 09:36:30 -0700 | [diff] [blame^] | 44 | virtual void SetUp() OVERRIDE { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 45 | ReserveImageSpace(); |
Andreas Gampe | e1459ae | 2016-06-29 09:36:30 -0700 | [diff] [blame^] | 46 | Dex2oatEnvironmentTest::SetUp(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 49 | // 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 70 | virtual void PreRuntimeCreate() { |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 71 | std::string error_msg; |
| 72 | ASSERT_TRUE(PreRelocateImage(&error_msg)) << error_msg; |
| 73 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 74 | UnreserveImageSpace(); |
| 75 | } |
| 76 | |
Andreas Gampe | e1459ae | 2016-06-29 09:36:30 -0700 | [diff] [blame^] | 77 | virtual void PostRuntimeCreate() OVERRIDE { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 78 | ReserveImageSpace(); |
| 79 | } |
| 80 | |
Richard Uhler | 93aa210 | 2015-08-10 14:47:41 -0700 | [diff] [blame] | 81 | // Generate a non-PIC odex file for the purposes of test. |
Richard Uhler | 94f5bda | 2015-07-22 08:25:11 -0700 | [diff] [blame] | 82 | // The generated odex file will be un-relocated. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 83 | void GenerateOdexForTest(const std::string& dex_location, |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 84 | const std::string& odex_location, |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 85 | 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 Uhler | 93aa210 | 2015-08-10 14:47:41 -0700 | [diff] [blame] | 92 | std::vector<std::string> args; |
| 93 | args.push_back("--dex-file=" + dex_location); |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 94 | args.push_back("--oat-file=" + odex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 95 | args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter)); |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 96 | args.push_back("--runtime-arg"); |
| 97 | args.push_back("-Xnorelocate"); |
Richard Uhler | 93aa210 | 2015-08-10 14:47:41 -0700 | [diff] [blame] | 98 | |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 99 | if (pic) { |
| 100 | args.push_back("--compile-pic"); |
| 101 | } |
| 102 | |
| 103 | if (with_patch_info) { |
| 104 | args.push_back("--include-patch-information"); |
| 105 | } |
Richard Uhler | 93aa210 | 2015-08-10 14:47:41 -0700 | [diff] [blame] | 106 | |
| 107 | std::string error_msg; |
| 108 | ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg; |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 109 | setenv("ANDROID_DATA", android_data_.c_str(), 1); |
Richard Uhler | 93aa210 | 2015-08-10 14:47:41 -0700 | [diff] [blame] | 110 | |
| 111 | // Verify the odex file was generated as expected and really is |
| 112 | // unrelocated. |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 113 | 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 Uhler | 93aa210 | 2015-08-10 14:47:41 -0700 | [diff] [blame] | 121 | ASSERT_TRUE(odex_file.get() != nullptr) << error_msg; |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 122 | EXPECT_EQ(pic, odex_file->IsPic()); |
| 123 | EXPECT_EQ(with_patch_info, odex_file->HasPatchInfo()); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 124 | EXPECT_EQ(filter, odex_file->GetCompilerFilter()); |
| 125 | |
Vladimir Marko | f6d1e0f | 2016-05-23 15:32:42 +0100 | [diff] [blame] | 126 | if (CompilerFilter::IsBytecodeCompilationEnabled(filter)) { |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 127 | const std::vector<gc::space::ImageSpace*> image_spaces = |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 128 | Runtime::Current()->GetHeap()->GetBootImageSpaces(); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 129 | 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 Hao | b11ffb7 | 2016-04-07 15:40:54 -0700 | [diff] [blame] | 132 | uint32_t combined_checksum = OatFileAssistant::CalculateCombinedImageChecksum(); |
| 133 | EXPECT_EQ(combined_checksum, oat_header.GetImageFileLocationOatChecksum()); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 134 | EXPECT_NE(reinterpret_cast<uintptr_t>(image_header.GetOatDataBegin()), |
| 135 | oat_header.GetImageFileLocationOatDataBegin()); |
| 136 | EXPECT_NE(image_header.GetPatchDelta(), oat_header.GetImagePatchDelta()); |
| 137 | } |
Richard Uhler | 93aa210 | 2015-08-10 14:47:41 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void GeneratePicOdexForTest(const std::string& dex_location, |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 141 | const std::string& odex_location, |
| 142 | CompilerFilter::Filter filter) { |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 143 | GenerateOdexForTest(dex_location, odex_location, filter, true, false); |
Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 144 | } |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 145 | |
Richard Uhler | d1537b5 | 2016-03-29 13:27:41 -0700 | [diff] [blame] | 146 | // Generate a non-PIC odex file without patch information for the purposes |
| 147 | // of test. The generated odex file will be un-relocated. |
Richard Uhler | d1537b5 | 2016-03-29 13:27:41 -0700 | [diff] [blame] | 148 | void GenerateNoPatchOdexForTest(const std::string& dex_location, |
| 149 | const std::string& odex_location, |
| 150 | CompilerFilter::Filter filter) { |
Richard Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 151 | GenerateOdexForTest(dex_location, odex_location, filter, false, false); |
Richard Uhler | d1537b5 | 2016-03-29 13:27:41 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 154 | 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 Uhler | a48403e | 2016-04-26 10:24:38 -0700 | [diff] [blame] | 163 | // 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 167 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 168 | 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 Uhler | 3efe979 | 2015-03-30 16:18:03 -0700 | [diff] [blame] | 172 | 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 177 | |
Richard Uhler | 3efe979 | 2015-03-30 16:18:03 -0700 | [diff] [blame] | 178 | // 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 183 | image_reservation_.push_back(std::unique_ptr<MemMap>( |
| 184 | MemMap::MapAnonymous("image reservation", |
Richard Uhler | 3efe979 | 2015-03-30 16:18:03 -0700 | [diff] [blame] | 185 | reinterpret_cast<uint8_t*>(start), end - start, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 186 | PROT_NONE, false, false, &error_msg))); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 187 | 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 191 | } |
| 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 201 | std::vector<std::unique_ptr<MemMap>> image_reservation_; |
| 202 | }; |
| 203 | |
| 204 | class 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 Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 214 | static void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter) { |
| 215 | // Use an oat file assistant to find the proper oat location. |
| 216 | OatFileAssistant ofa(dex_location, kRuntimeISA, false, false); |
| 217 | const std::string* oat_location = ofa.OatFileName(); |
| 218 | ASSERT_TRUE(oat_location != nullptr); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 219 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 220 | std::vector<std::string> args; |
| 221 | args.push_back("--dex-file=" + std::string(dex_location)); |
| 222 | args.push_back("--oat-file=" + *oat_location); |
| 223 | args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter)); |
| 224 | args.push_back("--runtime-arg"); |
| 225 | args.push_back("-Xnorelocate"); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 226 | std::string error_msg; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 227 | ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg; |
| 228 | |
| 229 | // Verify the oat file was generated as expected. |
| 230 | std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location->c_str(), |
| 231 | oat_location->c_str(), |
| 232 | 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // Case: We have a DEX file, but no OAT file for it. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 243 | // Expect: The status is kDex2OatNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 244 | TEST_F(OatFileAssistantTest, DexNoOat) { |
| 245 | std::string dex_location = GetScratchDir() + "/DexNoOat.jar"; |
| 246 | Copy(GetDexSrc1(), dex_location); |
| 247 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 248 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 249 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 250 | 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 258 | |
| 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 Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 264 | EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OdexFileStatus()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 265 | 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 Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 269 | EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OatFileStatus()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 270 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | // Case: We have no DEX file and no OAT file. |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 274 | // Expect: Status is kNoDexOptNeeded. Loading should fail, but not crash. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 275 | TEST_F(OatFileAssistantTest, NoDexNoOat) { |
| 276 | std::string dex_location = GetScratchDir() + "/NoDexNoOat.jar"; |
| 277 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 278 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 279 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 280 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 281 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 282 | 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 Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 286 | EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, oat_file_assistant.MakeUpToDate(&error_msg)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 287 | |
| 288 | // Trying to get the best oat file should fail, but not crash. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 289 | 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 Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 294 | // Expect: The status is kNoDexOptNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 295 | TEST_F(OatFileAssistantTest, OatUpToDate) { |
| 296 | std::string dex_location = GetScratchDir() + "/OatUpToDate.jar"; |
| 297 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 298 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 299 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 300 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 301 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 302 | 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 311 | 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 Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 319 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 320 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 323 | // Case: We have a DEX file and speed-profile OAT file for it. |
| 324 | // Expect: The status is kNoDexOptNeeded if the profile hasn't changed. |
| 325 | TEST_F(OatFileAssistantTest, ProfileOatUpToDate) { |
| 326 | std::string dex_location = GetScratchDir() + "/ProfileOatUpToDate.jar"; |
| 327 | Copy(GetDexSrc1(), dex_location); |
| 328 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile); |
| 329 | |
| 330 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
| 331 | |
| 332 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 333 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile)); |
| 334 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 335 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); |
| 336 | |
| 337 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 338 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 339 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 340 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 341 | EXPECT_TRUE(oat_file_assistant.OatFileExists()); |
| 342 | EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate()); |
| 343 | EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation()); |
| 344 | EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate()); |
| 345 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus()); |
| 346 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
| 347 | } |
| 348 | |
| 349 | // Case: We have a DEX file and speed-profile OAT file for it. |
| 350 | // Expect: The status is kNoDex2OatNeeded if the profile has changed. |
| 351 | TEST_F(OatFileAssistantTest, ProfileOatOutOfDate) { |
| 352 | std::string dex_location = GetScratchDir() + "/ProfileOatOutOfDate.jar"; |
| 353 | Copy(GetDexSrc1(), dex_location); |
| 354 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile); |
| 355 | |
| 356 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true, false); |
| 357 | |
| 358 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 359 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile)); |
| 360 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 361 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); |
| 362 | |
| 363 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 364 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 365 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 366 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 367 | EXPECT_TRUE(oat_file_assistant.OatFileExists()); |
| 368 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 369 | EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation()); |
| 370 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
| 371 | EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OatFileStatus()); |
| 372 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
| 373 | } |
| 374 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 375 | // Case: We have a MultiDEX file and up-to-date OAT file for it. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 376 | // Expect: The status is kNoDexOptNeeded and we load all dex files. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 377 | TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) { |
| 378 | std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar"; |
| 379 | Copy(GetMultiDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 380 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 381 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 382 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
| 383 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 384 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 385 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 386 | |
| 387 | // Verify we can load both dex files. |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 388 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 389 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 390 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 391 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 392 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 393 | EXPECT_EQ(2u, dex_files.size()); |
| 394 | } |
| 395 | |
Richard Uhler | 67ff7d1 | 2015-05-14 13:21:13 -0700 | [diff] [blame] | 396 | // Case: We have a MultiDEX file where the secondary dex file is out of date. |
| 397 | // Expect: The status is kDex2OatNeeded. |
| 398 | TEST_F(OatFileAssistantTest, MultiDexSecondaryOutOfDate) { |
| 399 | std::string dex_location = GetScratchDir() + "/MultiDexSecondaryOutOfDate.jar"; |
| 400 | |
| 401 | // Compile code for GetMultiDexSrc1. |
| 402 | Copy(GetMultiDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 403 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 67ff7d1 | 2015-05-14 13:21:13 -0700 | [diff] [blame] | 404 | |
| 405 | // Now overwrite the dex file with GetMultiDexSrc2 so the secondary checksum |
| 406 | // is out of date. |
| 407 | Copy(GetMultiDexSrc2(), dex_location); |
| 408 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 409 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
| 410 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 411 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 412 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 67ff7d1 | 2015-05-14 13:21:13 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 415 | // Case: We have a MultiDEX file and up-to-date OAT file for it with relative |
| 416 | // encoded dex locations. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 417 | // Expect: The oat file status is kNoDexOptNeeded. |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 418 | TEST_F(OatFileAssistantTest, RelativeEncodedDexLocation) { |
| 419 | std::string dex_location = GetScratchDir() + "/RelativeEncodedDexLocation.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 420 | std::string oat_location = GetOdexDir() + "/RelativeEncodedDexLocation.oat"; |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 421 | |
| 422 | // Create the dex file |
| 423 | Copy(GetMultiDexSrc1(), dex_location); |
| 424 | |
| 425 | // Create the oat file with relative encoded dex location. |
| 426 | std::vector<std::string> args; |
| 427 | args.push_back("--dex-file=" + dex_location); |
| 428 | args.push_back("--dex-location=" + std::string("RelativeEncodedDexLocation.jar")); |
| 429 | args.push_back("--oat-file=" + oat_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 430 | args.push_back("--compiler-filter=speed"); |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 431 | |
| 432 | std::string error_msg; |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 433 | ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg; |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 434 | |
| 435 | // Verify we can load both dex files. |
| 436 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 437 | oat_location.c_str(), |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 438 | kRuntimeISA, false, true); |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 439 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 440 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 441 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 442 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 443 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 444 | EXPECT_EQ(2u, dex_files.size()); |
| 445 | } |
| 446 | |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 447 | // Case: We have a DEX file and out-of-date OAT file. |
| 448 | // Expect: The status is kDex2OatNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 449 | TEST_F(OatFileAssistantTest, OatOutOfDate) { |
| 450 | std::string dex_location = GetScratchDir() + "/OatOutOfDate.jar"; |
| 451 | |
| 452 | // We create a dex, generate an oat for it, then overwrite the dex with a |
| 453 | // different dex to make the oat out of date. |
| 454 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 455 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 456 | Copy(GetDexSrc2(), dex_location); |
| 457 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 458 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
| 459 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 460 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); |
| 461 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 462 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 463 | |
| 464 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 465 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 466 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 467 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 468 | EXPECT_TRUE(oat_file_assistant.OatFileExists()); |
| 469 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 470 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 471 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | // Case: We have a DEX file and an ODEX file, but no OAT file. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 475 | // Expect: The status is kPatchOatNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 476 | TEST_F(OatFileAssistantTest, DexOdexNoOat) { |
| 477 | std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 478 | std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 479 | |
| 480 | // Create the dex and odex files |
| 481 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 482 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 483 | |
| 484 | // Verify the status. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 485 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 486 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 487 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 488 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); |
| 489 | EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, |
| 490 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 491 | |
| 492 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 493 | EXPECT_TRUE(oat_file_assistant.OdexFileExists()); |
| 494 | EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 495 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 496 | EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 497 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 498 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 499 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 500 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 5f946da | 2015-07-17 12:28:32 -0700 | [diff] [blame] | 501 | |
| 502 | // We should still be able to get the non-executable odex file to run from. |
| 503 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 504 | ASSERT_TRUE(oat_file.get() != nullptr); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | // Case: We have a stripped DEX file and an ODEX file, but no OAT file. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 508 | // Expect: The status is kPatchOatNeeded |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 509 | TEST_F(OatFileAssistantTest, StrippedDexOdexNoOat) { |
| 510 | std::string dex_location = GetScratchDir() + "/StrippedDexOdexNoOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 511 | std::string odex_location = GetOdexDir() + "/StrippedDexOdexNoOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 512 | |
| 513 | // Create the dex and odex files |
| 514 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 515 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 516 | |
| 517 | // Strip the dex file |
| 518 | Copy(GetStrippedDexSrc1(), dex_location); |
| 519 | |
| 520 | // Verify the status. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 521 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 522 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 523 | EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, |
| 524 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 525 | |
| 526 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 527 | EXPECT_TRUE(oat_file_assistant.OdexFileExists()); |
| 528 | EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 529 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 530 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 531 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 532 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 533 | EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 534 | |
| 535 | // Make the oat file up to date. |
| 536 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 537 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 538 | ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 539 | oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 540 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 541 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 542 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 543 | |
| 544 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 545 | EXPECT_TRUE(oat_file_assistant.OdexFileExists()); |
| 546 | EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 547 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 548 | EXPECT_TRUE(oat_file_assistant.OatFileExists()); |
| 549 | EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate()); |
| 550 | EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 551 | EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 552 | |
| 553 | // Verify we can load the dex files from it. |
| 554 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 555 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 556 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 557 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 558 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 559 | EXPECT_EQ(1u, dex_files.size()); |
| 560 | } |
| 561 | |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 562 | // Case: We have a stripped DEX file, an ODEX file, and an out-of-date OAT file. |
| 563 | // Expect: The status is kPatchOatNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 564 | TEST_F(OatFileAssistantTest, StrippedDexOdexOat) { |
| 565 | std::string dex_location = GetScratchDir() + "/StrippedDexOdexOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 566 | std::string odex_location = GetOdexDir() + "/StrippedDexOdexOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 567 | |
| 568 | // Create the oat file from a different dex file so it looks out of date. |
| 569 | Copy(GetDexSrc2(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 570 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 571 | |
| 572 | // Create the odex file |
| 573 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 574 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 575 | |
| 576 | // Strip the dex file. |
| 577 | Copy(GetStrippedDexSrc1(), dex_location); |
| 578 | |
| 579 | // Verify the status. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 580 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 581 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 582 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 583 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); |
| 584 | EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, |
| 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 Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 588 | |
| 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_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 596 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 597 | EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 598 | |
| 599 | // Make the oat file up to date. |
| 600 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 601 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 602 | ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 603 | oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 604 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 605 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 606 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
| 607 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, // Can't run dex2oat because dex file is stripped. |
| 608 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 609 | |
| 610 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 611 | EXPECT_TRUE(oat_file_assistant.OdexFileExists()); |
| 612 | EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 613 | EXPECT_TRUE(oat_file_assistant.OdexFileNeedsRelocation()); |
| 614 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 615 | EXPECT_TRUE(oat_file_assistant.OatFileExists()); |
| 616 | EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate()); |
| 617 | EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation()); |
| 618 | EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 619 | EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 620 | |
| 621 | // Verify we can load the dex files from it. |
| 622 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 623 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 624 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 625 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 626 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 627 | EXPECT_EQ(1u, dex_files.size()); |
| 628 | } |
| 629 | |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 630 | // Case: We have a stripped (or resource-only) DEX file, no ODEX file and no |
| 631 | // OAT file. Expect: The status is kNoDexOptNeeded. |
| 632 | TEST_F(OatFileAssistantTest, ResourceOnlyDex) { |
| 633 | std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar"; |
| 634 | |
| 635 | Copy(GetStrippedDexSrc1(), dex_location); |
| 636 | |
| 637 | // Verify the status. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 638 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 639 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 640 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 641 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
| 642 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 643 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); |
| 644 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 645 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 646 | |
| 647 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 648 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 649 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 650 | EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation()); |
| 651 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 652 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 653 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 654 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
| 655 | EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles()); |
| 656 | |
| 657 | // Make the oat file up to date. This should have no effect. |
| 658 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 659 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 660 | EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 661 | oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 662 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 663 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 664 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 665 | |
| 666 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 667 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 668 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 669 | EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation()); |
| 670 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 671 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 672 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 673 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
| 674 | EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles()); |
| 675 | } |
| 676 | |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 677 | // Case: We have a DEX file, no ODEX file and an OAT file that needs |
| 678 | // relocation. |
| 679 | // Expect: The status is kSelfPatchOatNeeded. |
| 680 | TEST_F(OatFileAssistantTest, SelfRelocation) { |
| 681 | std::string dex_location = GetScratchDir() + "/SelfRelocation.jar"; |
| 682 | std::string oat_location = GetOdexDir() + "/SelfRelocation.oat"; |
| 683 | |
| 684 | // Create the dex and odex files |
| 685 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 686 | GenerateOdexForTest(dex_location, oat_location, CompilerFilter::kSpeed); |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 687 | |
| 688 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 689 | oat_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 690 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 691 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 692 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); |
| 693 | EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded, |
| 694 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
| 695 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 696 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything)); |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 697 | |
| 698 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 699 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 700 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 701 | EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation()); |
| 702 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 703 | EXPECT_TRUE(oat_file_assistant.OatFileExists()); |
| 704 | EXPECT_TRUE(oat_file_assistant.OatFileNeedsRelocation()); |
| 705 | EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate()); |
| 706 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 707 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 708 | |
| 709 | // Make the oat file up to date. |
| 710 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 711 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 712 | ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 713 | oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 714 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 715 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 716 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 717 | |
| 718 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 719 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 720 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 721 | EXPECT_FALSE(oat_file_assistant.OdexFileNeedsRelocation()); |
| 722 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 723 | EXPECT_TRUE(oat_file_assistant.OatFileExists()); |
| 724 | EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate()); |
| 725 | EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation()); |
| 726 | EXPECT_TRUE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 727 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 728 | |
| 729 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 730 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 731 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 732 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 733 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 734 | EXPECT_EQ(1u, dex_files.size()); |
| 735 | } |
| 736 | |
Richard Uhler | d1537b5 | 2016-03-29 13:27:41 -0700 | [diff] [blame] | 737 | // Case: We have a DEX file, no ODEX file and an OAT file that needs |
| 738 | // relocation but doesn't have patch info. |
| 739 | // Expect: The status is kDex2OatNeeded, because we can't run patchoat. |
| 740 | TEST_F(OatFileAssistantTest, NoSelfRelocation) { |
| 741 | std::string dex_location = GetScratchDir() + "/NoSelfRelocation.jar"; |
| 742 | std::string oat_location = GetOdexDir() + "/NoSelfRelocation.oat"; |
| 743 | |
| 744 | // Create the dex and odex files |
| 745 | Copy(GetDexSrc1(), dex_location); |
| 746 | GenerateNoPatchOdexForTest(dex_location, oat_location, CompilerFilter::kSpeed); |
| 747 | |
| 748 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 749 | oat_location.c_str(), kRuntimeISA, false, true); |
| 750 | |
| 751 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 752 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
| 753 | |
| 754 | // Make the oat file up to date. |
| 755 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 756 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 757 | ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 758 | oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; |
Richard Uhler | d1537b5 | 2016-03-29 13:27:41 -0700 | [diff] [blame] | 759 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 760 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
| 761 | |
| 762 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 763 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 764 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 765 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 766 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 767 | EXPECT_EQ(1u, dex_files.size()); |
| 768 | } |
| 769 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 770 | // Case: We have a DEX file, an ODEX file and an OAT file, where the ODEX and |
| 771 | // OAT files both have patch delta of 0. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 772 | // Expect: It shouldn't crash, and status is kPatchOatNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 773 | TEST_F(OatFileAssistantTest, OdexOatOverlap) { |
| 774 | std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 775 | std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex"; |
| 776 | std::string oat_location = GetOdexDir() + "/OdexOatOverlap.oat"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 777 | |
| 778 | // Create the dex and odex files |
| 779 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 780 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 781 | |
| 782 | // Create the oat file by copying the odex so they are located in the same |
| 783 | // place in memory. |
| 784 | Copy(odex_location, oat_location); |
| 785 | |
| 786 | // Verify things don't go bad. |
| 787 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 788 | oat_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 789 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 790 | EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, |
| 791 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 792 | |
| 793 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 794 | EXPECT_TRUE(oat_file_assistant.OdexFileExists()); |
| 795 | EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 796 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 797 | EXPECT_TRUE(oat_file_assistant.OatFileExists()); |
| 798 | EXPECT_FALSE(oat_file_assistant.OatFileIsOutOfDate()); |
| 799 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 800 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 801 | |
| 802 | // Things aren't relocated, so it should fall back to interpreted. |
| 803 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 804 | ASSERT_TRUE(oat_file.get() != nullptr); |
Richard Uhler | f16d572 | 2015-05-11 09:32:47 -0700 | [diff] [blame] | 805 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 806 | EXPECT_FALSE(oat_file->IsExecutable()); |
| 807 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 808 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 809 | EXPECT_EQ(1u, dex_files.size()); |
| 810 | } |
| 811 | |
| 812 | // Case: We have a DEX file and a PIC ODEX file, but no OAT file. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 813 | // Expect: The status is kNoDexOptNeeded, because PIC needs no relocation. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 814 | TEST_F(OatFileAssistantTest, DexPicOdexNoOat) { |
| 815 | std::string dex_location = GetScratchDir() + "/DexPicOdexNoOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 816 | std::string odex_location = GetOdexDir() + "/DexPicOdexNoOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 817 | |
| 818 | // Create the dex and odex files |
| 819 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 820 | GeneratePicOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 821 | |
| 822 | // Verify the status. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 823 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 824 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 825 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 826 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
| 827 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 828 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kEverything)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 829 | |
| 830 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 831 | EXPECT_TRUE(oat_file_assistant.OdexFileExists()); |
| 832 | EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 833 | EXPECT_TRUE(oat_file_assistant.OdexFileIsUpToDate()); |
| 834 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 835 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 836 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 837 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 838 | } |
| 839 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 840 | // Case: We have a DEX file and a VerifyAtRuntime ODEX file, but no OAT file. |
| 841 | // Expect: The status is kNoDexOptNeeded, because VerifyAtRuntime contains no code. |
| 842 | TEST_F(OatFileAssistantTest, DexVerifyAtRuntimeOdexNoOat) { |
| 843 | std::string dex_location = GetScratchDir() + "/DexVerifyAtRuntimeOdexNoOat.jar"; |
| 844 | std::string odex_location = GetOdexDir() + "/DexVerifyAtRuntimeOdexNoOat.odex"; |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 845 | |
| 846 | // Create the dex and odex files |
| 847 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 848 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kVerifyAtRuntime); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 849 | |
| 850 | // Verify the status. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 851 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 852 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 853 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 854 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); |
| 855 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 856 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 857 | |
| 858 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 859 | EXPECT_TRUE(oat_file_assistant.OdexFileExists()); |
| 860 | EXPECT_FALSE(oat_file_assistant.OdexFileIsOutOfDate()); |
Nicolas Geoffray | 845e506 | 2016-03-23 06:42:05 +0000 | [diff] [blame] | 861 | EXPECT_TRUE(oat_file_assistant.OdexFileIsUpToDate()); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 862 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 863 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 864 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
| 865 | EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); |
| 866 | } |
| 867 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 868 | // Case: We have a DEX file and up-to-date OAT file for it. |
| 869 | // Expect: We should load an executable dex file. |
| 870 | TEST_F(OatFileAssistantTest, LoadOatUpToDate) { |
| 871 | std::string dex_location = GetScratchDir() + "/LoadOatUpToDate.jar"; |
| 872 | |
| 873 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 874 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 875 | |
| 876 | // Load the oat using an oat file assistant. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 877 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
| 878 | |
| 879 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 880 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 881 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 882 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 883 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 884 | EXPECT_EQ(1u, dex_files.size()); |
| 885 | } |
| 886 | |
| 887 | // Case: We have a DEX file and up-to-date interpret-only OAT file for it. |
| 888 | // Expect: We should still load the oat file as executable. |
| 889 | TEST_F(OatFileAssistantTest, LoadExecInterpretOnlyOatUpToDate) { |
| 890 | std::string dex_location = GetScratchDir() + "/LoadExecInterpretOnlyOatUpToDate.jar"; |
| 891 | |
| 892 | Copy(GetDexSrc1(), dex_location); |
| 893 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kInterpretOnly); |
| 894 | |
| 895 | // Load the oat using an oat file assistant. |
| 896 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 897 | |
| 898 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 899 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 900 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 901 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 902 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 903 | EXPECT_EQ(1u, dex_files.size()); |
| 904 | } |
| 905 | |
| 906 | // Case: We have a DEX file and up-to-date OAT file for it. |
| 907 | // Expect: Loading non-executable should load the oat non-executable. |
| 908 | TEST_F(OatFileAssistantTest, LoadNoExecOatUpToDate) { |
| 909 | std::string dex_location = GetScratchDir() + "/LoadNoExecOatUpToDate.jar"; |
| 910 | |
| 911 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 912 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 913 | |
| 914 | // Load the oat using an oat file assistant. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 915 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 916 | |
| 917 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 918 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 919 | EXPECT_FALSE(oat_file->IsExecutable()); |
| 920 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 921 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 922 | EXPECT_EQ(1u, dex_files.size()); |
| 923 | } |
| 924 | |
| 925 | // Case: We have a DEX file. |
| 926 | // Expect: We should load an executable dex file from an alternative oat |
| 927 | // location. |
| 928 | TEST_F(OatFileAssistantTest, LoadDexNoAlternateOat) { |
| 929 | std::string dex_location = GetScratchDir() + "/LoadDexNoAlternateOat.jar"; |
| 930 | std::string oat_location = GetScratchDir() + "/LoadDexNoAlternateOat.oat"; |
| 931 | |
| 932 | Copy(GetDexSrc1(), dex_location); |
| 933 | |
| 934 | OatFileAssistant oat_file_assistant( |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 935 | dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 936 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 937 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 938 | ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 939 | oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 940 | |
| 941 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 942 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 943 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 944 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 945 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 946 | EXPECT_EQ(1u, dex_files.size()); |
| 947 | |
| 948 | EXPECT_TRUE(OS::FileExists(oat_location.c_str())); |
| 949 | |
| 950 | // Verify it didn't create an oat in the default location. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 951 | OatFileAssistant ofm(dex_location.c_str(), kRuntimeISA, false, false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 952 | EXPECT_FALSE(ofm.OatFileExists()); |
| 953 | } |
| 954 | |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 955 | // Case: We have a DEX file but can't write the oat file. |
| 956 | // Expect: We should fail to make the oat file up to date. |
| 957 | TEST_F(OatFileAssistantTest, LoadDexUnwriteableAlternateOat) { |
| 958 | std::string dex_location = GetScratchDir() + "/LoadDexUnwriteableAlternateOat.jar"; |
| 959 | |
| 960 | // Make the oat location unwritable by inserting some non-existent |
| 961 | // intermediate directories. |
| 962 | std::string oat_location = GetScratchDir() + "/foo/bar/LoadDexUnwriteableAlternateOat.oat"; |
| 963 | |
| 964 | Copy(GetDexSrc1(), dex_location); |
| 965 | |
| 966 | OatFileAssistant oat_file_assistant( |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 967 | dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 968 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 969 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 970 | ASSERT_EQ(OatFileAssistant::kUpdateNotAttempted, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 971 | oat_file_assistant.MakeUpToDate(&error_msg)); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 972 | |
| 973 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 974 | ASSERT_TRUE(oat_file.get() == nullptr); |
| 975 | } |
| 976 | |
| 977 | // Case: We don't have a DEX file and can't write the oat file. |
| 978 | // Expect: We should fail to generate the oat file without crashing. |
| 979 | TEST_F(OatFileAssistantTest, GenNoDex) { |
| 980 | std::string dex_location = GetScratchDir() + "/GenNoDex.jar"; |
| 981 | std::string oat_location = GetScratchDir() + "/GenNoDex.oat"; |
| 982 | |
| 983 | OatFileAssistant oat_file_assistant( |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 984 | dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 985 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 986 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 987 | EXPECT_EQ(OatFileAssistant::kUpdateNotAttempted, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 988 | oat_file_assistant.GenerateOatFile(&error_msg)); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 991 | // Turn an absolute path into a path relative to the current working |
| 992 | // directory. |
| 993 | static std::string MakePathRelative(std::string target) { |
| 994 | char buf[MAXPATHLEN]; |
| 995 | std::string cwd = getcwd(buf, MAXPATHLEN); |
| 996 | |
| 997 | // Split the target and cwd paths into components. |
| 998 | std::vector<std::string> target_path; |
| 999 | std::vector<std::string> cwd_path; |
| 1000 | Split(target, '/', &target_path); |
| 1001 | Split(cwd, '/', &cwd_path); |
| 1002 | |
| 1003 | // Reverse the path components, so we can use pop_back(). |
| 1004 | std::reverse(target_path.begin(), target_path.end()); |
| 1005 | std::reverse(cwd_path.begin(), cwd_path.end()); |
| 1006 | |
| 1007 | // Drop the common prefix of the paths. Because we reversed the path |
| 1008 | // components, this becomes the common suffix of target_path and cwd_path. |
| 1009 | while (!target_path.empty() && !cwd_path.empty() |
| 1010 | && target_path.back() == cwd_path.back()) { |
| 1011 | target_path.pop_back(); |
| 1012 | cwd_path.pop_back(); |
| 1013 | } |
| 1014 | |
| 1015 | // For each element of the remaining cwd_path, add '..' to the beginning |
| 1016 | // of the target path. Because we reversed the path components, we add to |
| 1017 | // the end of target_path. |
| 1018 | for (unsigned int i = 0; i < cwd_path.size(); i++) { |
| 1019 | target_path.push_back(".."); |
| 1020 | } |
| 1021 | |
| 1022 | // Reverse again to get the right path order, and join to get the result. |
| 1023 | std::reverse(target_path.begin(), target_path.end()); |
| 1024 | return Join(target_path, '/'); |
| 1025 | } |
| 1026 | |
| 1027 | // Case: Non-absolute path to Dex location. |
| 1028 | // Expect: Not sure, but it shouldn't crash. |
| 1029 | TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) { |
| 1030 | std::string abs_dex_location = GetScratchDir() + "/NonAbsoluteDexLocation.jar"; |
| 1031 | Copy(GetDexSrc1(), abs_dex_location); |
| 1032 | |
| 1033 | std::string dex_location = MakePathRelative(abs_dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1034 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1035 | |
| 1036 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1037 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 1038 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1039 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 1040 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 1041 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 1042 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 1043 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 1044 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
| 1045 | } |
| 1046 | |
| 1047 | // Case: Very short, non-existent Dex location. |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 1048 | // Expect: kNoDexOptNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1049 | TEST_F(OatFileAssistantTest, ShortDexLocation) { |
| 1050 | std::string dex_location = "/xx"; |
| 1051 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1052 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1053 | |
| 1054 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1055 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 1056 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1057 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 1058 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 1059 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 1060 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 1061 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 1062 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 1063 | EXPECT_FALSE(oat_file_assistant.HasOriginalDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1064 | |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 1065 | // Trying to make it up to date should have no effect. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1066 | std::string error_msg; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 1067 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 1068 | EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 1069 | oat_file_assistant.MakeUpToDate(&error_msg)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 1070 | EXPECT_TRUE(error_msg.empty()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | // Case: Non-standard extension for dex file. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 1074 | // Expect: The status is kDex2OatNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1075 | TEST_F(OatFileAssistantTest, LongDexExtension) { |
| 1076 | std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx"; |
| 1077 | Copy(GetDexSrc1(), dex_location); |
| 1078 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1079 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1080 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1081 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 1082 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1083 | |
| 1084 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 1085 | EXPECT_FALSE(oat_file_assistant.OdexFileExists()); |
| 1086 | EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); |
| 1087 | EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); |
| 1088 | EXPECT_FALSE(oat_file_assistant.OatFileExists()); |
| 1089 | EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); |
| 1090 | EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); |
| 1091 | } |
| 1092 | |
| 1093 | // A task to generate a dex location. Used by the RaceToGenerate test. |
| 1094 | class RaceGenerateTask : public Task { |
| 1095 | public: |
| 1096 | explicit RaceGenerateTask(const std::string& dex_location, const std::string& oat_location) |
Jeff Hao | f0192c8 | 2016-03-28 20:39:50 -0700 | [diff] [blame] | 1097 | : dex_location_(dex_location), oat_location_(oat_location), loaded_oat_file_(nullptr) |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1098 | {} |
| 1099 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1100 | void Run(Thread* self ATTRIBUTE_UNUSED) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1101 | // Load the dex files, and save a pointer to the loaded oat file, so that |
| 1102 | // we can verify only one oat file was loaded for the dex location. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1103 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1104 | std::vector<std::string> error_msgs; |
Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 1105 | const OatFile* oat_file = nullptr; |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1106 | dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat( |
| 1107 | dex_location_.c_str(), |
| 1108 | oat_location_.c_str(), |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 1109 | /*class_loader*/nullptr, |
| 1110 | /*dex_elements*/nullptr, |
Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 1111 | &oat_file, |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1112 | &error_msgs); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1113 | CHECK(!dex_files.empty()) << Join(error_msgs, '\n'); |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 1114 | CHECK(dex_files[0]->GetOatDexFile() != nullptr) << dex_files[0]->GetLocation(); |
| 1115 | loaded_oat_file_ = dex_files[0]->GetOatDexFile()->GetOatFile(); |
Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 1116 | CHECK_EQ(loaded_oat_file_, oat_file); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | const OatFile* GetLoadedOatFile() const { |
| 1120 | return loaded_oat_file_; |
| 1121 | } |
| 1122 | |
| 1123 | private: |
| 1124 | std::string dex_location_; |
| 1125 | std::string oat_location_; |
| 1126 | const OatFile* loaded_oat_file_; |
| 1127 | }; |
| 1128 | |
| 1129 | // Test the case where multiple processes race to generate an oat file. |
| 1130 | // This simulates multiple processes using multiple threads. |
| 1131 | // |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1132 | // We want unique Oat files to be loaded even when there is a race to load. |
| 1133 | // TODO: The test case no longer tests locking the way it was intended since we now get multiple |
| 1134 | // copies of the same Oat files mapped at different locations. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1135 | TEST_F(OatFileAssistantTest, RaceToGenerate) { |
| 1136 | std::string dex_location = GetScratchDir() + "/RaceToGenerate.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1137 | std::string oat_location = GetOdexDir() + "/RaceToGenerate.oat"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1138 | |
| 1139 | // We use the lib core dex file, because it's large, and hopefully should |
| 1140 | // take a while to generate. |
Narayan Kamath | d1ef436 | 2015-11-12 11:49:06 +0000 | [diff] [blame] | 1141 | Copy(GetLibCoreDexFileNames()[0], dex_location); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1142 | |
| 1143 | const int kNumThreads = 32; |
| 1144 | Thread* self = Thread::Current(); |
| 1145 | ThreadPool thread_pool("Oat file assistant test thread pool", kNumThreads); |
| 1146 | std::vector<std::unique_ptr<RaceGenerateTask>> tasks; |
| 1147 | for (int i = 0; i < kNumThreads; i++) { |
| 1148 | std::unique_ptr<RaceGenerateTask> task(new RaceGenerateTask(dex_location, oat_location)); |
| 1149 | thread_pool.AddTask(self, task.get()); |
| 1150 | tasks.push_back(std::move(task)); |
| 1151 | } |
| 1152 | thread_pool.StartWorkers(self); |
| 1153 | thread_pool.Wait(self, true, false); |
| 1154 | |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1155 | // Verify every task got a unique oat file. |
| 1156 | std::set<const OatFile*> oat_files; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1157 | for (auto& task : tasks) { |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1158 | const OatFile* oat_file = task->GetLoadedOatFile(); |
| 1159 | EXPECT_TRUE(oat_files.find(oat_file) == oat_files.end()); |
| 1160 | oat_files.insert(oat_file); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | // Case: We have a DEX file and an ODEX file, no OAT file, and dex2oat is |
| 1165 | // disabled. |
| 1166 | // Expect: We should load the odex file non-executable. |
| 1167 | TEST_F(OatFileAssistantNoDex2OatTest, LoadDexOdexNoOat) { |
| 1168 | std::string dex_location = GetScratchDir() + "/LoadDexOdexNoOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1169 | std::string odex_location = GetOdexDir() + "/LoadDexOdexNoOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1170 | |
| 1171 | // Create the dex and odex files |
| 1172 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1173 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1174 | |
| 1175 | // Load the oat using an executable oat file assistant. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1176 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1177 | |
| 1178 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 1179 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 1180 | EXPECT_FALSE(oat_file->IsExecutable()); |
| 1181 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1182 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 1183 | EXPECT_EQ(1u, dex_files.size()); |
| 1184 | } |
| 1185 | |
| 1186 | // Case: We have a MultiDEX file and an ODEX file, no OAT file, and dex2oat is |
| 1187 | // disabled. |
| 1188 | // Expect: We should load the odex file non-executable. |
| 1189 | TEST_F(OatFileAssistantNoDex2OatTest, LoadMultiDexOdexNoOat) { |
| 1190 | std::string dex_location = GetScratchDir() + "/LoadMultiDexOdexNoOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1191 | std::string odex_location = GetOdexDir() + "/LoadMultiDexOdexNoOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1192 | |
| 1193 | // Create the dex and odex files |
| 1194 | Copy(GetMultiDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1195 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1196 | |
| 1197 | // Load the oat using an executable oat file assistant. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1198 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1199 | |
| 1200 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 1201 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 1202 | EXPECT_FALSE(oat_file->IsExecutable()); |
| 1203 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1204 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 1205 | EXPECT_EQ(2u, dex_files.size()); |
| 1206 | } |
| 1207 | |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 1208 | TEST_F(OatFileAssistantTest, RuntimeCompilerFilterOptionUsed) { |
| 1209 | std::string dex_location = GetScratchDir() + "/RuntimeCompilerFilterOptionUsed.jar"; |
| 1210 | Copy(GetDexSrc1(), dex_location); |
| 1211 | |
| 1212 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); |
| 1213 | |
| 1214 | std::string error_msg; |
| 1215 | Runtime::Current()->AddCompilerOption("--compiler-filter=interpret-only"); |
| 1216 | EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, |
| 1217 | oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; |
| 1218 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 1219 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); |
| 1220 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, |
| 1221 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
| 1222 | |
| 1223 | Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); |
| 1224 | EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, |
| 1225 | oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; |
| 1226 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 1227 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); |
| 1228 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 1229 | oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); |
| 1230 | |
| 1231 | Runtime::Current()->AddCompilerOption("--compiler-filter=bogus"); |
| 1232 | EXPECT_EQ(OatFileAssistant::kUpdateNotAttempted, |
| 1233 | oat_file_assistant.MakeUpToDate(&error_msg)); |
| 1234 | } |
| 1235 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1236 | TEST(OatFileAssistantUtilsTest, DexFilenameToOdexFilename) { |
| 1237 | std::string error_msg; |
| 1238 | std::string odex_file; |
| 1239 | |
| 1240 | EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename( |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 1241 | "/foo/bar/baz.jar", kArm, &odex_file, &error_msg)) << error_msg; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1242 | EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1243 | |
| 1244 | EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename( |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 1245 | "/foo/bar/baz.funnyext", kArm, &odex_file, &error_msg)) << error_msg; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1246 | EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1247 | |
| 1248 | EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename( |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 1249 | "nopath.jar", kArm, &odex_file, &error_msg)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1250 | EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename( |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 1251 | "/foo/bar/baz_noext", kArm, &odex_file, &error_msg)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1252 | } |
| 1253 | |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1254 | // Verify the dexopt status values from dalvik.system.DexFile |
| 1255 | // match the OatFileAssistant::DexOptStatus values. |
| 1256 | TEST_F(OatFileAssistantTest, DexOptStatusValues) { |
| 1257 | ScopedObjectAccess soa(Thread::Current()); |
| 1258 | StackHandleScope<1> hs(soa.Self()); |
| 1259 | ClassLinker* linker = Runtime::Current()->GetClassLinker(); |
| 1260 | Handle<mirror::Class> dexfile( |
| 1261 | hs.NewHandle(linker->FindSystemClass(soa.Self(), "Ldalvik/system/DexFile;"))); |
| 1262 | ASSERT_FALSE(dexfile.Get() == nullptr); |
| 1263 | linker->EnsureInitialized(soa.Self(), dexfile, true, true); |
| 1264 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1265 | ArtField* no_dexopt_needed = mirror::Class::FindStaticField( |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1266 | soa.Self(), dexfile, "NO_DEXOPT_NEEDED", "I"); |
| 1267 | ASSERT_FALSE(no_dexopt_needed == nullptr); |
| 1268 | EXPECT_EQ(no_dexopt_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt); |
| 1269 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, no_dexopt_needed->GetInt(dexfile.Get())); |
| 1270 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1271 | ArtField* dex2oat_needed = mirror::Class::FindStaticField( |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1272 | soa.Self(), dexfile, "DEX2OAT_NEEDED", "I"); |
| 1273 | ASSERT_FALSE(dex2oat_needed == nullptr); |
| 1274 | EXPECT_EQ(dex2oat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt); |
| 1275 | EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, dex2oat_needed->GetInt(dexfile.Get())); |
| 1276 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1277 | ArtField* patchoat_needed = mirror::Class::FindStaticField( |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1278 | soa.Self(), dexfile, "PATCHOAT_NEEDED", "I"); |
| 1279 | ASSERT_FALSE(patchoat_needed == nullptr); |
| 1280 | EXPECT_EQ(patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt); |
| 1281 | EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, patchoat_needed->GetInt(dexfile.Get())); |
| 1282 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1283 | ArtField* self_patchoat_needed = mirror::Class::FindStaticField( |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1284 | soa.Self(), dexfile, "SELF_PATCHOAT_NEEDED", "I"); |
| 1285 | ASSERT_FALSE(self_patchoat_needed == nullptr); |
| 1286 | EXPECT_EQ(self_patchoat_needed->GetTypeAsPrimitiveType(), Primitive::kPrimInt); |
| 1287 | EXPECT_EQ(OatFileAssistant::kSelfPatchOatNeeded, self_patchoat_needed->GetInt(dexfile.Get())); |
| 1288 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1289 | |
| 1290 | // TODO: More Tests: |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1291 | // * Image checksum change is out of date for kIntepretOnly, but not |
| 1292 | // kVerifyAtRuntime. But target of kVerifyAtRuntime still says current |
| 1293 | // kInterpretOnly is out of date. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1294 | // * Test class linker falls back to unquickened dex for DexNoOat |
| 1295 | // * Test class linker falls back to unquickened dex for MultiDexNoOat |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1296 | // * Test using secondary isa |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1297 | // * Test for status of oat while oat is being generated (how?) |
| 1298 | // * Test case where 32 and 64 bit boot class paths differ, |
| 1299 | // and we ask IsInBootClassPath for a class in exactly one of the 32 or |
| 1300 | // 64 bit boot class paths. |
| 1301 | // * Test unexpected scenarios (?): |
| 1302 | // - Dex is stripped, don't have odex. |
| 1303 | // - Oat file corrupted after status check, before reload unexecutable |
| 1304 | // because it's unrelocated and no dex2oat |
Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 1305 | // * Test unrelocated specific target compilation type can be relocated to |
| 1306 | // make it up to date. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1307 | |
| 1308 | } // namespace art |