Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 | |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 17 | #include "odrefresh.h" |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 18 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 19 | #include <unistd.h> |
| 20 | |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 21 | #include <functional> |
| 22 | #include <memory> |
| 23 | #include <string_view> |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 24 | #include <utility> |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 25 | #include <vector> |
| 26 | |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 27 | #include "aidl/com/android/art/CompilerFilter.h" |
| 28 | #include "aidl/com/android/art/DexoptBcpExtArgs.h" |
| 29 | #include "aidl/com/android/art/DexoptSystemServerArgs.h" |
| 30 | #include "aidl/com/android/art/Isa.h" |
Jiakai Zhang | 34dcce5 | 2022-01-07 16:45:11 +0000 | [diff] [blame^] | 31 | #include "android-base/file.h" |
Victor Hsieh | d750630 | 2021-09-24 17:08:23 +0000 | [diff] [blame] | 32 | #include "android-base/parseint.h" |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 33 | #include "android-base/scopeguard.h" |
Jiakai Zhang | 617c6ab | 2021-09-24 05:06:07 +0000 | [diff] [blame] | 34 | #include "android-base/stringprintf.h" |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 35 | #include "android-base/strings.h" |
| 36 | #include "arch/instruction_set.h" |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 37 | #include "base/common_art_test.h" |
| 38 | #include "base/file_utils.h" |
Jiakai Zhang | 617c6ab | 2021-09-24 05:06:07 +0000 | [diff] [blame] | 39 | #include "base/stl_util.h" |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 40 | #include "exec_utils.h" |
| 41 | #include "gmock/gmock.h" |
| 42 | #include "gtest/gtest.h" |
Jiakai Zhang | 617c6ab | 2021-09-24 05:06:07 +0000 | [diff] [blame] | 43 | #include "odr_artifacts.h" |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 44 | #include "odr_common.h" |
| 45 | #include "odr_config.h" |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 46 | #include "odr_dexopt.h" |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 47 | #include "odr_fs_utils.h" |
| 48 | #include "odr_metrics.h" |
| 49 | #include "odrefresh/odrefresh.h" |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 50 | |
| 51 | namespace art { |
| 52 | namespace odrefresh { |
| 53 | |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 54 | using ::aidl::com::android::art::CompilerFilter; |
| 55 | using ::aidl::com::android::art::DexoptBcpExtArgs; |
| 56 | using ::aidl::com::android::art::DexoptSystemServerArgs; |
| 57 | using ::aidl::com::android::art::Isa; |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 58 | using ::testing::_; |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 59 | using ::testing::AllOf; |
| 60 | using ::testing::Contains; |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 61 | using ::testing::ElementsAre; |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 62 | using ::testing::Eq; |
| 63 | using ::testing::Field; |
| 64 | using ::testing::Ge; |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 65 | using ::testing::IsEmpty; |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 66 | using ::testing::Return; |
| 67 | |
| 68 | constexpr int kReplace = 1; |
| 69 | |
| 70 | void CreateEmptyFile(const std::string& name) { |
| 71 | File* file = OS::CreateEmptyFile(name.c_str()); |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 72 | ASSERT_TRUE(file != nullptr) << "Cannot create file " << name; |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 73 | file->Release(); |
| 74 | delete file; |
| 75 | } |
| 76 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 77 | android::base::ScopeGuard<std::function<void()>> ScopedCreateEmptyFile(const std::string& name) { |
| 78 | CreateEmptyFile(name); |
| 79 | return android::base::ScopeGuard([=]() { unlink(name.c_str()); }); |
| 80 | } |
| 81 | |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 82 | class MockOdrDexopt : public OdrDexopt { |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 83 | public: |
| 84 | // A workaround to avoid MOCK_METHOD on a method with an `std::string*` parameter, which will lead |
| 85 | // to a conflict between gmock and android-base/logging.h (b/132668253). |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 86 | int DexoptBcpExtension(const DexoptBcpExtArgs& args, time_t, bool*, std::string*) override { |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 87 | return DoDexoptBcpExtension(args); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 90 | int DexoptSystemServer(const DexoptSystemServerArgs& args, time_t, bool*, std::string*) override { |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 91 | return DoDexoptSystemServer(args); |
| 92 | } |
| 93 | |
| 94 | MOCK_METHOD(int, DoDexoptBcpExtension, (const DexoptBcpExtArgs&)); |
| 95 | MOCK_METHOD(int, DoDexoptSystemServer, (const DexoptSystemServerArgs&)); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 98 | // Matches an FD of a file whose path matches `matcher`. |
| 99 | MATCHER_P(FdOf, matcher, "") { |
| 100 | char path[PATH_MAX]; |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 101 | int fd = arg; |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 102 | std::string proc_path = android::base::StringPrintf("/proc/self/fd/%d", fd); |
| 103 | ssize_t len = readlink(proc_path.c_str(), path, sizeof(path)); |
| 104 | if (len < 0) { |
| 105 | return false; |
| 106 | } |
Jiakai Zhang | b1d9035 | 2021-09-22 09:08:26 +0000 | [diff] [blame] | 107 | std::string path_str{path, static_cast<size_t>(len)}; |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 108 | return ExplainMatchResult(matcher, path_str, result_listener); |
| 109 | } |
| 110 | |
Jiakai Zhang | 34dcce5 | 2022-01-07 16:45:11 +0000 | [diff] [blame^] | 111 | void WriteFakeApexInfoList(const std::string& filename) { |
| 112 | std::string content = R"xml( |
| 113 | <?xml version="1.0" encoding="utf-8"?> |
| 114 | <apex-info-list> |
| 115 | <apex-info |
| 116 | moduleName="com.android.art" |
| 117 | modulePath="/data/apex/active/com.android.art@319999900.apex" |
| 118 | preinstalledModulePath="/system/apex/com.android.art.capex" |
| 119 | versionCode="319999900" |
| 120 | versionName="" |
| 121 | isFactory="false" |
| 122 | isActive="true" |
| 123 | lastUpdateMillis="12345678"> |
| 124 | </apex-info> |
| 125 | </apex-info-list> |
| 126 | )xml"; |
| 127 | android::base::WriteStringToFile(content, filename); |
| 128 | } |
| 129 | |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 130 | class OdRefreshTest : public CommonArtTest { |
| 131 | public: |
| 132 | OdRefreshTest() : config_("odrefresh") {} |
| 133 | |
| 134 | protected: |
| 135 | void SetUp() override { |
| 136 | CommonArtTest::SetUp(); |
| 137 | |
| 138 | temp_dir_ = std::make_unique<ScratchDir>(); |
| 139 | std::string_view temp_dir_path = temp_dir_->GetPath(); |
| 140 | android::base::ConsumeSuffix(&temp_dir_path, "/"); |
| 141 | |
| 142 | std::string android_root_path = Concatenate({temp_dir_path, "/system"}); |
| 143 | ASSERT_TRUE(EnsureDirectoryExists(android_root_path)); |
| 144 | android_root_env_ = std::make_unique<ScopedUnsetEnvironmentVariable>("ANDROID_ROOT"); |
| 145 | setenv("ANDROID_ROOT", android_root_path.c_str(), kReplace); |
| 146 | |
| 147 | std::string android_art_root_path = Concatenate({temp_dir_path, "/apex/com.android.art"}); |
| 148 | ASSERT_TRUE(EnsureDirectoryExists(android_art_root_path)); |
| 149 | android_art_root_env_ = std::make_unique<ScopedUnsetEnvironmentVariable>("ANDROID_ART_ROOT"); |
| 150 | setenv("ANDROID_ART_ROOT", android_art_root_path.c_str(), kReplace); |
| 151 | |
| 152 | std::string art_apex_data_path = Concatenate({temp_dir_path, kArtApexDataDefaultPath}); |
| 153 | ASSERT_TRUE(EnsureDirectoryExists(art_apex_data_path)); |
| 154 | art_apex_data_env_ = std::make_unique<ScopedUnsetEnvironmentVariable>("ART_APEX_DATA"); |
| 155 | setenv("ART_APEX_DATA", art_apex_data_path.c_str(), kReplace); |
| 156 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 157 | dalvik_cache_dir_ = art_apex_data_path + "/dalvik-cache"; |
| 158 | ASSERT_TRUE(EnsureDirectoryExists(dalvik_cache_dir_ + "/x86_64")); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 159 | |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 160 | std::string system_etc_dir = Concatenate({android_root_path, "/etc"}); |
| 161 | ASSERT_TRUE(EnsureDirectoryExists(system_etc_dir)); |
| 162 | boot_profile_file_ = system_etc_dir + "/boot-image.prof"; |
| 163 | CreateEmptyFile(boot_profile_file_); |
| 164 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 165 | framework_dir_ = android_root_path + "/framework"; |
| 166 | framework_jar_ = framework_dir_ + "/framework.jar"; |
| 167 | location_provider_jar_ = framework_dir_ + "/com.android.location.provider.jar"; |
| 168 | services_jar_ = framework_dir_ + "/services.jar"; |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 169 | services_foo_jar_ = framework_dir_ + "/services-foo.jar"; |
| 170 | services_bar_jar_ = framework_dir_ + "/services-bar.jar"; |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 171 | std::string services_jar_prof = framework_dir_ + "/services.jar.prof"; |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 172 | std::string javalib_dir = android_art_root_path + "/javalib"; |
| 173 | std::string boot_art = javalib_dir + "/boot.art"; |
| 174 | |
| 175 | // Create placeholder files. |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 176 | ASSERT_TRUE(EnsureDirectoryExists(framework_dir_ + "/x86_64")); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 177 | CreateEmptyFile(framework_jar_); |
| 178 | CreateEmptyFile(location_provider_jar_); |
| 179 | CreateEmptyFile(services_jar_); |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 180 | CreateEmptyFile(services_foo_jar_); |
| 181 | CreateEmptyFile(services_bar_jar_); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 182 | CreateEmptyFile(services_jar_prof); |
| 183 | ASSERT_TRUE(EnsureDirectoryExists(javalib_dir)); |
| 184 | CreateEmptyFile(boot_art); |
| 185 | |
Jiakai Zhang | 34dcce5 | 2022-01-07 16:45:11 +0000 | [diff] [blame^] | 186 | std::string apex_info_filename = Concatenate({temp_dir_path, "/apex-info-list.xml"}); |
| 187 | WriteFakeApexInfoList(apex_info_filename); |
| 188 | config_.SetApexInfoListFile(apex_info_filename); |
| 189 | |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 190 | config_.SetArtBinDir(Concatenate({temp_dir_path, "/bin"})); |
| 191 | config_.SetBootClasspath(framework_jar_); |
| 192 | config_.SetDex2oatBootclasspath(framework_jar_); |
| 193 | config_.SetSystemServerClasspath(Concatenate({location_provider_jar_, ":", services_jar_})); |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 194 | config_.SetStandaloneSystemServerJars(Concatenate({services_foo_jar_, ":", services_bar_jar_})); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 195 | config_.SetIsa(InstructionSet::kX86_64); |
| 196 | config_.SetZygoteKind(ZygoteKind::kZygote64_32); |
Victor Hsieh | a39356a | 2021-12-16 11:40:39 -0800 | [diff] [blame] | 197 | config_.SetSystemServerCompilerFilter("speed"); // specify a default |
Jiakai Zhang | 34dcce5 | 2022-01-07 16:45:11 +0000 | [diff] [blame^] | 198 | config_.SetArtifactDirectory(dalvik_cache_dir_); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 199 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 200 | std::string staging_dir = dalvik_cache_dir_ + "/staging"; |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 201 | ASSERT_TRUE(EnsureDirectoryExists(staging_dir)); |
| 202 | config_.SetStagingDir(staging_dir); |
| 203 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 204 | metrics_ = std::make_unique<OdrMetrics>(dalvik_cache_dir_); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void TearDown() override { |
| 208 | metrics_.reset(); |
| 209 | temp_dir_.reset(); |
| 210 | android_root_env_.reset(); |
| 211 | android_art_root_env_.reset(); |
| 212 | art_apex_data_env_.reset(); |
| 213 | |
| 214 | CommonArtTest::TearDown(); |
| 215 | } |
| 216 | |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 217 | std::pair<std::unique_ptr<OnDeviceRefresh>, MockOdrDexopt*> CreateOdRefresh() { |
| 218 | auto mock_odr_dexopt = std::make_unique<MockOdrDexopt>(); |
| 219 | MockOdrDexopt* mock_odr_dexopt_ptr = mock_odr_dexopt.get(); |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 220 | auto odrefresh = std::make_unique<OnDeviceRefresh>(config_, |
| 221 | dalvik_cache_dir_ + "/cache-info.xml", |
| 222 | std::make_unique<ExecUtils>(), |
| 223 | std::move(mock_odr_dexopt)); |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 224 | return std::make_pair(std::move(odrefresh), mock_odr_dexopt_ptr); |
| 225 | } |
| 226 | |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 227 | std::unique_ptr<ScratchDir> temp_dir_; |
| 228 | std::unique_ptr<ScopedUnsetEnvironmentVariable> android_root_env_; |
| 229 | std::unique_ptr<ScopedUnsetEnvironmentVariable> android_art_root_env_; |
| 230 | std::unique_ptr<ScopedUnsetEnvironmentVariable> art_apex_data_env_; |
| 231 | OdrConfig config_; |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 232 | std::unique_ptr<OdrMetrics> metrics_; |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 233 | std::string framework_jar_; |
| 234 | std::string location_provider_jar_; |
| 235 | std::string services_jar_; |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 236 | std::string services_foo_jar_; |
| 237 | std::string services_bar_jar_; |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 238 | std::string dalvik_cache_dir_; |
| 239 | std::string framework_dir_; |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 240 | std::string boot_profile_file_; |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 243 | TEST_F(OdRefreshTest, AllSystemServerJars) { |
| 244 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
| 245 | |
| 246 | EXPECT_CALL(*mock_odr_dexopt, |
| 247 | DoDexoptSystemServer( |
| 248 | AllOf(Field(&DexoptSystemServerArgs::dexPath, Eq(location_provider_jar_)), |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 249 | Field(&DexoptSystemServerArgs::classloaderContext, IsEmpty()), |
| 250 | Field(&DexoptSystemServerArgs::classloaderContextAsParent, Eq(false))))) |
| 251 | .WillOnce(Return(0)); |
| 252 | EXPECT_CALL( |
| 253 | *mock_odr_dexopt, |
| 254 | DoDexoptSystemServer(AllOf( |
| 255 | Field(&DexoptSystemServerArgs::dexPath, Eq(services_jar_)), |
| 256 | Field(&DexoptSystemServerArgs::classloaderContext, ElementsAre(location_provider_jar_)), |
| 257 | Field(&DexoptSystemServerArgs::classloaderContextAsParent, Eq(false))))) |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 258 | .WillOnce(Return(0)); |
| 259 | EXPECT_CALL(*mock_odr_dexopt, |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 260 | DoDexoptSystemServer( |
| 261 | AllOf(Field(&DexoptSystemServerArgs::dexPath, Eq(services_foo_jar_)), |
| 262 | Field(&DexoptSystemServerArgs::classloaderContext, |
| 263 | ElementsAre(location_provider_jar_, services_jar_)), |
| 264 | Field(&DexoptSystemServerArgs::classloaderContextAsParent, Eq(true))))) |
| 265 | .WillOnce(Return(0)); |
| 266 | EXPECT_CALL(*mock_odr_dexopt, |
| 267 | DoDexoptSystemServer( |
| 268 | AllOf(Field(&DexoptSystemServerArgs::dexPath, Eq(services_bar_jar_)), |
| 269 | Field(&DexoptSystemServerArgs::classloaderContext, |
| 270 | ElementsAre(location_provider_jar_, services_jar_)), |
| 271 | Field(&DexoptSystemServerArgs::classloaderContextAsParent, Eq(true))))) |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 272 | .WillOnce(Return(0)); |
| 273 | |
| 274 | EXPECT_EQ( |
| 275 | odrefresh->Compile(*metrics_, |
| 276 | CompilationOptions{ |
| 277 | .system_server_jars_to_compile = odrefresh->AllSystemServerJars(), |
| 278 | }), |
| 279 | ExitCode::kCompilationSuccess); |
| 280 | } |
| 281 | |
| 282 | TEST_F(OdRefreshTest, PartialSystemServerJars) { |
| 283 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
| 284 | |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 285 | EXPECT_CALL( |
| 286 | *mock_odr_dexopt, |
| 287 | DoDexoptSystemServer(AllOf( |
| 288 | Field(&DexoptSystemServerArgs::dexPath, Eq(services_jar_)), |
| 289 | Field(&DexoptSystemServerArgs::classloaderContext, ElementsAre(location_provider_jar_)), |
| 290 | Field(&DexoptSystemServerArgs::classloaderContextAsParent, Eq(false))))) |
| 291 | .WillOnce(Return(0)); |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 292 | EXPECT_CALL(*mock_odr_dexopt, |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 293 | DoDexoptSystemServer( |
| 294 | AllOf(Field(&DexoptSystemServerArgs::dexPath, Eq(services_bar_jar_)), |
| 295 | Field(&DexoptSystemServerArgs::classloaderContext, |
| 296 | ElementsAre(location_provider_jar_, services_jar_)), |
| 297 | Field(&DexoptSystemServerArgs::classloaderContextAsParent, Eq(true))))) |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 298 | .WillOnce(Return(0)); |
| 299 | |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 300 | EXPECT_EQ( |
| 301 | odrefresh->Compile(*metrics_, |
| 302 | CompilationOptions{ |
| 303 | .system_server_jars_to_compile = {services_jar_, services_bar_jar_}, |
| 304 | }), |
| 305 | ExitCode::kCompilationSuccess); |
| 306 | } |
| 307 | |
| 308 | // Verifies that odrefresh can run properly when the STANDALONE_SYSTEM_SERVER_JARS variable is |
| 309 | // missing, which is expected on Android S. |
| 310 | TEST_F(OdRefreshTest, MissingStandaloneSystemServerJars) { |
| 311 | config_.SetStandaloneSystemServerJars(""); |
| 312 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
Jiakai Zhang | 34dcce5 | 2022-01-07 16:45:11 +0000 | [diff] [blame^] | 313 | EXPECT_CALL(*mock_odr_dexopt, DoDexoptSystemServer).WillRepeatedly(Return(0)); |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 314 | EXPECT_EQ( |
| 315 | odrefresh->Compile(*metrics_, |
| 316 | CompilationOptions{ |
| 317 | .system_server_jars_to_compile = odrefresh->AllSystemServerJars(), |
| 318 | }), |
| 319 | ExitCode::kCompilationSuccess); |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Victor Hsieh | d750630 | 2021-09-24 17:08:23 +0000 | [diff] [blame] | 322 | TEST_F(OdRefreshTest, CompileSetsCompilerFilter) { |
Jiakai Zhang | eb65b41 | 2021-11-26 14:29:38 +0000 | [diff] [blame] | 323 | { |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 324 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
| 325 | |
Victor Hsieh | a39356a | 2021-12-16 11:40:39 -0800 | [diff] [blame] | 326 | // Test setup: use "speed" compiler filter. |
| 327 | config_.SetSystemServerCompilerFilter("speed"); |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 328 | |
Jiakai Zhang | eb65b41 | 2021-11-26 14:29:38 +0000 | [diff] [blame] | 329 | // Uninteresting calls. |
| 330 | EXPECT_CALL(*mock_odr_dexopt, DoDexoptSystemServer(_)) |
| 331 | .Times(odrefresh->AllSystemServerJars().size() - 2) |
| 332 | .WillRepeatedly(Return(0)) |
| 333 | .RetiresOnSaturation(); |
| 334 | |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 335 | EXPECT_CALL(*mock_odr_dexopt, |
| 336 | DoDexoptSystemServer(AllOf( |
| 337 | Field(&DexoptSystemServerArgs::dexPath, Eq(location_provider_jar_)), |
| 338 | Field(&DexoptSystemServerArgs::compilerFilter, Eq(CompilerFilter::SPEED))))) |
| 339 | .WillOnce(Return(0)) |
| 340 | .RetiresOnSaturation(); |
| 341 | EXPECT_CALL(*mock_odr_dexopt, |
| 342 | DoDexoptSystemServer(AllOf( |
| 343 | Field(&DexoptSystemServerArgs::dexPath, Eq(services_jar_)), |
| 344 | Field(&DexoptSystemServerArgs::compilerFilter, Eq(CompilerFilter::SPEED))))) |
| 345 | .WillOnce(Return(0)) |
| 346 | .RetiresOnSaturation(); |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 347 | EXPECT_EQ( |
| 348 | odrefresh->Compile(*metrics_, |
| 349 | CompilationOptions{ |
| 350 | .system_server_jars_to_compile = odrefresh->AllSystemServerJars(), |
| 351 | }), |
| 352 | ExitCode::kCompilationSuccess); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | { |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 356 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
| 357 | |
| 358 | // Test setup: with "speed-profile" compiler filter in the request, only apply if there is a |
| 359 | // profile, otherwise fallback to speed. |
Victor Hsieh | a39356a | 2021-12-16 11:40:39 -0800 | [diff] [blame] | 360 | config_.SetSystemServerCompilerFilter("speed-profile"); |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 361 | |
Jiakai Zhang | eb65b41 | 2021-11-26 14:29:38 +0000 | [diff] [blame] | 362 | // Uninteresting calls. |
| 363 | EXPECT_CALL(*mock_odr_dexopt, DoDexoptSystemServer(_)) |
| 364 | .Times(odrefresh->AllSystemServerJars().size() - 2) |
| 365 | .WillRepeatedly(Return(0)) |
| 366 | .RetiresOnSaturation(); |
| 367 | |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 368 | // services.jar has a profile, while location.provider.jar does not. |
| 369 | EXPECT_CALL( |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 370 | *mock_odr_dexopt, |
| 371 | DoDexoptSystemServer(AllOf( |
| 372 | Field(&DexoptSystemServerArgs::dexPath, Eq(services_jar_)), |
| 373 | Field(&DexoptSystemServerArgs::profileFd, Ge(0)), |
| 374 | Field(&DexoptSystemServerArgs::compilerFilter, Eq(CompilerFilter::SPEED_PROFILE))))) |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 375 | .WillOnce(Return(0)) |
| 376 | .RetiresOnSaturation(); |
| 377 | EXPECT_CALL(*mock_odr_dexopt, |
| 378 | DoDexoptSystemServer(AllOf( |
| 379 | Field(&DexoptSystemServerArgs::dexPath, Eq(location_provider_jar_)), |
| 380 | Field(&DexoptSystemServerArgs::compilerFilter, Eq(CompilerFilter::SPEED))))) |
| 381 | .WillOnce(Return(0)) |
| 382 | .RetiresOnSaturation(); |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 383 | EXPECT_EQ( |
| 384 | odrefresh->Compile(*metrics_, |
| 385 | CompilationOptions{ |
| 386 | .system_server_jars_to_compile = odrefresh->AllSystemServerJars(), |
| 387 | }), |
| 388 | ExitCode::kCompilationSuccess); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | { |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 392 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
| 393 | |
| 394 | // Test setup: "verify" compiler filter should be simply applied. |
Victor Hsieh | a39356a | 2021-12-16 11:40:39 -0800 | [diff] [blame] | 395 | config_.SetSystemServerCompilerFilter("verify"); |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 396 | |
Jiakai Zhang | eb65b41 | 2021-11-26 14:29:38 +0000 | [diff] [blame] | 397 | // Uninteresting calls. |
| 398 | EXPECT_CALL(*mock_odr_dexopt, DoDexoptSystemServer(_)) |
| 399 | .Times(odrefresh->AllSystemServerJars().size() - 2) |
| 400 | .WillRepeatedly(Return(0)) |
| 401 | .RetiresOnSaturation(); |
| 402 | |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 403 | EXPECT_CALL(*mock_odr_dexopt, |
| 404 | DoDexoptSystemServer(AllOf( |
| 405 | Field(&DexoptSystemServerArgs::dexPath, Eq(location_provider_jar_)), |
| 406 | Field(&DexoptSystemServerArgs::compilerFilter, Eq(CompilerFilter::VERIFY))))) |
| 407 | .WillOnce(Return(0)) |
| 408 | .RetiresOnSaturation(); |
| 409 | EXPECT_CALL(*mock_odr_dexopt, |
| 410 | DoDexoptSystemServer(AllOf( |
| 411 | Field(&DexoptSystemServerArgs::dexPath, Eq(services_jar_)), |
| 412 | Field(&DexoptSystemServerArgs::compilerFilter, Eq(CompilerFilter::VERIFY))))) |
| 413 | .WillOnce(Return(0)) |
| 414 | .RetiresOnSaturation(); |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 415 | EXPECT_EQ( |
| 416 | odrefresh->Compile(*metrics_, |
| 417 | CompilationOptions{ |
| 418 | .system_server_jars_to_compile = odrefresh->AllSystemServerJars(), |
| 419 | }), |
| 420 | ExitCode::kCompilationSuccess); |
Jiakai Zhang | ccbcfb1 | 2021-08-23 15:10:35 +0000 | [diff] [blame] | 421 | } |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 424 | TEST_F(OdRefreshTest, OutputFilesAndIsa) { |
| 425 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
| 426 | |
Jiakai Zhang | 9b7ddf6 | 2021-11-01 11:36:52 +0000 | [diff] [blame] | 427 | EXPECT_CALL(*mock_odr_dexopt, |
| 428 | DoDexoptBcpExtension(AllOf(Field(&DexoptBcpExtArgs::isa, Eq(Isa::X86_64)), |
| 429 | Field(&DexoptBcpExtArgs::imageFd, Ge(0)), |
| 430 | Field(&DexoptBcpExtArgs::vdexFd, Ge(0)), |
| 431 | Field(&DexoptBcpExtArgs::oatFd, Ge(0))))) |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 432 | .WillOnce(Return(0)); |
| 433 | |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 434 | EXPECT_CALL(*mock_odr_dexopt, |
| 435 | DoDexoptSystemServer(AllOf(Field(&DexoptSystemServerArgs::isa, Eq(Isa::X86_64)), |
| 436 | Field(&DexoptSystemServerArgs::imageFd, Ge(0)), |
| 437 | Field(&DexoptSystemServerArgs::vdexFd, Ge(0)), |
| 438 | Field(&DexoptSystemServerArgs::oatFd, Ge(0))))) |
| 439 | .Times(odrefresh->AllSystemServerJars().size()) |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 440 | .WillRepeatedly(Return(0)); |
| 441 | |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 442 | EXPECT_EQ( |
| 443 | odrefresh->Compile(*metrics_, |
| 444 | CompilationOptions{ |
| 445 | .compile_boot_extensions_for_isas = {InstructionSet::kX86_64}, |
| 446 | .system_server_jars_to_compile = odrefresh->AllSystemServerJars(), |
| 447 | }), |
| 448 | ExitCode::kCompilationSuccess); |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 451 | TEST_F(OdRefreshTest, CompileChoosesBootImage) { |
| 452 | { |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 453 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
| 454 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 455 | // Boot image is on /data. |
| 456 | OdrArtifacts artifacts = |
| 457 | OdrArtifacts::ForBootImageExtension(dalvik_cache_dir_ + "/x86_64/boot-framework.art"); |
| 458 | auto file1 = ScopedCreateEmptyFile(artifacts.ImagePath()); |
| 459 | auto file2 = ScopedCreateEmptyFile(artifacts.VdexPath()); |
| 460 | auto file3 = ScopedCreateEmptyFile(artifacts.OatPath()); |
| 461 | |
| 462 | EXPECT_CALL( |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 463 | *mock_odr_dexopt, |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 464 | DoDexoptSystemServer(AllOf(Field(&DexoptSystemServerArgs::isBootImageOnSystem, Eq(false)), |
| 465 | Field(&DexoptSystemServerArgs::bootClasspathImageFds, |
| 466 | Contains(FdOf(artifacts.ImagePath()))), |
| 467 | Field(&DexoptSystemServerArgs::bootClasspathVdexFds, |
| 468 | Contains(FdOf(artifacts.VdexPath()))), |
| 469 | Field(&DexoptSystemServerArgs::bootClasspathOatFds, |
| 470 | Contains(FdOf(artifacts.OatPath())))))) |
| 471 | .Times(odrefresh->AllSystemServerJars().size()) |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 472 | .WillRepeatedly(Return(0)); |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 473 | EXPECT_EQ( |
| 474 | odrefresh->Compile(*metrics_, |
| 475 | CompilationOptions{ |
| 476 | .system_server_jars_to_compile = odrefresh->AllSystemServerJars(), |
| 477 | }), |
| 478 | ExitCode::kCompilationSuccess); |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | { |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 482 | auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh(); |
| 483 | |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 484 | // Boot image is on /system. |
| 485 | OdrArtifacts artifacts = |
| 486 | OdrArtifacts::ForBootImageExtension(framework_dir_ + "/x86_64/boot-framework.art"); |
| 487 | auto file1 = ScopedCreateEmptyFile(artifacts.ImagePath()); |
| 488 | auto file2 = ScopedCreateEmptyFile(artifacts.VdexPath()); |
| 489 | auto file3 = ScopedCreateEmptyFile(artifacts.OatPath()); |
| 490 | |
Victor Hsieh | 73c4f79 | 2021-10-01 18:13:52 +0000 | [diff] [blame] | 491 | EXPECT_CALL( |
| 492 | *mock_odr_dexopt, |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 493 | DoDexoptSystemServer(AllOf(Field(&DexoptSystemServerArgs::isBootImageOnSystem, Eq(true)), |
| 494 | Field(&DexoptSystemServerArgs::bootClasspathImageFds, |
| 495 | Contains(FdOf(artifacts.ImagePath()))), |
| 496 | Field(&DexoptSystemServerArgs::bootClasspathVdexFds, |
| 497 | Contains(FdOf(artifacts.VdexPath()))), |
| 498 | Field(&DexoptSystemServerArgs::bootClasspathOatFds, |
| 499 | Contains(FdOf(artifacts.OatPath())))))) |
| 500 | .Times(odrefresh->AllSystemServerJars().size()) |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 501 | .WillRepeatedly(Return(0)); |
Jiakai Zhang | 83c38e2 | 2021-11-03 20:54:55 +0000 | [diff] [blame] | 502 | EXPECT_EQ( |
| 503 | odrefresh->Compile(*metrics_, |
| 504 | CompilationOptions{ |
| 505 | .system_server_jars_to_compile = odrefresh->AllSystemServerJars(), |
| 506 | }), |
| 507 | ExitCode::kCompilationSuccess); |
Jiakai Zhang | 4e6cc73 | 2021-09-17 04:46:24 +0000 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 511 | } // namespace odrefresh |
| 512 | } // namespace art |