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 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 17 | #include "oat_file_assistant.h" |
| 18 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 19 | #include <sys/param.h> |
| 20 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 23 | #include <fcntl.h> |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 24 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 25 | #include <gtest/gtest.h> |
| 26 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 27 | #include "android-base/strings.h" |
| 28 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 29 | #include "art_field-inl.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 30 | #include "base/os.h" |
| 31 | #include "base/utils.h" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 32 | #include "class_linker-inl.h" |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 33 | #include "class_loader_context.h" |
Jeff Hao | 0cb1728 | 2017-07-12 14:51:49 -0700 | [diff] [blame] | 34 | #include "common_runtime_test.h" |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 35 | #include "dexopt_test.h" |
David Brazdil | 32bde99 | 2018-05-14 15:24:34 +0100 | [diff] [blame] | 36 | #include "hidden_api.h" |
Vladimir Marko | d3d00c0 | 2019-11-07 15:09:07 +0000 | [diff] [blame] | 37 | #include "oat.h" |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 38 | #include "oat_file.h" |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 39 | #include "oat_file_manager.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 40 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 41 | #include "thread-current-inl.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 42 | |
| 43 | namespace art { |
| 44 | |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 45 | class OatFileAssistantTest : public DexoptTest { |
| 46 | public: |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 47 | void VerifyOptimizationStatus(OatFileAssistant* assistant, |
| 48 | const std::string& file, |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 49 | const std::string& expected_filter, |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 50 | const std::string& expected_reason, |
| 51 | const std::string& expected_odex_status) { |
| 52 | // Verify the static methods (called from PM for dexOptNeeded). |
| 53 | std::string compilation_filter1; |
| 54 | std::string compilation_reason1; |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 55 | |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 56 | OatFileAssistant::GetOptimizationStatus( |
| 57 | file, kRuntimeISA, &compilation_filter1, &compilation_reason1); |
| 58 | |
| 59 | ASSERT_EQ(expected_filter, compilation_filter1); |
| 60 | ASSERT_EQ(expected_reason, compilation_reason1); |
| 61 | |
| 62 | // Verify the instance methods (called at runtime for systrace). |
| 63 | std::string odex_location2; // ignored |
| 64 | std::string compilation_filter2; |
| 65 | std::string compilation_reason2; |
| 66 | std::string odex_status2; |
| 67 | |
| 68 | assistant->GetOptimizationStatus( |
| 69 | &odex_location2, |
| 70 | &compilation_filter2, |
| 71 | &compilation_reason2, |
| 72 | &odex_status2); |
| 73 | |
| 74 | ASSERT_EQ(expected_filter, compilation_filter2); |
| 75 | ASSERT_EQ(expected_reason, compilation_reason2); |
| 76 | ASSERT_EQ(expected_odex_status, odex_status2); |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 79 | void VerifyOptimizationStatus(OatFileAssistant* assistant, |
| 80 | const std::string& file, |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 81 | CompilerFilter::Filter expected_filter, |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 82 | const std::string& expected_reason, |
| 83 | const std::string& expected_odex_status) { |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 84 | VerifyOptimizationStatus( |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 85 | assistant, |
| 86 | file, |
| 87 | CompilerFilter::NameOfFilter(expected_filter), |
| 88 | expected_reason, |
| 89 | expected_odex_status); |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 90 | } |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 91 | |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 92 | void InsertNewBootClasspathEntry() { |
| 93 | std::string extra_dex_filename = GetMultiDexSrc1(); |
| 94 | Runtime* runtime = Runtime::Current(); |
| 95 | runtime->boot_class_path_.push_back(extra_dex_filename); |
| 96 | if (!runtime->boot_class_path_locations_.empty()) { |
| 97 | runtime->boot_class_path_locations_.push_back(extra_dex_filename); |
| 98 | } |
| 99 | } |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 100 | |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 101 | int GetDexOptNeeded( |
| 102 | OatFileAssistant* assistant, |
| 103 | CompilerFilter::Filter compiler_filter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 104 | bool profile_changed = false, |
| 105 | bool downgrade = false) { |
| 106 | return assistant->GetDexOptNeeded( |
| 107 | compiler_filter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 108 | profile_changed, |
| 109 | downgrade); |
| 110 | } |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 111 | |
| 112 | static std::unique_ptr<ClassLoaderContext> InitializeDefaultContext() { |
| 113 | auto context = ClassLoaderContext::Default(); |
| 114 | context->OpenDexFiles(); |
| 115 | return context; |
| 116 | } |
| 117 | |
| 118 | std::unique_ptr<ClassLoaderContext> default_context_ = InitializeDefaultContext(); |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 119 | }; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 120 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 121 | class ScopedNonWritable { |
| 122 | public: |
| 123 | explicit ScopedNonWritable(const std::string& dex_location) { |
| 124 | is_valid_ = false; |
| 125 | size_t pos = dex_location.rfind('/'); |
| 126 | if (pos != std::string::npos) { |
| 127 | is_valid_ = true; |
| 128 | dex_parent_ = dex_location.substr(0, pos); |
| 129 | if (chmod(dex_parent_.c_str(), 0555) != 0) { |
| 130 | PLOG(ERROR) << "Could not change permissions on " << dex_parent_; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | bool IsSuccessful() { return is_valid_ && (access(dex_parent_.c_str(), W_OK) != 0); } |
| 136 | |
| 137 | ~ScopedNonWritable() { |
| 138 | if (is_valid_) { |
| 139 | if (chmod(dex_parent_.c_str(), 0777) != 0) { |
| 140 | PLOG(ERROR) << "Could not restore permissions on " << dex_parent_; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | private: |
| 146 | std::string dex_parent_; |
| 147 | bool is_valid_; |
| 148 | }; |
| 149 | |
| 150 | static bool IsExecutedAsRoot() { |
| 151 | return geteuid() == 0; |
| 152 | } |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 153 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 154 | // Case: We have a MultiDEX file and up-to-date ODEX file for it with relative |
| 155 | // encoded dex locations. |
| 156 | // Expect: The oat file status is kNoDexOptNeeded. |
| 157 | TEST_F(OatFileAssistantTest, RelativeEncodedDexLocation) { |
| 158 | std::string dex_location = GetScratchDir() + "/RelativeEncodedDexLocation.jar"; |
| 159 | std::string odex_location = GetOdexDir() + "/RelativeEncodedDexLocation.odex"; |
| 160 | |
| 161 | // Create the dex file |
| 162 | Copy(GetMultiDexSrc1(), dex_location); |
| 163 | |
| 164 | // Create the oat file with relative encoded dex location. |
| 165 | std::vector<std::string> args = { |
| 166 | "--dex-file=" + dex_location, |
| 167 | "--dex-location=" + std::string("RelativeEncodedDexLocation.jar"), |
| 168 | "--oat-file=" + odex_location, |
| 169 | "--compiler-filter=speed" |
| 170 | }; |
| 171 | |
| 172 | std::string error_msg; |
| 173 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 174 | |
| 175 | // Verify we can load both dex files. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 176 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 177 | kRuntimeISA, |
| 178 | default_context_.get(), |
| 179 | true); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 180 | |
| 181 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 182 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 183 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 184 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 185 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 186 | EXPECT_EQ(2u, dex_files.size()); |
| 187 | } |
| 188 | |
| 189 | TEST_F(OatFileAssistantTest, MakeUpToDateWithContext) { |
| 190 | std::string dex_location = GetScratchDir() + "/TestDex.jar"; |
| 191 | std::string odex_location = GetOdexDir() + "/TestDex.odex"; |
| 192 | std::string context_location = GetScratchDir() + "/ContextDex.jar"; |
| 193 | Copy(GetDexSrc1(), dex_location); |
| 194 | Copy(GetDexSrc2(), context_location); |
| 195 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 196 | std::string context_str = "PCL[" + context_location + "]"; |
| 197 | std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_str); |
| 198 | ASSERT_TRUE(context != nullptr); |
Calin Juravle | 5ff2393 | 2020-12-11 18:26:14 -0800 | [diff] [blame] | 199 | ASSERT_TRUE(context->OpenDexFiles()); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 200 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 201 | OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, context.get(), false); |
| 202 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 203 | std::string error_msg; |
| 204 | std::vector<std::string> args; |
| 205 | args.push_back("--dex-file=" + dex_location); |
| 206 | args.push_back("--oat-file=" + odex_location); |
| 207 | args.push_back("--class-loader-context=" + context_str); |
| 208 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 209 | |
| 210 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 211 | ASSERT_NE(nullptr, oat_file.get()); |
| 212 | ASSERT_NE(nullptr, oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kClassPathKey)); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 213 | EXPECT_EQ(context->EncodeContextForOatFile(""), |
| 214 | oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kClassPathKey)); |
| 215 | } |
| 216 | |
| 217 | TEST_F(OatFileAssistantTest, GetDexOptNeededWithUpToDateContextRelative) { |
| 218 | std::string dex_location = GetScratchDir() + "/TestDex.jar"; |
| 219 | std::string odex_location = GetOdexDir() + "/TestDex.odex"; |
| 220 | std::string context_location = GetScratchDir() + "/ContextDex.jar"; |
| 221 | Copy(GetDexSrc1(), dex_location); |
| 222 | Copy(GetDexSrc2(), context_location); |
| 223 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 224 | // A relative context simulates a dependent split context. |
| 225 | std::unique_ptr<ClassLoaderContext> relative_context = |
| 226 | ClassLoaderContext::Create("PCL[ContextDex.jar]"); |
| 227 | ASSERT_TRUE(relative_context != nullptr); |
| 228 | std::vector<int> context_fds; |
| 229 | ASSERT_TRUE(relative_context->OpenDexFiles(GetScratchDir(), context_fds)); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 230 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 231 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 232 | kRuntimeISA, |
| 233 | relative_context.get(), |
| 234 | false); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 235 | |
| 236 | std::string error_msg; |
| 237 | std::vector<std::string> args; |
| 238 | args.push_back("--dex-file=" + dex_location); |
| 239 | args.push_back("--oat-file=" + odex_location); |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 240 | args.push_back("--class-loader-context=PCL[" + context_location + "]"); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 241 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 242 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 243 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 244 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kDefaultCompilerFilter)); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 247 | // Case: We have a DEX file, but no OAT file for it. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 248 | // Expect: The status is kDex2OatNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 249 | TEST_F(OatFileAssistantTest, DexNoOat) { |
| 250 | std::string dex_location = GetScratchDir() + "/DexNoOat.jar"; |
| 251 | Copy(GetDexSrc1(), dex_location); |
| 252 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 253 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 254 | kRuntimeISA, |
| 255 | default_context_.get(), |
| 256 | false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 257 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 258 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 259 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 260 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 261 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 262 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 263 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeedProfile)); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 264 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 265 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 266 | |
| 267 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 268 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 269 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 270 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 271 | |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 272 | VerifyOptimizationStatus( |
| 273 | &oat_file_assistant, |
| 274 | dex_location, |
| 275 | "run-from-apk", |
| 276 | "unknown", |
| 277 | "io-error-no-oat"); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | // Case: We have no DEX file and no OAT file. |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 281 | // Expect: Status is kNoDexOptNeeded. Loading should fail, but not crash. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 282 | TEST_F(OatFileAssistantTest, NoDexNoOat) { |
| 283 | std::string dex_location = GetScratchDir() + "/NoDexNoOat.jar"; |
| 284 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 285 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 286 | kRuntimeISA, |
| 287 | default_context_.get(), |
| 288 | true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 289 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 290 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 291 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 292 | EXPECT_FALSE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 293 | |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 294 | // Trying to get the best oat file should fail, but not crash. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 295 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 296 | EXPECT_EQ(nullptr, oat_file.get()); |
| 297 | } |
| 298 | |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 299 | // Case: We have a DEX file and an ODEX file, but no OAT file. |
| 300 | // Expect: The status is kNoDexOptNeeded. |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 301 | TEST_F(OatFileAssistantTest, OdexUpToDate) { |
| 302 | std::string dex_location = GetScratchDir() + "/OdexUpToDate.jar"; |
| 303 | std::string odex_location = GetOdexDir() + "/OdexUpToDate.odex"; |
| 304 | Copy(GetDexSrc1(), dex_location); |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 305 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed, "install"); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 306 | |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 307 | // Force the use of oat location by making the dex parent not writable. |
| 308 | OatFileAssistant oat_file_assistant( |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 309 | dex_location.c_str(), |
| 310 | kRuntimeISA, |
| 311 | default_context_.get(), |
| 312 | /*load_executable=*/ false); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 313 | |
| 314 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 315 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 316 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 317 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 318 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 319 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 320 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 321 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything)); |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 322 | |
| 323 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 324 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
| 325 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 326 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 327 | |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 328 | VerifyOptimizationStatus( |
| 329 | &oat_file_assistant, |
| 330 | dex_location, |
| 331 | CompilerFilter::kSpeed, |
| 332 | "install", |
| 333 | "up-to-date"); |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | // Case: We have an ODEX file compiled against partial boot image. |
| 337 | // Expect: The status is kNoDexOptNeeded. |
| 338 | TEST_F(OatFileAssistantTest, OdexUpToDatePartialBootImage) { |
| 339 | std::string dex_location = GetScratchDir() + "/OdexUpToDate.jar"; |
| 340 | std::string odex_location = GetOdexDir() + "/OdexUpToDate.odex"; |
| 341 | Copy(GetDexSrc1(), dex_location); |
| 342 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed, "install"); |
| 343 | |
| 344 | // Insert an extra dex file to the boot class path. |
| 345 | InsertNewBootClasspathEntry(); |
| 346 | |
| 347 | // Force the use of oat location by making the dex parent not writable. |
| 348 | OatFileAssistant oat_file_assistant( |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 349 | dex_location.c_str(), |
| 350 | kRuntimeISA, |
| 351 | default_context_.get(), |
| 352 | /*load_executable=*/ false); |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 353 | |
| 354 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 355 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 356 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 357 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 358 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 359 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 360 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 361 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 362 | |
| 363 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 364 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
| 365 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 366 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 367 | |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 368 | VerifyOptimizationStatus( |
| 369 | &oat_file_assistant, |
| 370 | dex_location, |
| 371 | CompilerFilter::kSpeed, |
| 372 | "install", |
| 373 | "up-to-date"); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | // Case: We have a DEX file and a PIC ODEX file, but no OAT file. We load the dex |
| 377 | // file via a symlink. |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 378 | // Expect: The status is kNoDexOptNeeded. |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 379 | TEST_F(OatFileAssistantTest, OdexUpToDateSymLink) { |
| 380 | std::string scratch_dir = GetScratchDir(); |
| 381 | std::string dex_location = GetScratchDir() + "/OdexUpToDate.jar"; |
| 382 | std::string odex_location = GetOdexDir() + "/OdexUpToDate.odex"; |
| 383 | |
| 384 | Copy(GetDexSrc1(), dex_location); |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 385 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 386 | |
| 387 | // Now replace the dex location with a symlink. |
| 388 | std::string link = scratch_dir + "/link"; |
| 389 | ASSERT_EQ(0, symlink(scratch_dir.c_str(), link.c_str())); |
| 390 | dex_location = link + "/OdexUpToDate.jar"; |
| 391 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 392 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 393 | kRuntimeISA, |
| 394 | default_context_.get(), |
| 395 | false); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 396 | |
| 397 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 398 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 399 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 400 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 401 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 402 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 403 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 404 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 405 | |
| 406 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 407 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
| 408 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 409 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 412 | // 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] | 413 | // Expect: The status is kNoDexOptNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 414 | TEST_F(OatFileAssistantTest, OatUpToDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 415 | if (IsExecutedAsRoot()) { |
| 416 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 417 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 418 | return; |
| 419 | } |
| 420 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 421 | std::string dex_location = GetScratchDir() + "/OatUpToDate.jar"; |
| 422 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 423 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 424 | |
Vladimir Marko | f3d88a8 | 2018-12-21 16:38:47 +0000 | [diff] [blame] | 425 | // Force the use of oat location by making the dex parent not writable. |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 426 | ScopedNonWritable scoped_non_writable(dex_location); |
| 427 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 428 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 429 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 430 | kRuntimeISA, |
| 431 | default_context_.get(), |
| 432 | false); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 433 | |
| 434 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 435 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 436 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 437 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 438 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 439 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 440 | EXPECT_EQ(OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 441 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything)); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 442 | |
| 443 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 444 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 445 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 446 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 447 | |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 448 | VerifyOptimizationStatus( |
| 449 | &oat_file_assistant, |
| 450 | dex_location, |
| 451 | CompilerFilter::kSpeed, |
| 452 | "unknown", |
| 453 | "up-to-date"); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 456 | // Case: Passing valid file descriptors of updated odex/vdex files along with the dex file. |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 457 | // Expect: The status is kNoDexOptNeeded. |
| 458 | TEST_F(OatFileAssistantTest, GetDexOptNeededWithFd) { |
| 459 | std::string dex_location = GetScratchDir() + "/OatUpToDate.jar"; |
| 460 | std::string odex_location = GetScratchDir() + "/OatUpToDate.odex"; |
| 461 | std::string vdex_location = GetScratchDir() + "/OatUpToDate.vdex"; |
| 462 | |
| 463 | Copy(GetDexSrc1(), dex_location); |
| 464 | GenerateOatForTest(dex_location.c_str(), |
| 465 | odex_location.c_str(), |
| 466 | CompilerFilter::kSpeed, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 467 | /* with_alternate_image= */ false); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 468 | |
Andreas Gampe | dfcd82c | 2018-10-16 20:22:37 -0700 | [diff] [blame] | 469 | android::base::unique_fd odex_fd(open(odex_location.c_str(), O_RDONLY | O_CLOEXEC)); |
| 470 | android::base::unique_fd vdex_fd(open(vdex_location.c_str(), O_RDONLY | O_CLOEXEC)); |
| 471 | android::base::unique_fd zip_fd(open(dex_location.c_str(), O_RDONLY | O_CLOEXEC)); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 472 | |
| 473 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 474 | kRuntimeISA, |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 475 | default_context_.get(), |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 476 | false, |
Nicolas Geoffray | 2974260 | 2017-12-14 10:09:03 +0000 | [diff] [blame] | 477 | false, |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 478 | vdex_fd.get(), |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 479 | odex_fd.get(), |
| 480 | zip_fd.get()); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 481 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 482 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 483 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 484 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 485 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 486 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 487 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 488 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything)); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 489 | |
| 490 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 491 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
| 492 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 493 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 496 | // Case: Passing invalid odex fd and valid vdex and zip fds. |
| 497 | // Expect: The status should be kDex2OatForBootImage. |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 498 | TEST_F(OatFileAssistantTest, GetDexOptNeededWithInvalidOdexFd) { |
| 499 | std::string dex_location = GetScratchDir() + "/OatUpToDate.jar"; |
| 500 | std::string odex_location = GetScratchDir() + "/OatUpToDate.odex"; |
| 501 | std::string vdex_location = GetScratchDir() + "/OatUpToDate.vdex"; |
| 502 | |
| 503 | Copy(GetDexSrc1(), dex_location); |
| 504 | GenerateOatForTest(dex_location.c_str(), |
| 505 | odex_location.c_str(), |
| 506 | CompilerFilter::kSpeed, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 507 | /* with_alternate_image= */ false); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 508 | |
Andreas Gampe | dfcd82c | 2018-10-16 20:22:37 -0700 | [diff] [blame] | 509 | android::base::unique_fd vdex_fd(open(vdex_location.c_str(), O_RDONLY | O_CLOEXEC)); |
| 510 | android::base::unique_fd zip_fd(open(dex_location.c_str(), O_RDONLY | O_CLOEXEC)); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 511 | |
| 512 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 513 | kRuntimeISA, |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 514 | default_context_.get(), |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 515 | false, |
Nicolas Geoffray | 2974260 | 2017-12-14 10:09:03 +0000 | [diff] [blame] | 516 | false, |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 517 | vdex_fd.get(), |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 518 | /* oat_fd= */ -1, |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 519 | zip_fd.get()); |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 520 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
| 521 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
| 522 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 523 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 524 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 525 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything)); |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 526 | |
| 527 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 528 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 529 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 530 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 533 | // Case: Passing invalid vdex fd and valid odex and zip fds. |
| 534 | // Expect: The status should be kDex2OatFromScratch. |
| 535 | TEST_F(OatFileAssistantTest, GetDexOptNeededWithInvalidVdexFd) { |
| 536 | std::string dex_location = GetScratchDir() + "/OatUpToDate.jar"; |
| 537 | std::string odex_location = GetScratchDir() + "/OatUpToDate.odex"; |
| 538 | |
| 539 | Copy(GetDexSrc1(), dex_location); |
| 540 | GenerateOatForTest(dex_location.c_str(), |
| 541 | odex_location.c_str(), |
| 542 | CompilerFilter::kSpeed, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 543 | /* with_alternate_image= */ false); |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 544 | |
Andreas Gampe | dfcd82c | 2018-10-16 20:22:37 -0700 | [diff] [blame] | 545 | android::base::unique_fd odex_fd(open(odex_location.c_str(), O_RDONLY | O_CLOEXEC)); |
| 546 | android::base::unique_fd zip_fd(open(dex_location.c_str(), O_RDONLY | O_CLOEXEC)); |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 547 | |
| 548 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 549 | kRuntimeISA, |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 550 | default_context_.get(), |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 551 | false, |
Nicolas Geoffray | 2974260 | 2017-12-14 10:09:03 +0000 | [diff] [blame] | 552 | false, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 553 | /* vdex_fd= */ -1, |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 554 | odex_fd.get(), |
| 555 | zip_fd.get()); |
| 556 | |
| 557 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 558 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 559 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 560 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 561 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 562 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | // Case: Passing invalid vdex and odex fd with valid zip fd. |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 566 | // Expect: The status is kDex2oatFromScratch. |
| 567 | TEST_F(OatFileAssistantTest, GetDexOptNeededWithInvalidOdexVdexFd) { |
| 568 | std::string dex_location = GetScratchDir() + "/OatUpToDate.jar"; |
| 569 | |
| 570 | Copy(GetDexSrc1(), dex_location); |
| 571 | |
Andreas Gampe | dfcd82c | 2018-10-16 20:22:37 -0700 | [diff] [blame] | 572 | android::base::unique_fd zip_fd(open(dex_location.c_str(), O_RDONLY | O_CLOEXEC)); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 573 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 574 | kRuntimeISA, |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 575 | default_context_.get(), |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 576 | false, |
Nicolas Geoffray | 2974260 | 2017-12-14 10:09:03 +0000 | [diff] [blame] | 577 | false, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 578 | /* vdex_fd= */ -1, |
| 579 | /* oat_fd= */ -1, |
Shubham Ajmera | c12bf4c | 2017-10-24 16:59:42 -0700 | [diff] [blame] | 580 | zip_fd); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 581 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 582 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 583 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 584 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
| 585 | } |
| 586 | |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 587 | // Case: We have a DEX file and up-to-date VDEX file for it, but no |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 588 | // ODEX file. |
| 589 | TEST_F(OatFileAssistantTest, VdexUpToDateNoOdex) { |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 590 | std::string dex_location = GetScratchDir() + "/VdexUpToDateNoOdex.jar"; |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 591 | std::string odex_location = GetOdexDir() + "/VdexUpToDateNoOdex.oat"; |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 592 | |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 593 | Copy(GetDexSrc1(), dex_location); |
| 594 | |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 595 | // Generating and deleting the oat file should have the side effect of |
| 596 | // creating an up-to-date vdex file. |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 597 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
| 598 | ASSERT_EQ(0, unlink(odex_location.c_str())); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 599 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 600 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 601 | kRuntimeISA, |
| 602 | default_context_.get(), |
| 603 | false); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 604 | |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 605 | EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded, |
| 606 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
| 607 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 608 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 609 | |
| 610 | // Make sure we don't crash in this case when we dump the status. We don't |
| 611 | // care what the actual dumped value is. |
| 612 | oat_file_assistant.GetStatusDump(); |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 613 | |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 614 | VerifyOptimizationStatus( |
| 615 | &oat_file_assistant, |
| 616 | dex_location, |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 617 | "verify", |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 618 | "unknown", |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 619 | "up-to-date"); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | // Case: We have a DEX file and empty VDEX and ODEX files. |
| 623 | TEST_F(OatFileAssistantTest, EmptyVdexOdex) { |
| 624 | std::string dex_location = GetScratchDir() + "/EmptyVdexOdex.jar"; |
| 625 | std::string odex_location = GetOdexDir() + "/EmptyVdexOdex.oat"; |
| 626 | std::string vdex_location = GetOdexDir() + "/EmptyVdexOdex.vdex"; |
| 627 | |
| 628 | Copy(GetDexSrc1(), dex_location); |
Richard Uhler | 5cd5929 | 2017-02-01 12:54:23 +0000 | [diff] [blame] | 629 | ScratchFile vdex_file(vdex_location.c_str()); |
| 630 | ScratchFile odex_file(odex_location.c_str()); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 631 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 632 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 633 | kRuntimeISA, |
| 634 | default_context_.get(), |
| 635 | false); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 636 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 637 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | // Case: We have a DEX file and up-to-date (OAT) VDEX file for it, but no OAT |
| 641 | // file. |
| 642 | TEST_F(OatFileAssistantTest, VdexUpToDateNoOat) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 643 | if (IsExecutedAsRoot()) { |
| 644 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 645 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 646 | return; |
| 647 | } |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 648 | |
| 649 | std::string dex_location = GetScratchDir() + "/VdexUpToDateNoOat.jar"; |
| 650 | std::string oat_location; |
| 651 | std::string error_msg; |
| 652 | ASSERT_TRUE(OatFileAssistant::DexLocationToOatFilename( |
| 653 | dex_location, kRuntimeISA, &oat_location, &error_msg)) << error_msg; |
| 654 | |
| 655 | Copy(GetDexSrc1(), dex_location); |
| 656 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
| 657 | ASSERT_EQ(0, unlink(oat_location.c_str())); |
| 658 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 659 | ScopedNonWritable scoped_non_writable(dex_location); |
| 660 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 661 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 662 | kRuntimeISA, |
| 663 | default_context_.get(), |
| 664 | false); |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 665 | |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 666 | EXPECT_EQ(OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 667 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 670 | // Case: We have a DEX file and speed-profile OAT file for it. |
Richard Uhler | d1472a2 | 2016-04-15 15:18:56 -0700 | [diff] [blame] | 671 | // Expect: The status is kNoDexOptNeeded if the profile hasn't changed, but |
| 672 | // kDex2Oat if the profile has changed. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 673 | TEST_F(OatFileAssistantTest, ProfileOatUpToDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 674 | if (IsExecutedAsRoot()) { |
| 675 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 676 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 677 | return; |
| 678 | } |
| 679 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 680 | std::string dex_location = GetScratchDir() + "/ProfileOatUpToDate.jar"; |
| 681 | Copy(GetDexSrc1(), dex_location); |
| 682 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile); |
| 683 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 684 | ScopedNonWritable scoped_non_writable(dex_location); |
| 685 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 686 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 687 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 688 | kRuntimeISA, |
| 689 | default_context_.get(), |
| 690 | false); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 691 | |
| 692 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 693 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeedProfile, false)); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 694 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 695 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify, false)); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 696 | EXPECT_EQ(OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 697 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeedProfile, true)); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 698 | EXPECT_EQ(OatFileAssistant::kDex2OatForFilter, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 699 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify, true)); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 700 | |
| 701 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 702 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 703 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 704 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 707 | // 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] | 708 | // Expect: The status is kNoDexOptNeeded and we load all dex files. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 709 | TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 710 | if (IsExecutedAsRoot()) { |
| 711 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 712 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 713 | return; |
| 714 | } |
| 715 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 716 | std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar"; |
| 717 | Copy(GetMultiDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 718 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 719 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 720 | ScopedNonWritable scoped_non_writable(dex_location); |
| 721 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 722 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 723 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 724 | kRuntimeISA, |
| 725 | default_context_.get(), |
| 726 | true); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 727 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 728 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 729 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 730 | |
| 731 | // Verify we can load both dex files. |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 732 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 733 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 734 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 735 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 736 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 737 | EXPECT_EQ(2u, dex_files.size()); |
| 738 | } |
| 739 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 740 | // Case: We have a MultiDEX file where the non-main multdex entry is out of date. |
Richard Uhler | 67ff7d1 | 2015-05-14 13:21:13 -0700 | [diff] [blame] | 741 | // Expect: The status is kDex2OatNeeded. |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 742 | TEST_F(OatFileAssistantTest, MultiDexNonMainOutOfDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 743 | if (IsExecutedAsRoot()) { |
| 744 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 745 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 746 | return; |
| 747 | } |
| 748 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 749 | std::string dex_location = GetScratchDir() + "/MultiDexNonMainOutOfDate.jar"; |
Richard Uhler | 67ff7d1 | 2015-05-14 13:21:13 -0700 | [diff] [blame] | 750 | |
| 751 | // Compile code for GetMultiDexSrc1. |
| 752 | Copy(GetMultiDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 753 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 67ff7d1 | 2015-05-14 13:21:13 -0700 | [diff] [blame] | 754 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 755 | // Now overwrite the dex file with GetMultiDexSrc2 so the non-main checksum |
Richard Uhler | 67ff7d1 | 2015-05-14 13:21:13 -0700 | [diff] [blame] | 756 | // is out of date. |
| 757 | Copy(GetMultiDexSrc2(), dex_location); |
| 758 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 759 | ScopedNonWritable scoped_non_writable(dex_location); |
| 760 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 761 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 762 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 763 | kRuntimeISA, |
| 764 | default_context_.get(), |
| 765 | true); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 766 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 767 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 768 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 771 | // Case: We have a DEX file and an OAT file out of date with respect to the |
| 772 | // dex checksum. |
| 773 | TEST_F(OatFileAssistantTest, OatDexOutOfDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 774 | if (IsExecutedAsRoot()) { |
| 775 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 776 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 777 | return; |
| 778 | } |
| 779 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 780 | std::string dex_location = GetScratchDir() + "/OatDexOutOfDate.jar"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 781 | |
| 782 | // We create a dex, generate an oat for it, then overwrite the dex with a |
| 783 | // different dex to make the oat out of date. |
| 784 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 785 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 786 | Copy(GetDexSrc2(), dex_location); |
| 787 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 788 | ScopedNonWritable scoped_non_writable(dex_location); |
| 789 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 790 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 791 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 792 | kRuntimeISA, |
| 793 | default_context_.get(), |
| 794 | false); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 795 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 796 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 797 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 798 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 799 | |
| 800 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 801 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 802 | EXPECT_EQ(OatFileAssistant::kOatDexOutOfDate, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 803 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 804 | |
| 805 | VerifyOptimizationStatus( |
| 806 | &oat_file_assistant, |
| 807 | dex_location, |
| 808 | "run-from-apk-fallback", |
| 809 | "unknown", |
| 810 | "apk-more-recent"); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 813 | // Case: We have a DEX file and an (ODEX) VDEX file out of date with respect |
| 814 | // to the dex checksum, but no ODEX file. |
| 815 | TEST_F(OatFileAssistantTest, VdexDexOutOfDate) { |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 816 | std::string dex_location = GetScratchDir() + "/VdexDexOutOfDate.jar"; |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 817 | std::string odex_location = GetOdexDir() + "/VdexDexOutOfDate.oat"; |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 818 | |
| 819 | Copy(GetDexSrc1(), dex_location); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 820 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
| 821 | ASSERT_EQ(0, unlink(odex_location.c_str())); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 822 | Copy(GetDexSrc2(), dex_location); |
| 823 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 824 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 825 | kRuntimeISA, |
| 826 | default_context_.get(), |
| 827 | false); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 828 | |
| 829 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 830 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 833 | // Case: We have a MultiDEX (ODEX) VDEX file where the non-main multidex entry |
| 834 | // is out of date and there is no corresponding ODEX file. |
| 835 | TEST_F(OatFileAssistantTest, VdexMultiDexNonMainOutOfDate) { |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 836 | std::string dex_location = GetScratchDir() + "/VdexMultiDexNonMainOutOfDate.jar"; |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 837 | std::string odex_location = GetOdexDir() + "/VdexMultiDexNonMainOutOfDate.odex"; |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 838 | |
| 839 | Copy(GetMultiDexSrc1(), dex_location); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 840 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
| 841 | ASSERT_EQ(0, unlink(odex_location.c_str())); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 842 | Copy(GetMultiDexSrc2(), dex_location); |
| 843 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 844 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 845 | kRuntimeISA, |
| 846 | default_context_.get(), |
| 847 | false); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 848 | |
| 849 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 850 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 853 | // Case: We have a DEX file and an OAT file out of date with respect to the |
| 854 | // boot image. |
| 855 | TEST_F(OatFileAssistantTest, OatImageOutOfDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 856 | if (IsExecutedAsRoot()) { |
| 857 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 858 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 859 | return; |
| 860 | } |
| 861 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 862 | std::string dex_location = GetScratchDir() + "/OatImageOutOfDate.jar"; |
| 863 | |
| 864 | Copy(GetDexSrc1(), dex_location); |
| 865 | GenerateOatForTest(dex_location.c_str(), |
| 866 | CompilerFilter::kSpeed, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 867 | /* with_alternate_image= */ true); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 868 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 869 | ScopedNonWritable scoped_non_writable(dex_location); |
| 870 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 871 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 872 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 873 | kRuntimeISA, |
| 874 | default_context_.get(), |
| 875 | false); |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 876 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 877 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 878 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 879 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 880 | EXPECT_EQ(OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 881 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 882 | |
| 883 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 884 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 885 | EXPECT_EQ(OatFileAssistant::kOatBootImageOutOfDate, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 886 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 887 | |
| 888 | VerifyOptimizationStatus( |
| 889 | &oat_file_assistant, |
| 890 | dex_location, |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 891 | "verify", |
Calin Juravle | 9807115 | 2021-01-27 18:41:58 -0800 | [diff] [blame] | 892 | "unknown", |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 893 | "up-to-date"); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | // Case: We have a DEX file and a verify-at-runtime OAT file out of date with |
| 897 | // respect to the boot image. |
| 898 | // It shouldn't matter that the OAT file is out of date, because it is |
| 899 | // verify-at-runtime. |
| 900 | TEST_F(OatFileAssistantTest, OatVerifyAtRuntimeImageOutOfDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 901 | if (IsExecutedAsRoot()) { |
| 902 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 903 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 904 | return; |
| 905 | } |
| 906 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 907 | std::string dex_location = GetScratchDir() + "/OatVerifyAtRuntimeImageOutOfDate.jar"; |
| 908 | |
| 909 | Copy(GetDexSrc1(), dex_location); |
| 910 | GenerateOatForTest(dex_location.c_str(), |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 911 | CompilerFilter::kExtract, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 912 | /* with_alternate_image= */ true); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 913 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 914 | ScopedNonWritable scoped_non_writable(dex_location); |
| 915 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 916 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 917 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 918 | kRuntimeISA, |
| 919 | default_context_.get(), |
| 920 | false); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 921 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 922 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 923 | EXPECT_EQ(OatFileAssistant::kDex2OatForFilter, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 924 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 925 | |
| 926 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
| 927 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 928 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 929 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | // Case: We have a DEX file and an ODEX file, but no OAT file. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 933 | TEST_F(OatFileAssistantTest, DexOdexNoOat) { |
| 934 | std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 935 | std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 936 | |
| 937 | // Create the dex and odex files |
| 938 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 939 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 940 | |
| 941 | // Verify the status. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 942 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 943 | kRuntimeISA, |
| 944 | default_context_.get(), |
| 945 | false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 946 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 947 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 948 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 949 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 950 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 951 | |
| 952 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 953 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 954 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 955 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 5f946da | 2015-07-17 12:28:32 -0700 | [diff] [blame] | 956 | |
| 957 | // We should still be able to get the non-executable odex file to run from. |
| 958 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 959 | ASSERT_TRUE(oat_file.get() != nullptr); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 962 | // Case: We have a resource-only DEX file, no ODEX file and no |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 963 | // OAT file. Expect: The status is kNoDexOptNeeded. |
| 964 | TEST_F(OatFileAssistantTest, ResourceOnlyDex) { |
| 965 | std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar"; |
| 966 | |
Calin Juravle | 5ff2393 | 2020-12-11 18:26:14 -0800 | [diff] [blame] | 967 | Copy(GetResourceOnlySrc1(), dex_location); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 968 | |
| 969 | // Verify the status. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 970 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 971 | kRuntimeISA, |
| 972 | default_context_.get(), |
| 973 | true); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 974 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 975 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 976 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 977 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 978 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 979 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 980 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 981 | |
| 982 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 983 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 984 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 985 | EXPECT_FALSE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 986 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 987 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 988 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 989 | |
| 990 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 991 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 992 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 993 | EXPECT_FALSE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 996 | // Case: We have a DEX file, an ODEX file and an OAT file. |
| 997 | // Expect: It shouldn't crash. We should load the odex file executable. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 998 | TEST_F(OatFileAssistantTest, OdexOatOverlap) { |
| 999 | std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1000 | std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1001 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 1002 | // Create the dex, the odex and the oat files. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1003 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1004 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 1005 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1006 | |
| 1007 | // Verify things don't go bad. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1008 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1009 | kRuntimeISA, |
| 1010 | default_context_.get(), |
| 1011 | true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1012 | |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 1013 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 1014 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1015 | |
| 1016 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 1017 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
| 1018 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 1019 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1020 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1021 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 1022 | ASSERT_TRUE(oat_file.get() != nullptr); |
Richard Uhler | f16d572 | 2015-05-11 09:32:47 -0700 | [diff] [blame] | 1023 | |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 1024 | EXPECT_TRUE(oat_file->IsExecutable()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1025 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1026 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 1027 | EXPECT_EQ(1u, dex_files.size()); |
| 1028 | } |
| 1029 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1030 | // Case: We have a DEX file and a VerifyAtRuntime ODEX file, but no OAT file. |
| 1031 | // Expect: The status is kNoDexOptNeeded, because VerifyAtRuntime contains no code. |
| 1032 | TEST_F(OatFileAssistantTest, DexVerifyAtRuntimeOdexNoOat) { |
| 1033 | std::string dex_location = GetScratchDir() + "/DexVerifyAtRuntimeOdexNoOat.jar"; |
| 1034 | std::string odex_location = GetOdexDir() + "/DexVerifyAtRuntimeOdexNoOat.odex"; |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 1035 | |
| 1036 | // Create the dex and odex files |
| 1037 | Copy(GetDexSrc1(), dex_location); |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 1038 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kExtract); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 1039 | |
| 1040 | // Verify the status. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1041 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1042 | kRuntimeISA, |
| 1043 | default_context_.get(), |
| 1044 | false); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 1045 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1046 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 1047 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1048 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 1049 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 1050 | |
| 1051 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Richard Uhler | 3e580bc | 2016-11-08 16:23:07 +0000 | [diff] [blame] | 1052 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 1053 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 1054 | EXPECT_TRUE(oat_file_assistant.HasDexFiles()); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1057 | // Case: We have a DEX file and up-to-date OAT file for it. |
| 1058 | // Expect: We should load an executable dex file. |
| 1059 | TEST_F(OatFileAssistantTest, LoadOatUpToDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 1060 | if (IsExecutedAsRoot()) { |
| 1061 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 1062 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 1063 | return; |
| 1064 | } |
| 1065 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1066 | std::string dex_location = GetScratchDir() + "/LoadOatUpToDate.jar"; |
| 1067 | |
| 1068 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1069 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1070 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 1071 | ScopedNonWritable scoped_non_writable(dex_location); |
| 1072 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 1073 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1074 | // Load the oat using an oat file assistant. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1075 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1076 | kRuntimeISA, |
| 1077 | default_context_.get(), |
| 1078 | true); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1079 | |
| 1080 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 1081 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 1082 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 1083 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1084 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 1085 | EXPECT_EQ(1u, dex_files.size()); |
| 1086 | } |
| 1087 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 1088 | // Case: We have a DEX file and up-to-date quicken OAT file for it. |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1089 | // Expect: We should still load the oat file as executable. |
| 1090 | TEST_F(OatFileAssistantTest, LoadExecInterpretOnlyOatUpToDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 1091 | if (IsExecutedAsRoot()) { |
| 1092 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 1093 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 1094 | return; |
| 1095 | } |
| 1096 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1097 | std::string dex_location = GetScratchDir() + "/LoadExecInterpretOnlyOatUpToDate.jar"; |
| 1098 | |
| 1099 | Copy(GetDexSrc1(), dex_location); |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 1100 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kVerify); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1101 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 1102 | ScopedNonWritable scoped_non_writable(dex_location); |
| 1103 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 1104 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1105 | // Load the oat using an oat file assistant. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1106 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1107 | kRuntimeISA, |
| 1108 | default_context_.get(), |
| 1109 | true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1110 | |
| 1111 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 1112 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 1113 | EXPECT_TRUE(oat_file->IsExecutable()); |
| 1114 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1115 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 1116 | EXPECT_EQ(1u, dex_files.size()); |
| 1117 | } |
| 1118 | |
| 1119 | // Case: We have a DEX file and up-to-date OAT file for it. |
| 1120 | // Expect: Loading non-executable should load the oat non-executable. |
| 1121 | TEST_F(OatFileAssistantTest, LoadNoExecOatUpToDate) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 1122 | if (IsExecutedAsRoot()) { |
| 1123 | // We cannot simulate non writable locations when executed as root: b/38000545. |
| 1124 | LOG(ERROR) << "Test skipped because it's running as root"; |
| 1125 | return; |
| 1126 | } |
| 1127 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1128 | std::string dex_location = GetScratchDir() + "/LoadNoExecOatUpToDate.jar"; |
| 1129 | |
| 1130 | Copy(GetDexSrc1(), dex_location); |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 1131 | |
| 1132 | ScopedNonWritable scoped_non_writable(dex_location); |
| 1133 | ASSERT_TRUE(scoped_non_writable.IsSuccessful()); |
| 1134 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1135 | GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1136 | |
| 1137 | // Load the oat using an oat file assistant. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1138 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1139 | kRuntimeISA, |
| 1140 | default_context_.get(), |
| 1141 | false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1142 | |
| 1143 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 1144 | ASSERT_TRUE(oat_file.get() != nullptr); |
| 1145 | EXPECT_FALSE(oat_file->IsExecutable()); |
| 1146 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1147 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 1148 | EXPECT_EQ(1u, dex_files.size()); |
| 1149 | } |
| 1150 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1151 | // Turn an absolute path into a path relative to the current working |
| 1152 | // directory. |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 1153 | static std::string MakePathRelative(const std::string& target) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1154 | char buf[MAXPATHLEN]; |
| 1155 | std::string cwd = getcwd(buf, MAXPATHLEN); |
| 1156 | |
| 1157 | // Split the target and cwd paths into components. |
| 1158 | std::vector<std::string> target_path; |
| 1159 | std::vector<std::string> cwd_path; |
| 1160 | Split(target, '/', &target_path); |
| 1161 | Split(cwd, '/', &cwd_path); |
| 1162 | |
| 1163 | // Reverse the path components, so we can use pop_back(). |
| 1164 | std::reverse(target_path.begin(), target_path.end()); |
| 1165 | std::reverse(cwd_path.begin(), cwd_path.end()); |
| 1166 | |
| 1167 | // Drop the common prefix of the paths. Because we reversed the path |
| 1168 | // components, this becomes the common suffix of target_path and cwd_path. |
| 1169 | while (!target_path.empty() && !cwd_path.empty() |
| 1170 | && target_path.back() == cwd_path.back()) { |
| 1171 | target_path.pop_back(); |
| 1172 | cwd_path.pop_back(); |
| 1173 | } |
| 1174 | |
| 1175 | // For each element of the remaining cwd_path, add '..' to the beginning |
| 1176 | // of the target path. Because we reversed the path components, we add to |
| 1177 | // the end of target_path. |
| 1178 | for (unsigned int i = 0; i < cwd_path.size(); i++) { |
| 1179 | target_path.push_back(".."); |
| 1180 | } |
| 1181 | |
| 1182 | // Reverse again to get the right path order, and join to get the result. |
| 1183 | std::reverse(target_path.begin(), target_path.end()); |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 1184 | return android::base::Join(target_path, '/'); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | // Case: Non-absolute path to Dex location. |
| 1188 | // Expect: Not sure, but it shouldn't crash. |
| 1189 | TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) { |
| 1190 | std::string abs_dex_location = GetScratchDir() + "/NonAbsoluteDexLocation.jar"; |
| 1191 | Copy(GetDexSrc1(), abs_dex_location); |
| 1192 | |
| 1193 | std::string dex_location = MakePathRelative(abs_dex_location); |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1194 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1195 | kRuntimeISA, |
| 1196 | default_context_.get(), |
| 1197 | true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1198 | |
| 1199 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1200 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 1201 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 1202 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 1203 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | // Case: Very short, non-existent Dex location. |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 1207 | // Expect: kNoDexOptNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1208 | TEST_F(OatFileAssistantTest, ShortDexLocation) { |
| 1209 | std::string dex_location = "/xx"; |
| 1210 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1211 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1212 | kRuntimeISA, |
| 1213 | default_context_.get(), |
| 1214 | true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1215 | |
| 1216 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1217 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 1218 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 1219 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 1220 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 1221 | EXPECT_FALSE(oat_file_assistant.HasDexFiles()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | // Case: Non-standard extension for dex file. |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 1225 | // Expect: The status is kDex2OatNeeded. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1226 | TEST_F(OatFileAssistantTest, LongDexExtension) { |
| 1227 | std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx"; |
| 1228 | Copy(GetDexSrc1(), dex_location); |
| 1229 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1230 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1231 | kRuntimeISA, |
| 1232 | default_context_.get(), |
| 1233 | false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1234 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1235 | EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 1236 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1237 | |
| 1238 | EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 1239 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus()); |
| 1240 | EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | // A task to generate a dex location. Used by the RaceToGenerate test. |
| 1244 | class RaceGenerateTask : public Task { |
| 1245 | public: |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 1246 | RaceGenerateTask(OatFileAssistantTest& test, |
| 1247 | const std::string& dex_location, |
Nicolas Geoffray | 1e76d7a | 2018-09-03 13:23:34 +0100 | [diff] [blame] | 1248 | const std::string& oat_location, |
| 1249 | Mutex* lock) |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 1250 | : test_(test), |
| 1251 | dex_location_(dex_location), |
Nicolas Geoffray | 1e76d7a | 2018-09-03 13:23:34 +0100 | [diff] [blame] | 1252 | oat_location_(oat_location), |
| 1253 | lock_(lock), |
| 1254 | loaded_oat_file_(nullptr) |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1255 | {} |
| 1256 | |
Andreas Gampe | fa6a1b0 | 2018-09-07 08:11:55 -0700 | [diff] [blame] | 1257 | void Run(Thread* self ATTRIBUTE_UNUSED) override { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1258 | // Load the dex files, and save a pointer to the loaded oat file, so that |
| 1259 | // 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] | 1260 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1261 | std::vector<std::string> error_msgs; |
Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 1262 | const OatFile* oat_file = nullptr; |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1263 | { |
Nicolas Geoffray | 1e76d7a | 2018-09-03 13:23:34 +0100 | [diff] [blame] | 1264 | MutexLock mu(Thread::Current(), *lock_); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1265 | // Create the oat file. |
| 1266 | std::vector<std::string> args; |
| 1267 | args.push_back("--dex-file=" + dex_location_); |
| 1268 | args.push_back("--oat-file=" + oat_location_); |
| 1269 | std::string error_msg; |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 1270 | ASSERT_TRUE(test_.Dex2Oat(args, &error_msg)) << error_msg; |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1273 | dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat( |
| 1274 | dex_location_.c_str(), |
Jeff Hao | 0cb1728 | 2017-07-12 14:51:49 -0700 | [diff] [blame] | 1275 | Runtime::Current()->GetSystemClassLoader(), |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 1276 | /*dex_elements=*/nullptr, |
Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 1277 | &oat_file, |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1278 | &error_msgs); |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 1279 | CHECK(!dex_files.empty()) << android::base::Join(error_msgs, '\n'); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1280 | if (dex_files[0]->GetOatDexFile() != nullptr) { |
| 1281 | loaded_oat_file_ = dex_files[0]->GetOatDexFile()->GetOatFile(); |
| 1282 | } |
Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 1283 | CHECK_EQ(loaded_oat_file_, oat_file); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | const OatFile* GetLoadedOatFile() const { |
| 1287 | return loaded_oat_file_; |
| 1288 | } |
| 1289 | |
| 1290 | private: |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 1291 | OatFileAssistantTest& test_; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1292 | std::string dex_location_; |
| 1293 | std::string oat_location_; |
Nicolas Geoffray | 1e76d7a | 2018-09-03 13:23:34 +0100 | [diff] [blame] | 1294 | Mutex* lock_; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1295 | const OatFile* loaded_oat_file_; |
| 1296 | }; |
| 1297 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1298 | // Test the case where dex2oat invocations race with multiple processes trying to |
| 1299 | // load the oat file. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1300 | TEST_F(OatFileAssistantTest, RaceToGenerate) { |
| 1301 | std::string dex_location = GetScratchDir() + "/RaceToGenerate.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1302 | std::string oat_location = GetOdexDir() + "/RaceToGenerate.oat"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1303 | |
Jeff Hao | 0cb1728 | 2017-07-12 14:51:49 -0700 | [diff] [blame] | 1304 | // Start the runtime to initialize the system's class loader. |
| 1305 | Thread::Current()->TransitionFromSuspendedToRunnable(); |
| 1306 | runtime_->Start(); |
| 1307 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1308 | // We use the lib core dex file, because it's large, and hopefully should |
| 1309 | // take a while to generate. |
Narayan Kamath | d1ef436 | 2015-11-12 11:49:06 +0000 | [diff] [blame] | 1310 | Copy(GetLibCoreDexFileNames()[0], dex_location); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1311 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1312 | const size_t kNumThreads = 32; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1313 | Thread* self = Thread::Current(); |
| 1314 | ThreadPool thread_pool("Oat file assistant test thread pool", kNumThreads); |
| 1315 | std::vector<std::unique_ptr<RaceGenerateTask>> tasks; |
Nicolas Geoffray | 1e76d7a | 2018-09-03 13:23:34 +0100 | [diff] [blame] | 1316 | Mutex lock("RaceToGenerate"); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1317 | for (size_t i = 0; i < kNumThreads; i++) { |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 1318 | std::unique_ptr<RaceGenerateTask> task( |
| 1319 | new RaceGenerateTask(*this, dex_location, oat_location, &lock)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1320 | thread_pool.AddTask(self, task.get()); |
| 1321 | tasks.push_back(std::move(task)); |
| 1322 | } |
| 1323 | thread_pool.StartWorkers(self); |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 1324 | thread_pool.Wait(self, /* do_work= */ true, /* may_hold_locks= */ false); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1325 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1326 | // Verify that tasks which got an oat file got a unique one. |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1327 | std::set<const OatFile*> oat_files; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1328 | for (auto& task : tasks) { |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1329 | const OatFile* oat_file = task->GetLoadedOatFile(); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1330 | if (oat_file != nullptr) { |
| 1331 | EXPECT_TRUE(oat_files.find(oat_file) == oat_files.end()); |
| 1332 | oat_files.insert(oat_file); |
| 1333 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1337 | // Case: We have a DEX file and an ODEX file, and no OAT file, |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 1338 | // Expect: We should load the odex file executable. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1339 | TEST_F(OatFileAssistantTest, LoadDexOdexNoOat) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1340 | std::string dex_location = GetScratchDir() + "/LoadDexOdexNoOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1341 | std::string odex_location = GetOdexDir() + "/LoadDexOdexNoOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1342 | |
| 1343 | // Create the dex and odex files |
| 1344 | Copy(GetDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1345 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1346 | |
| 1347 | // Load the oat using an executable oat file assistant. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1348 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1349 | kRuntimeISA, |
| 1350 | default_context_.get(), |
| 1351 | true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1352 | |
| 1353 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 1354 | ASSERT_TRUE(oat_file.get() != nullptr); |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 1355 | EXPECT_TRUE(oat_file->IsExecutable()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1356 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1357 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 1358 | EXPECT_EQ(1u, dex_files.size()); |
| 1359 | } |
| 1360 | |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 1361 | // Case: We have a MultiDEX file and an ODEX file, and no OAT file. |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 1362 | // Expect: We should load the odex file executable. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1363 | TEST_F(OatFileAssistantTest, LoadMultiDexOdexNoOat) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1364 | std::string dex_location = GetScratchDir() + "/LoadMultiDexOdexNoOat.jar"; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1365 | std::string odex_location = GetOdexDir() + "/LoadMultiDexOdexNoOat.odex"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1366 | |
| 1367 | // Create the dex and odex files |
| 1368 | Copy(GetMultiDexSrc1(), dex_location); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 1369 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1370 | |
| 1371 | // Load the oat using an executable oat file assistant. |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1372 | OatFileAssistant oat_file_assistant(dex_location.c_str(), |
| 1373 | kRuntimeISA, |
| 1374 | default_context_.get(), |
| 1375 | true); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1376 | |
| 1377 | std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile(); |
| 1378 | ASSERT_TRUE(oat_file.get() != nullptr); |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 1379 | EXPECT_TRUE(oat_file->IsExecutable()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1380 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1381 | dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str()); |
| 1382 | EXPECT_EQ(2u, dex_files.size()); |
| 1383 | } |
| 1384 | |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 1385 | TEST(OatFileAssistantUtilsTest, DexLocationToOdexFilename) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1386 | std::string error_msg; |
| 1387 | std::string odex_file; |
| 1388 | |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 1389 | EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename( |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1390 | "/foo/bar/baz.jar", InstructionSet::kArm, &odex_file, &error_msg)) << error_msg; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1391 | EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1392 | |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 1393 | EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename( |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1394 | "/foo/bar/baz.funnyext", InstructionSet::kArm, &odex_file, &error_msg)) << error_msg; |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 1395 | EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1396 | |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 1397 | EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename( |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1398 | "nopath.jar", InstructionSet::kArm, &odex_file, &error_msg)); |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 1399 | EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename( |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1400 | "/foo/bar/baz_noext", InstructionSet::kArm, &odex_file, &error_msg)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1401 | } |
| 1402 | |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1403 | // Verify the dexopt status values from dalvik.system.DexFile |
| 1404 | // match the OatFileAssistant::DexOptStatus values. |
| 1405 | TEST_F(OatFileAssistantTest, DexOptStatusValues) { |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1406 | std::pair<OatFileAssistant::DexOptNeeded, const char*> mapping[] = { |
| 1407 | {OatFileAssistant::kNoDexOptNeeded, "NO_DEXOPT_NEEDED"}, |
| 1408 | {OatFileAssistant::kDex2OatFromScratch, "DEX2OAT_FROM_SCRATCH"}, |
| 1409 | {OatFileAssistant::kDex2OatForBootImage, "DEX2OAT_FOR_BOOT_IMAGE"}, |
| 1410 | {OatFileAssistant::kDex2OatForFilter, "DEX2OAT_FOR_FILTER"}, |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1411 | }; |
| 1412 | |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1413 | ScopedObjectAccess soa(Thread::Current()); |
| 1414 | StackHandleScope<1> hs(soa.Self()); |
| 1415 | ClassLinker* linker = Runtime::Current()->GetClassLinker(); |
| 1416 | Handle<mirror::Class> dexfile( |
| 1417 | hs.NewHandle(linker->FindSystemClass(soa.Self(), "Ldalvik/system/DexFile;"))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1418 | ASSERT_FALSE(dexfile == nullptr); |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1419 | linker->EnsureInitialized(soa.Self(), dexfile, true, true); |
| 1420 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1421 | for (std::pair<OatFileAssistant::DexOptNeeded, const char*> field : mapping) { |
| 1422 | ArtField* art_field = mirror::Class::FindStaticField( |
Vladimir Marko | 19a4d37 | 2016-12-08 14:41:46 +0000 | [diff] [blame] | 1423 | soa.Self(), dexfile.Get(), field.second, "I"); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1424 | ASSERT_FALSE(art_field == nullptr); |
| 1425 | EXPECT_EQ(art_field->GetTypeAsPrimitiveType(), Primitive::kPrimInt); |
| 1426 | EXPECT_EQ(field.first, art_field->GetInt(dexfile.Get())); |
| 1427 | } |
Richard Uhler | 23cedd2 | 2015-04-08 13:17:29 -0700 | [diff] [blame] | 1428 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1429 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1430 | TEST_F(OatFileAssistantTest, GetDexOptNeededWithOutOfDateContext) { |
| 1431 | std::string dex_location = GetScratchDir() + "/TestDex.jar"; |
Calin Juravle | af32242 | 2020-02-11 13:45:53 -0800 | [diff] [blame] | 1432 | std::string odex_location = GetOdexDir() + "/TestDex.odex"; |
| 1433 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1434 | std::string context_location = GetScratchDir() + "/ContextDex.jar"; |
| 1435 | Copy(GetDexSrc1(), dex_location); |
| 1436 | Copy(GetDexSrc2(), context_location); |
| 1437 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1438 | std::string context_str = "PCL[" + context_location + "]"; |
Calin Juravle | af32242 | 2020-02-11 13:45:53 -0800 | [diff] [blame] | 1439 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1440 | std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_str); |
| 1441 | ASSERT_TRUE(context != nullptr); |
Calin Juravle | 5ff2393 | 2020-12-11 18:26:14 -0800 | [diff] [blame] | 1442 | ASSERT_TRUE(context->OpenDexFiles()); |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1443 | |
Calin Juravle | af32242 | 2020-02-11 13:45:53 -0800 | [diff] [blame] | 1444 | std::string error_msg; |
| 1445 | std::vector<std::string> args; |
| 1446 | args.push_back("--dex-file=" + dex_location); |
| 1447 | args.push_back("--oat-file=" + odex_location); |
| 1448 | args.push_back("--class-loader-context=" + context_str); |
| 1449 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 1450 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1451 | // Update the context by overriding the jar file. |
| 1452 | Copy(GetMultiDexSrc2(), context_location); |
Calin Juravle | af32242 | 2020-02-11 13:45:53 -0800 | [diff] [blame] | 1453 | |
| 1454 | { |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 1455 | std::unique_ptr<ClassLoaderContext> updated_context = ClassLoaderContext::Create(context_str); |
| 1456 | ASSERT_TRUE(updated_context != nullptr); |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1457 | std::vector<int> context_fds; |
| 1458 | ASSERT_TRUE(updated_context->OpenDexFiles("", context_fds, /*only_read_checksums*/ true)); |
| 1459 | OatFileAssistant oat_file_assistant( |
| 1460 | dex_location.c_str(), kRuntimeISA, updated_context.get(), false); |
| 1461 | // DexOptNeeded should advise compilation for filter when the context changes. |
| 1462 | EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter, |
| 1463 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kDefaultCompilerFilter)); |
Calin Juravle | af32242 | 2020-02-11 13:45:53 -0800 | [diff] [blame] | 1464 | } |
| 1465 | { |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 1466 | std::unique_ptr<ClassLoaderContext> updated_context = ClassLoaderContext::Create(context_str); |
| 1467 | ASSERT_TRUE(updated_context != nullptr); |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1468 | std::vector<int> context_fds; |
| 1469 | ASSERT_TRUE(updated_context->OpenDexFiles("", context_fds, /*only_read_checksums*/ true)); |
| 1470 | OatFileAssistant oat_file_assistant( |
| 1471 | dex_location.c_str(), kRuntimeISA, updated_context.get(), false); |
Calin Juravle | af32242 | 2020-02-11 13:45:53 -0800 | [diff] [blame] | 1472 | // Now check that DexOptNeeded does not advise compilation if we only extracted the file. |
| 1473 | args.push_back("--compiler-filter=extract"); |
| 1474 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 1475 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 1476 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
| 1477 | } |
| 1478 | { |
| 1479 | std::unique_ptr<ClassLoaderContext> updated_context = ClassLoaderContext::Create(context_str); |
| 1480 | ASSERT_TRUE(updated_context != nullptr); |
| 1481 | std::vector<int> context_fds; |
| 1482 | ASSERT_TRUE(updated_context->OpenDexFiles("", context_fds, /*only_read_checksums*/ true)); |
| 1483 | OatFileAssistant oat_file_assistant( |
| 1484 | dex_location.c_str(), kRuntimeISA, updated_context.get(), false); |
| 1485 | // Now check that DexOptNeeded does not advise compilation if we only verify the file. |
| 1486 | args.push_back("--compiler-filter=verify"); |
| 1487 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 1488 | EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, |
| 1489 | GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract)); |
Calin Juravle | af32242 | 2020-02-11 13:45:53 -0800 | [diff] [blame] | 1490 | } |
Nicolas Geoffray | 2974260 | 2017-12-14 10:09:03 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1493 | // Test that GetLocation of a dex file is the same whether the dex |
| 1494 | // filed is backed by an oat file or not. |
| 1495 | TEST_F(OatFileAssistantTest, GetDexLocation) { |
| 1496 | std::string dex_location = GetScratchDir() + "/TestDex.jar"; |
| 1497 | std::string oat_location = GetOdexDir() + "/TestDex.odex"; |
Eric Holk | bc89ed4 | 2020-04-29 19:59:24 +0000 | [diff] [blame] | 1498 | std::string art_location = GetOdexDir() + "/TestDex.art"; |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1499 | |
| 1500 | // Start the runtime to initialize the system's class loader. |
| 1501 | Thread::Current()->TransitionFromSuspendedToRunnable(); |
| 1502 | runtime_->Start(); |
| 1503 | |
| 1504 | Copy(GetDexSrc1(), dex_location); |
| 1505 | |
| 1506 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1507 | std::vector<std::string> error_msgs; |
| 1508 | const OatFile* oat_file = nullptr; |
| 1509 | |
| 1510 | dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat( |
| 1511 | dex_location.c_str(), |
| 1512 | Runtime::Current()->GetSystemClassLoader(), |
| 1513 | /*dex_elements=*/nullptr, |
| 1514 | &oat_file, |
| 1515 | &error_msgs); |
Vladimir Marko | b7bf843 | 2019-12-03 13:18:50 +0000 | [diff] [blame] | 1516 | ASSERT_EQ(dex_files.size(), 1u) << android::base::Join(error_msgs, "\n"); |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1517 | EXPECT_EQ(oat_file, nullptr); |
| 1518 | std::string stored_dex_location = dex_files[0]->GetLocation(); |
| 1519 | { |
| 1520 | // Create the oat file. |
| 1521 | std::vector<std::string> args; |
| 1522 | args.push_back("--dex-file=" + dex_location); |
| 1523 | args.push_back("--dex-location=TestDex.jar"); |
| 1524 | args.push_back("--oat-file=" + oat_location); |
Eric Holk | bc89ed4 | 2020-04-29 19:59:24 +0000 | [diff] [blame] | 1525 | args.push_back("--app-image-file=" + art_location); |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1526 | std::string error_msg; |
| 1527 | ASSERT_TRUE(DexoptTest::Dex2Oat(args, &error_msg)) << error_msg; |
| 1528 | } |
| 1529 | dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat( |
| 1530 | dex_location.c_str(), |
| 1531 | Runtime::Current()->GetSystemClassLoader(), |
| 1532 | /*dex_elements=*/nullptr, |
| 1533 | &oat_file, |
| 1534 | &error_msgs); |
Vladimir Marko | b7bf843 | 2019-12-03 13:18:50 +0000 | [diff] [blame] | 1535 | ASSERT_EQ(dex_files.size(), 1u) << android::base::Join(error_msgs, "\n"); |
| 1536 | ASSERT_NE(oat_file, nullptr); |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1537 | std::string oat_stored_dex_location = dex_files[0]->GetLocation(); |
| 1538 | EXPECT_EQ(oat_stored_dex_location, stored_dex_location); |
| 1539 | } |
| 1540 | |
| 1541 | // Test that a dex file on the platform location gets the right hiddenapi domain, |
| 1542 | // regardless of whether it has a backing oat file. |
| 1543 | TEST_F(OatFileAssistantTest, SystemFrameworkDir) { |
| 1544 | std::string filebase = "OatFileAssistantTestSystemFrameworkDir"; |
| 1545 | std::string dex_location = GetAndroidRoot() + "/framework/" + filebase + ".jar"; |
| 1546 | Copy(GetDexSrc1(), dex_location); |
| 1547 | |
| 1548 | std::string odex_dir = GetAndroidRoot() + "/framework/oat/"; |
| 1549 | mkdir(odex_dir.c_str(), 0700); |
| 1550 | odex_dir = odex_dir + std::string(GetInstructionSetString(kRuntimeISA)); |
| 1551 | mkdir(odex_dir.c_str(), 0700); |
| 1552 | std::string oat_location = odex_dir + "/" + filebase + ".odex"; |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 1553 | std::string vdex_location = odex_dir + "/" + filebase + ".vdex"; |
Eric Holk | bc89ed4 | 2020-04-29 19:59:24 +0000 | [diff] [blame] | 1554 | std::string art_location = odex_dir + "/" + filebase + ".art"; |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1555 | // Clean up in case previous run crashed. |
| 1556 | remove(oat_location.c_str()); |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 1557 | remove(vdex_location.c_str()); |
| 1558 | remove(art_location.c_str()); |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1559 | |
| 1560 | // Start the runtime to initialize the system's class loader. |
| 1561 | Thread::Current()->TransitionFromSuspendedToRunnable(); |
| 1562 | runtime_->Start(); |
| 1563 | |
| 1564 | std::vector<std::unique_ptr<const DexFile>> dex_files_first; |
| 1565 | std::vector<std::unique_ptr<const DexFile>> dex_files_second; |
| 1566 | std::vector<std::string> error_msgs; |
| 1567 | const OatFile* oat_file = nullptr; |
| 1568 | |
| 1569 | dex_files_first = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat( |
| 1570 | dex_location.c_str(), |
| 1571 | Runtime::Current()->GetSystemClassLoader(), |
| 1572 | /*dex_elements=*/nullptr, |
| 1573 | &oat_file, |
| 1574 | &error_msgs); |
Vladimir Marko | b7bf843 | 2019-12-03 13:18:50 +0000 | [diff] [blame] | 1575 | ASSERT_EQ(dex_files_first.size(), 1u) << android::base::Join(error_msgs, "\n"); |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1576 | EXPECT_EQ(oat_file, nullptr) << dex_location; |
| 1577 | EXPECT_EQ(dex_files_first[0]->GetOatDexFile(), nullptr); |
| 1578 | |
| 1579 | // Register the dex file to get a domain. |
| 1580 | { |
| 1581 | ScopedObjectAccess soa(Thread::Current()); |
| 1582 | Runtime::Current()->GetClassLinker()->RegisterDexFile( |
| 1583 | *dex_files_first[0], |
| 1584 | soa.Decode<mirror::ClassLoader>(Runtime::Current()->GetSystemClassLoader())); |
| 1585 | } |
| 1586 | std::string stored_dex_location = dex_files_first[0]->GetLocation(); |
| 1587 | EXPECT_EQ(dex_files_first[0]->GetHiddenapiDomain(), hiddenapi::Domain::kPlatform); |
| 1588 | { |
| 1589 | // Create the oat file. |
| 1590 | std::vector<std::string> args; |
| 1591 | args.push_back("--dex-file=" + dex_location); |
| 1592 | args.push_back("--dex-location=" + filebase + ".jar"); |
| 1593 | args.push_back("--oat-file=" + oat_location); |
Eric Holk | bc89ed4 | 2020-04-29 19:59:24 +0000 | [diff] [blame] | 1594 | args.push_back("--app-image-file=" + art_location); |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1595 | std::string error_msg; |
| 1596 | ASSERT_TRUE(DexoptTest::Dex2Oat(args, &error_msg)) << error_msg; |
| 1597 | } |
| 1598 | dex_files_second = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat( |
| 1599 | dex_location.c_str(), |
| 1600 | Runtime::Current()->GetSystemClassLoader(), |
| 1601 | /*dex_elements=*/nullptr, |
| 1602 | &oat_file, |
| 1603 | &error_msgs); |
Vladimir Marko | b7bf843 | 2019-12-03 13:18:50 +0000 | [diff] [blame] | 1604 | ASSERT_EQ(dex_files_second.size(), 1u) << android::base::Join(error_msgs, "\n"); |
| 1605 | ASSERT_NE(oat_file, nullptr); |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame] | 1606 | EXPECT_NE(dex_files_second[0]->GetOatDexFile(), nullptr); |
| 1607 | EXPECT_NE(dex_files_second[0]->GetOatDexFile()->GetOatFile(), nullptr); |
| 1608 | |
| 1609 | // Register the dex file to get a domain. |
| 1610 | { |
| 1611 | ScopedObjectAccess soa(Thread::Current()); |
| 1612 | Runtime::Current()->GetClassLinker()->RegisterDexFile( |
| 1613 | *dex_files_second[0], |
| 1614 | soa.Decode<mirror::ClassLoader>(Runtime::Current()->GetSystemClassLoader())); |
| 1615 | } |
| 1616 | std::string oat_stored_dex_location = dex_files_second[0]->GetLocation(); |
| 1617 | EXPECT_EQ(oat_stored_dex_location, stored_dex_location); |
| 1618 | EXPECT_EQ(dex_files_second[0]->GetHiddenapiDomain(), hiddenapi::Domain::kPlatform); |
| 1619 | EXPECT_EQ(0, remove(oat_location.c_str())); |
| 1620 | } |
| 1621 | |
Eric Holk | bc89ed4 | 2020-04-29 19:59:24 +0000 | [diff] [blame] | 1622 | // Make sure OAT files that require app images are not loaded as executable. |
| 1623 | TEST_F(OatFileAssistantTest, LoadOatNoArt) { |
| 1624 | std::string dex_location = GetScratchDir() + "/TestDex.jar"; |
| 1625 | std::string odex_location = GetOdexDir() + "/TestDex.odex"; |
| 1626 | std::string art_location = GetOdexDir() + "/TestDex.art"; |
| 1627 | Copy(GetDexSrc1(), dex_location); |
| 1628 | GenerateOdexForTest(dex_location, |
| 1629 | odex_location, |
| 1630 | CompilerFilter::kSpeed, |
| 1631 | "install", |
| 1632 | { |
| 1633 | "--app-image-file=" + art_location, |
| 1634 | }); |
| 1635 | |
| 1636 | unlink(art_location.c_str()); |
| 1637 | |
| 1638 | std::vector<std::string> error_msgs; |
| 1639 | const OatFile* oat_file = nullptr; |
| 1640 | |
| 1641 | // Start the runtime to initialize the system's class loader. |
| 1642 | Thread::Current()->TransitionFromSuspendedToRunnable(); |
| 1643 | runtime_->Start(); |
| 1644 | |
| 1645 | const auto dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat( |
| 1646 | dex_location.c_str(), |
| 1647 | Runtime::Current()->GetSystemClassLoader(), |
| 1648 | /*dex_elements=*/nullptr, |
| 1649 | &oat_file, |
| 1650 | &error_msgs); |
| 1651 | |
| 1652 | EXPECT_FALSE(dex_files.empty()); |
Nicolas Geoffray | 90a18cf | 2020-06-25 15:12:59 +0100 | [diff] [blame] | 1653 | ASSERT_NE(oat_file, nullptr); |
Eric Holk | bc89ed4 | 2020-04-29 19:59:24 +0000 | [diff] [blame] | 1654 | EXPECT_FALSE(oat_file->IsExecutable()); |
| 1655 | } |
| 1656 | |
Nicolas Geoffray | d3c45c2 | 2021-04-27 13:21:28 +0100 | [diff] [blame] | 1657 | TEST_F(OatFileAssistantTest, GetDexOptNeededWithApexVersions) { |
| 1658 | std::string dex_location = GetScratchDir() + "/TestDex.jar"; |
| 1659 | std::string odex_location = GetOdexDir() + "/TestDex.odex"; |
| 1660 | Copy(GetDexSrc1(), dex_location); |
| 1661 | |
| 1662 | // Test that using the current's runtime apex versions works. |
| 1663 | { |
| 1664 | std::string error_msg; |
| 1665 | std::vector<std::string> args; |
| 1666 | args.push_back("--dex-file=" + dex_location); |
| 1667 | args.push_back("--oat-file=" + odex_location); |
| 1668 | args.push_back("--apex-versions=" + Runtime::Current()->GetApexVersions()); |
| 1669 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 1670 | |
| 1671 | OatFileAssistant oat_file_assistant( |
| 1672 | dex_location.c_str(), kRuntimeISA, default_context_.get(), false); |
| 1673 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
| 1674 | } |
| 1675 | |
| 1676 | // Test that a subset of apex versions works. |
| 1677 | { |
| 1678 | std::string error_msg; |
| 1679 | std::vector<std::string> args; |
| 1680 | args.push_back("--dex-file=" + dex_location); |
| 1681 | args.push_back("--oat-file=" + odex_location); |
| 1682 | args.push_back("--apex-versions=" + Runtime::Current()->GetApexVersions().substr(0, 1)); |
| 1683 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 1684 | |
| 1685 | OatFileAssistant oat_file_assistant( |
| 1686 | dex_location.c_str(), kRuntimeISA, default_context_.get(), false); |
| 1687 | EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus()); |
| 1688 | } |
| 1689 | |
| 1690 | // Test that different apex versions require to recompile. |
| 1691 | { |
| 1692 | std::string error_msg; |
| 1693 | std::vector<std::string> args; |
| 1694 | args.push_back("--dex-file=" + dex_location); |
| 1695 | args.push_back("--oat-file=" + odex_location); |
| 1696 | args.push_back("--apex-versions=/1/2/3/4"); |
| 1697 | ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg; |
| 1698 | |
| 1699 | OatFileAssistant oat_file_assistant( |
| 1700 | dex_location.c_str(), kRuntimeISA, default_context_.get(), false); |
| 1701 | EXPECT_EQ(OatFileAssistant::kDex2OatForBootImage, oat_file_assistant.OdexFileStatus()); |
| 1702 | } |
| 1703 | } |
| 1704 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1705 | // TODO: More Tests: |
| 1706 | // * Test class linker falls back to unquickened dex for DexNoOat |
| 1707 | // * Test class linker falls back to unquickened dex for MultiDexNoOat |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1708 | // * Test using secondary isa |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1709 | // * Test for status of oat while oat is being generated (how?) |
| 1710 | // * Test case where 32 and 64 bit boot class paths differ, |
| 1711 | // and we ask IsInBootClassPath for a class in exactly one of the 32 or |
| 1712 | // 64 bit boot class paths. |
| 1713 | // * Test unexpected scenarios (?): |
| 1714 | // - Dex is stripped, don't have odex. |
| 1715 | // - Oat file corrupted after status check, before reload unexecutable |
| 1716 | // because it's unrelocated and no dex2oat |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1717 | } // namespace art |