1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #include "odrefresh.h"
18*795d594fSAndroid Build Coastguard Worker
19*795d594fSAndroid Build Coastguard Worker #include <unistd.h>
20*795d594fSAndroid Build Coastguard Worker
21*795d594fSAndroid Build Coastguard Worker #include <functional>
22*795d594fSAndroid Build Coastguard Worker #include <memory>
23*795d594fSAndroid Build Coastguard Worker #include <string_view>
24*795d594fSAndroid Build Coastguard Worker #include <utility>
25*795d594fSAndroid Build Coastguard Worker #include <vector>
26*795d594fSAndroid Build Coastguard Worker
27*795d594fSAndroid Build Coastguard Worker #include "android-base/file.h"
28*795d594fSAndroid Build Coastguard Worker #include "android-base/parseint.h"
29*795d594fSAndroid Build Coastguard Worker #include "android-base/scopeguard.h"
30*795d594fSAndroid Build Coastguard Worker #include "android-base/stringprintf.h"
31*795d594fSAndroid Build Coastguard Worker #include "android-base/strings.h"
32*795d594fSAndroid Build Coastguard Worker #include "android-modules-utils/sdk_level.h"
33*795d594fSAndroid Build Coastguard Worker #include "arch/instruction_set.h"
34*795d594fSAndroid Build Coastguard Worker #include "base/common_art_test.h"
35*795d594fSAndroid Build Coastguard Worker #include "base/file_utils.h"
36*795d594fSAndroid Build Coastguard Worker #include "base/macros.h"
37*795d594fSAndroid Build Coastguard Worker #include "base/stl_util.h"
38*795d594fSAndroid Build Coastguard Worker #include "exec_utils.h"
39*795d594fSAndroid Build Coastguard Worker #include "gmock/gmock.h"
40*795d594fSAndroid Build Coastguard Worker #include "gtest/gtest.h"
41*795d594fSAndroid Build Coastguard Worker #include "odr_artifacts.h"
42*795d594fSAndroid Build Coastguard Worker #include "odr_common.h"
43*795d594fSAndroid Build Coastguard Worker #include "odr_config.h"
44*795d594fSAndroid Build Coastguard Worker #include "odr_fs_utils.h"
45*795d594fSAndroid Build Coastguard Worker #include "odr_metrics.h"
46*795d594fSAndroid Build Coastguard Worker #include "odrefresh/odrefresh.h"
47*795d594fSAndroid Build Coastguard Worker
48*795d594fSAndroid Build Coastguard Worker namespace art {
49*795d594fSAndroid Build Coastguard Worker namespace odrefresh {
50*795d594fSAndroid Build Coastguard Worker
51*795d594fSAndroid Build Coastguard Worker using ::android::base::Split;
52*795d594fSAndroid Build Coastguard Worker using ::android::modules::sdklevel::IsAtLeastU;
53*795d594fSAndroid Build Coastguard Worker using ::testing::_;
54*795d594fSAndroid Build Coastguard Worker using ::testing::AllOf;
55*795d594fSAndroid Build Coastguard Worker using ::testing::Contains;
56*795d594fSAndroid Build Coastguard Worker using ::testing::ElementsAre;
57*795d594fSAndroid Build Coastguard Worker using ::testing::Not;
58*795d594fSAndroid Build Coastguard Worker using ::testing::ResultOf;
59*795d594fSAndroid Build Coastguard Worker using ::testing::Return;
60*795d594fSAndroid Build Coastguard Worker
61*795d594fSAndroid Build Coastguard Worker constexpr int kReplace = 1;
62*795d594fSAndroid Build Coastguard Worker
CreateEmptyFile(const std::string & name)63*795d594fSAndroid Build Coastguard Worker void CreateEmptyFile(const std::string& name) {
64*795d594fSAndroid Build Coastguard Worker File* file = OS::CreateEmptyFile(name.c_str());
65*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(file != nullptr) << "Cannot create file " << name;
66*795d594fSAndroid Build Coastguard Worker file->Release();
67*795d594fSAndroid Build Coastguard Worker delete file;
68*795d594fSAndroid Build Coastguard Worker }
69*795d594fSAndroid Build Coastguard Worker
ScopedCreateEmptyFile(const std::string & name)70*795d594fSAndroid Build Coastguard Worker android::base::ScopeGuard<std::function<void()>> ScopedCreateEmptyFile(const std::string& name) {
71*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(name);
72*795d594fSAndroid Build Coastguard Worker return android::base::ScopeGuard([=]() { unlink(name.c_str()); });
73*795d594fSAndroid Build Coastguard Worker }
74*795d594fSAndroid Build Coastguard Worker
75*795d594fSAndroid Build Coastguard Worker class MockExecUtils : public ExecUtils {
76*795d594fSAndroid Build Coastguard Worker public:
77*795d594fSAndroid Build Coastguard Worker // A workaround to avoid MOCK_METHOD on a method with an `std::string*` parameter, which will lead
78*795d594fSAndroid Build Coastguard Worker // to a conflict between gmock and android-base/logging.h (b/132668253).
ExecAndReturnResult(const std::vector<std::string> & arg_vector,int,std::string *) const79*795d594fSAndroid Build Coastguard Worker ExecResult ExecAndReturnResult(const std::vector<std::string>& arg_vector,
80*795d594fSAndroid Build Coastguard Worker int,
81*795d594fSAndroid Build Coastguard Worker std::string*) const override {
82*795d594fSAndroid Build Coastguard Worker return {.status = ExecResult::kExited, .exit_code = DoExecAndReturnCode(arg_vector)};
83*795d594fSAndroid Build Coastguard Worker }
84*795d594fSAndroid Build Coastguard Worker
85*795d594fSAndroid Build Coastguard Worker MOCK_METHOD(int, DoExecAndReturnCode, (const std::vector<std::string>& arg_vector), (const));
86*795d594fSAndroid Build Coastguard Worker };
87*795d594fSAndroid Build Coastguard Worker
88*795d594fSAndroid Build Coastguard Worker // Matches a flag that starts with `flag` and whose value matches `matcher`.
89*795d594fSAndroid Build Coastguard Worker MATCHER_P2(Flag, flag, matcher, "") {
90*795d594fSAndroid Build Coastguard Worker std::string_view value(arg);
91*795d594fSAndroid Build Coastguard Worker if (!android::base::ConsumePrefix(&value, flag)) {
92*795d594fSAndroid Build Coastguard Worker return false;
93*795d594fSAndroid Build Coastguard Worker }
94*795d594fSAndroid Build Coastguard Worker return ExplainMatchResult(matcher, std::string(value), result_listener);
95*795d594fSAndroid Build Coastguard Worker }
96*795d594fSAndroid Build Coastguard Worker
97*795d594fSAndroid Build Coastguard Worker // Matches a flag that starts with `flag` and whose value is a colon-separated list that matches
98*795d594fSAndroid Build Coastguard Worker // `matcher`. The matcher acts on an `std::vector<std::string>` of the split list argument.
99*795d594fSAndroid Build Coastguard Worker MATCHER_P2(ListFlag, flag, matcher, "") {
100*795d594fSAndroid Build Coastguard Worker return ExplainMatchResult(
101*795d594fSAndroid Build Coastguard Worker Flag(flag, ResultOf(std::bind(Split, std::placeholders::_1, ":"), matcher)),
102*795d594fSAndroid Build Coastguard Worker arg,
103*795d594fSAndroid Build Coastguard Worker result_listener);
104*795d594fSAndroid Build Coastguard Worker }
105*795d594fSAndroid Build Coastguard Worker
106*795d594fSAndroid Build Coastguard Worker // Matches an FD of a file whose path matches `matcher`.
107*795d594fSAndroid Build Coastguard Worker MATCHER_P(FdOf, matcher, "") {
108*795d594fSAndroid Build Coastguard Worker char path[PATH_MAX];
109*795d594fSAndroid Build Coastguard Worker int fd;
110*795d594fSAndroid Build Coastguard Worker if (!android::base::ParseInt(std::string{arg}, &fd)) {
111*795d594fSAndroid Build Coastguard Worker return false;
112*795d594fSAndroid Build Coastguard Worker }
113*795d594fSAndroid Build Coastguard Worker std::string proc_path = android::base::StringPrintf("/proc/self/fd/%d", fd);
114*795d594fSAndroid Build Coastguard Worker ssize_t len = readlink(proc_path.c_str(), path, sizeof(path));
115*795d594fSAndroid Build Coastguard Worker if (len < 0) {
116*795d594fSAndroid Build Coastguard Worker return false;
117*795d594fSAndroid Build Coastguard Worker }
118*795d594fSAndroid Build Coastguard Worker std::string path_str{path, static_cast<size_t>(len)};
119*795d594fSAndroid Build Coastguard Worker return ExplainMatchResult(matcher, path_str, result_listener);
120*795d594fSAndroid Build Coastguard Worker }
121*795d594fSAndroid Build Coastguard Worker
WriteFakeApexInfoList(const std::string & filename)122*795d594fSAndroid Build Coastguard Worker void WriteFakeApexInfoList(const std::string& filename) {
123*795d594fSAndroid Build Coastguard Worker std::string content = R"xml(
124*795d594fSAndroid Build Coastguard Worker <?xml version="1.0" encoding="utf-8"?>
125*795d594fSAndroid Build Coastguard Worker <apex-info-list>
126*795d594fSAndroid Build Coastguard Worker <apex-info
127*795d594fSAndroid Build Coastguard Worker moduleName="com.android.art"
128*795d594fSAndroid Build Coastguard Worker modulePath="/data/apex/active/com.android.art@319999900.apex"
129*795d594fSAndroid Build Coastguard Worker preinstalledModulePath="/system/apex/com.android.art.capex"
130*795d594fSAndroid Build Coastguard Worker versionCode="319999900"
131*795d594fSAndroid Build Coastguard Worker versionName=""
132*795d594fSAndroid Build Coastguard Worker isFactory="false"
133*795d594fSAndroid Build Coastguard Worker isActive="true"
134*795d594fSAndroid Build Coastguard Worker lastUpdateMillis="12345678">
135*795d594fSAndroid Build Coastguard Worker </apex-info>
136*795d594fSAndroid Build Coastguard Worker </apex-info-list>
137*795d594fSAndroid Build Coastguard Worker )xml";
138*795d594fSAndroid Build Coastguard Worker android::base::WriteStringToFile(content, filename);
139*795d594fSAndroid Build Coastguard Worker }
140*795d594fSAndroid Build Coastguard Worker
141*795d594fSAndroid Build Coastguard Worker class OdRefreshTest : public CommonArtTest {
142*795d594fSAndroid Build Coastguard Worker public:
OdRefreshTest()143*795d594fSAndroid Build Coastguard Worker OdRefreshTest() : config_("odrefresh") {}
144*795d594fSAndroid Build Coastguard Worker
145*795d594fSAndroid Build Coastguard Worker protected:
SetUp()146*795d594fSAndroid Build Coastguard Worker void SetUp() override {
147*795d594fSAndroid Build Coastguard Worker CommonArtTest::SetUp();
148*795d594fSAndroid Build Coastguard Worker
149*795d594fSAndroid Build Coastguard Worker temp_dir_ = std::make_unique<ScratchDir>();
150*795d594fSAndroid Build Coastguard Worker std::string temp_dir_path = temp_dir_->GetPath();
151*795d594fSAndroid Build Coastguard Worker // Remove the trailing '/';
152*795d594fSAndroid Build Coastguard Worker temp_dir_path.resize(temp_dir_path.length() - 1);
153*795d594fSAndroid Build Coastguard Worker
154*795d594fSAndroid Build Coastguard Worker std::string android_root_path = temp_dir_path + "/system";
155*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(android_root_path));
156*795d594fSAndroid Build Coastguard Worker android_root_env_ = std::make_unique<ScopedUnsetEnvironmentVariable>("ANDROID_ROOT");
157*795d594fSAndroid Build Coastguard Worker setenv("ANDROID_ROOT", android_root_path.c_str(), kReplace);
158*795d594fSAndroid Build Coastguard Worker
159*795d594fSAndroid Build Coastguard Worker std::string android_art_root_path = temp_dir_path + "/apex/com.android.art";
160*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(android_art_root_path));
161*795d594fSAndroid Build Coastguard Worker android_art_root_env_ = std::make_unique<ScopedUnsetEnvironmentVariable>("ANDROID_ART_ROOT");
162*795d594fSAndroid Build Coastguard Worker setenv("ANDROID_ART_ROOT", android_art_root_path.c_str(), kReplace);
163*795d594fSAndroid Build Coastguard Worker
164*795d594fSAndroid Build Coastguard Worker std::string art_apex_data_path = temp_dir_path + kArtApexDataDefaultPath;
165*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(art_apex_data_path));
166*795d594fSAndroid Build Coastguard Worker art_apex_data_env_ = std::make_unique<ScopedUnsetEnvironmentVariable>("ART_APEX_DATA");
167*795d594fSAndroid Build Coastguard Worker setenv("ART_APEX_DATA", art_apex_data_path.c_str(), kReplace);
168*795d594fSAndroid Build Coastguard Worker
169*795d594fSAndroid Build Coastguard Worker dalvik_cache_dir_ = art_apex_data_path + "/dalvik-cache";
170*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(dalvik_cache_dir_ + "/x86_64"));
171*795d594fSAndroid Build Coastguard Worker
172*795d594fSAndroid Build Coastguard Worker std::string system_etc_dir = android_root_path + "/etc";
173*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(system_etc_dir));
174*795d594fSAndroid Build Coastguard Worker framework_profile_ = system_etc_dir + "/boot-image.prof";
175*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(framework_profile_);
176*795d594fSAndroid Build Coastguard Worker dirty_image_objects_file_ = system_etc_dir + "/dirty-image-objects";
177*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(dirty_image_objects_file_);
178*795d594fSAndroid Build Coastguard Worker preloaded_classes_file_ = system_etc_dir + "/preloaded-classes";
179*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(preloaded_classes_file_);
180*795d594fSAndroid Build Coastguard Worker art_etc_dir_ = android_art_root_path + "/etc";
181*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(art_etc_dir_));
182*795d594fSAndroid Build Coastguard Worker art_profile_ = art_etc_dir_ + "/boot-image.prof";
183*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(art_profile_);
184*795d594fSAndroid Build Coastguard Worker
185*795d594fSAndroid Build Coastguard Worker framework_dir_ = android_root_path + "/framework";
186*795d594fSAndroid Build Coastguard Worker framework_jar_ = framework_dir_ + "/framework.jar";
187*795d594fSAndroid Build Coastguard Worker location_provider_jar_ = framework_dir_ + "/com.android.location.provider.jar";
188*795d594fSAndroid Build Coastguard Worker services_jar_ = framework_dir_ + "/services.jar";
189*795d594fSAndroid Build Coastguard Worker services_foo_jar_ = framework_dir_ + "/services-foo.jar";
190*795d594fSAndroid Build Coastguard Worker services_bar_jar_ = framework_dir_ + "/services-bar.jar";
191*795d594fSAndroid Build Coastguard Worker services_jar_profile_ = framework_dir_ + "/services.jar.prof";
192*795d594fSAndroid Build Coastguard Worker std::string art_javalib_dir = android_art_root_path + "/javalib";
193*795d594fSAndroid Build Coastguard Worker core_oj_jar_ = art_javalib_dir + "/core-oj.jar";
194*795d594fSAndroid Build Coastguard Worker std::string conscrypt_javalib_dir = temp_dir_path + "/apex/com.android.conscrypt/javalib";
195*795d594fSAndroid Build Coastguard Worker conscrypt_jar_ = conscrypt_javalib_dir + "/conscrypt.jar";
196*795d594fSAndroid Build Coastguard Worker std::string wifi_javalib_dir = temp_dir_path + "/apex/com.android.wifi/javalib";
197*795d594fSAndroid Build Coastguard Worker framework_wifi_jar_ = wifi_javalib_dir + "/framework-wifi.jar";
198*795d594fSAndroid Build Coastguard Worker
199*795d594fSAndroid Build Coastguard Worker // Create placeholder files.
200*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(framework_dir_ + "/x86_64"));
201*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(framework_jar_);
202*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(location_provider_jar_);
203*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(services_jar_);
204*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(services_foo_jar_);
205*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(services_bar_jar_);
206*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(services_jar_profile_);
207*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(art_javalib_dir));
208*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(core_oj_jar_);
209*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(conscrypt_javalib_dir));
210*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(conscrypt_jar_);
211*795d594fSAndroid Build Coastguard Worker ASSERT_TRUE(EnsureDirectoryExists(wifi_javalib_dir));
212*795d594fSAndroid Build Coastguard Worker CreateEmptyFile(framework_wifi_jar_);
213*795d594fSAndroid Build Coastguard Worker
214*795d594fSAndroid Build Coastguard Worker std::string apex_info_filename = temp_dir_path + "/apex-info-list.xml";
215*795d594fSAndroid Build Coastguard Worker WriteFakeApexInfoList(apex_info_filename);
216*795d594fSAndroid Build Coastguard Worker config_.SetApexInfoListFile(apex_info_filename);
217*795d594fSAndroid Build Coastguard Worker
218*795d594fSAndroid Build Coastguard Worker config_.SetArtBinDir(temp_dir_path + "/bin");
219*795d594fSAndroid Build Coastguard Worker config_.SetBootClasspath(core_oj_jar_ + ":" + framework_jar_ + ":" + conscrypt_jar_ + ":" +
220*795d594fSAndroid Build Coastguard Worker framework_wifi_jar_);
221*795d594fSAndroid Build Coastguard Worker config_.SetDex2oatBootclasspath(core_oj_jar_ + ":" + framework_jar_);
222*795d594fSAndroid Build Coastguard Worker config_.SetSystemServerClasspath(location_provider_jar_ + ":" + services_jar_);
223*795d594fSAndroid Build Coastguard Worker config_.SetStandaloneSystemServerJars(services_foo_jar_ + ":" + services_bar_jar_);
224*795d594fSAndroid Build Coastguard Worker config_.SetIsa(InstructionSet::kX86_64);
225*795d594fSAndroid Build Coastguard Worker config_.SetZygoteKind(ZygoteKind::kZygote64_32);
226*795d594fSAndroid Build Coastguard Worker config_.SetSystemServerCompilerFilter("");
227*795d594fSAndroid Build Coastguard Worker config_.SetArtifactDirectory(dalvik_cache_dir_);
228*795d594fSAndroid Build Coastguard Worker
229*795d594fSAndroid Build Coastguard Worker auto mock_exec_utils = std::make_unique<MockExecUtils>();
230*795d594fSAndroid Build Coastguard Worker mock_exec_utils_ = mock_exec_utils.get();
231*795d594fSAndroid Build Coastguard Worker
232*795d594fSAndroid Build Coastguard Worker metrics_ = std::make_unique<OdrMetrics>(dalvik_cache_dir_);
233*795d594fSAndroid Build Coastguard Worker cache_info_xml_ = dalvik_cache_dir_ + "/cache-info.xml";
234*795d594fSAndroid Build Coastguard Worker check_compilation_space_ = [] { return true; };
235*795d594fSAndroid Build Coastguard Worker setfilecon_ = [](auto, auto) { return 0; };
236*795d594fSAndroid Build Coastguard Worker restorecon_ = [](auto, auto) { return 0; };
237*795d594fSAndroid Build Coastguard Worker odrefresh_ = std::make_unique<OnDeviceRefresh>(config_,
238*795d594fSAndroid Build Coastguard Worker setfilecon_,
239*795d594fSAndroid Build Coastguard Worker restorecon_,
240*795d594fSAndroid Build Coastguard Worker cache_info_xml_,
241*795d594fSAndroid Build Coastguard Worker std::move(mock_exec_utils),
242*795d594fSAndroid Build Coastguard Worker check_compilation_space_);
243*795d594fSAndroid Build Coastguard Worker }
244*795d594fSAndroid Build Coastguard Worker
TearDown()245*795d594fSAndroid Build Coastguard Worker void TearDown() override {
246*795d594fSAndroid Build Coastguard Worker metrics_.reset();
247*795d594fSAndroid Build Coastguard Worker temp_dir_.reset();
248*795d594fSAndroid Build Coastguard Worker android_root_env_.reset();
249*795d594fSAndroid Build Coastguard Worker android_art_root_env_.reset();
250*795d594fSAndroid Build Coastguard Worker art_apex_data_env_.reset();
251*795d594fSAndroid Build Coastguard Worker
252*795d594fSAndroid Build Coastguard Worker CommonArtTest::TearDown();
253*795d594fSAndroid Build Coastguard Worker }
254*795d594fSAndroid Build Coastguard Worker
255*795d594fSAndroid Build Coastguard Worker std::unique_ptr<ScratchDir> temp_dir_;
256*795d594fSAndroid Build Coastguard Worker std::unique_ptr<ScopedUnsetEnvironmentVariable> android_root_env_;
257*795d594fSAndroid Build Coastguard Worker std::unique_ptr<ScopedUnsetEnvironmentVariable> android_art_root_env_;
258*795d594fSAndroid Build Coastguard Worker std::unique_ptr<ScopedUnsetEnvironmentVariable> art_apex_data_env_;
259*795d594fSAndroid Build Coastguard Worker OdrConfig config_;
260*795d594fSAndroid Build Coastguard Worker MockExecUtils* mock_exec_utils_;
261*795d594fSAndroid Build Coastguard Worker std::unique_ptr<OnDeviceRefresh> odrefresh_;
262*795d594fSAndroid Build Coastguard Worker std::unique_ptr<OdrMetrics> metrics_;
263*795d594fSAndroid Build Coastguard Worker std::string core_oj_jar_;
264*795d594fSAndroid Build Coastguard Worker std::string framework_jar_;
265*795d594fSAndroid Build Coastguard Worker std::string conscrypt_jar_;
266*795d594fSAndroid Build Coastguard Worker std::string framework_wifi_jar_;
267*795d594fSAndroid Build Coastguard Worker std::string location_provider_jar_;
268*795d594fSAndroid Build Coastguard Worker std::string services_jar_;
269*795d594fSAndroid Build Coastguard Worker std::string services_foo_jar_;
270*795d594fSAndroid Build Coastguard Worker std::string services_bar_jar_;
271*795d594fSAndroid Build Coastguard Worker std::string dalvik_cache_dir_;
272*795d594fSAndroid Build Coastguard Worker std::string art_etc_dir_;
273*795d594fSAndroid Build Coastguard Worker std::string framework_dir_;
274*795d594fSAndroid Build Coastguard Worker std::string framework_profile_;
275*795d594fSAndroid Build Coastguard Worker std::string art_profile_;
276*795d594fSAndroid Build Coastguard Worker std::string services_jar_profile_;
277*795d594fSAndroid Build Coastguard Worker std::string dirty_image_objects_file_;
278*795d594fSAndroid Build Coastguard Worker std::string preloaded_classes_file_;
279*795d594fSAndroid Build Coastguard Worker std::string cache_info_xml_;
280*795d594fSAndroid Build Coastguard Worker std::function<bool()> check_compilation_space_;
281*795d594fSAndroid Build Coastguard Worker std::function<int(const char*, const char*)> setfilecon_;
282*795d594fSAndroid Build Coastguard Worker std::function<int(const char*, unsigned int)> restorecon_;
283*795d594fSAndroid Build Coastguard Worker };
284*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,PrimaryBootImage)285*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, PrimaryBootImage) {
286*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
287*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
288*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", core_oj_jar_)),
289*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", framework_jar_)),
290*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-file=", conscrypt_jar_))),
291*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-file=", framework_wifi_jar_))),
292*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-fd=", FdOf(core_oj_jar_))),
293*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-fd=", FdOf(framework_jar_))),
294*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-fd=", FdOf(conscrypt_jar_)))),
295*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-fd=", FdOf(framework_wifi_jar_)))),
296*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspath:", ElementsAre(core_oj_jar_, framework_jar_))),
297*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathfds:",
298*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(core_oj_jar_), FdOf(framework_jar_)))),
299*795d594fSAndroid Build Coastguard Worker Contains(Flag("--oat-location=", dalvik_cache_dir_ + "/x86_64/boot.oat")),
300*795d594fSAndroid Build Coastguard Worker Contains(Flag("--base=", _)),
301*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--boot-image=", _))),
302*795d594fSAndroid Build Coastguard Worker Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))))))
303*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
304*795d594fSAndroid Build Coastguard Worker
305*795d594fSAndroid Build Coastguard Worker // Ignore the invocation for the mainline extension.
306*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_, DoExecAndReturnCode(Contains(Flag("--dex-file=", conscrypt_jar_))))
307*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
308*795d594fSAndroid Build Coastguard Worker
309*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
310*795d594fSAndroid Build Coastguard Worker *metrics_,
311*795d594fSAndroid Build Coastguard Worker CompilationOptions{
312*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
313*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
314*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
315*795d594fSAndroid Build Coastguard Worker }),
316*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
317*795d594fSAndroid Build Coastguard Worker }
318*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,BootImageMainlineExtension)319*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, BootImageMainlineExtension) {
320*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
321*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
322*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
323*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-file=", core_oj_jar_))),
324*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-file=", framework_jar_))),
325*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", conscrypt_jar_)),
326*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", framework_wifi_jar_)),
327*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-fd=", FdOf(core_oj_jar_)))),
328*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-fd=", FdOf(framework_jar_)))),
329*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-fd=", FdOf(conscrypt_jar_))),
330*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-fd=", FdOf(framework_wifi_jar_))),
331*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
332*795d594fSAndroid Build Coastguard Worker "-Xbootclasspath:",
333*795d594fSAndroid Build Coastguard Worker ElementsAre(core_oj_jar_, framework_jar_, conscrypt_jar_, framework_wifi_jar_))),
334*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathfds:",
335*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(core_oj_jar_),
336*795d594fSAndroid Build Coastguard Worker FdOf(framework_jar_),
337*795d594fSAndroid Build Coastguard Worker FdOf(conscrypt_jar_),
338*795d594fSAndroid Build Coastguard Worker FdOf(framework_wifi_jar_)))),
339*795d594fSAndroid Build Coastguard Worker Contains(Flag("--oat-location=", dalvik_cache_dir_ + "/x86_64/boot-conscrypt.oat")),
340*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--base=", _))),
341*795d594fSAndroid Build Coastguard Worker Contains(Flag("--boot-image=", _)),
342*795d594fSAndroid Build Coastguard Worker Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))))))
343*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
344*795d594fSAndroid Build Coastguard Worker
345*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
346*795d594fSAndroid Build Coastguard Worker *metrics_,
347*795d594fSAndroid Build Coastguard Worker CompilationOptions{
348*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
349*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64, {.boot_image_mainline_extension = true}}},
350*795d594fSAndroid Build Coastguard Worker }),
351*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
352*795d594fSAndroid Build Coastguard Worker }
353*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,BootClasspathJarsWithExplicitCompilerFilter)354*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, BootClasspathJarsWithExplicitCompilerFilter) {
355*795d594fSAndroid Build Coastguard Worker config_.SetBootImageCompilerFilter("speed");
356*795d594fSAndroid Build Coastguard Worker
357*795d594fSAndroid Build Coastguard Worker // Profiles should still be passed for primary boot image.
358*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
359*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
360*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", core_oj_jar_)),
361*795d594fSAndroid Build Coastguard Worker Contains(Flag("--profile-file-fd=", FdOf(art_profile_))),
362*795d594fSAndroid Build Coastguard Worker Contains(Flag("--profile-file-fd=", FdOf(framework_profile_))),
363*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=speed"))))
364*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
365*795d594fSAndroid Build Coastguard Worker
366*795d594fSAndroid Build Coastguard Worker // "verify" should always be used for boot image mainline extension.
367*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
368*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", conscrypt_jar_)),
369*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--profile-file-fd=", _))),
370*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=verify"))))
371*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
372*795d594fSAndroid Build Coastguard Worker
373*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
374*795d594fSAndroid Build Coastguard Worker *metrics_,
375*795d594fSAndroid Build Coastguard Worker CompilationOptions{
376*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
377*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
378*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
379*795d594fSAndroid Build Coastguard Worker }),
380*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
381*795d594fSAndroid Build Coastguard Worker }
382*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,BootClasspathJarsWithDefaultCompilerFilter)383*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, BootClasspathJarsWithDefaultCompilerFilter) {
384*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
385*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
386*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", core_oj_jar_)),
387*795d594fSAndroid Build Coastguard Worker Contains(Flag("--profile-file-fd=", FdOf(art_profile_))),
388*795d594fSAndroid Build Coastguard Worker Contains(Flag("--profile-file-fd=", FdOf(framework_profile_))),
389*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=speed-profile"))))
390*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
391*795d594fSAndroid Build Coastguard Worker
392*795d594fSAndroid Build Coastguard Worker // "verify" should always be used for boot image mainline extension.
393*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
394*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", conscrypt_jar_)),
395*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--profile-file-fd=", _))),
396*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=verify"))))
397*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
398*795d594fSAndroid Build Coastguard Worker
399*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
400*795d594fSAndroid Build Coastguard Worker *metrics_,
401*795d594fSAndroid Build Coastguard Worker CompilationOptions{
402*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
403*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
404*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
405*795d594fSAndroid Build Coastguard Worker }),
406*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
407*795d594fSAndroid Build Coastguard Worker }
408*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,BootClasspathJarsFallback)409*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, BootClasspathJarsFallback) {
410*795d594fSAndroid Build Coastguard Worker // Simulate the case where dex2oat fails when generating the full boot image.
411*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
412*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", core_oj_jar_)),
413*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", framework_jar_)))))
414*795d594fSAndroid Build Coastguard Worker .Times(2)
415*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(1));
416*795d594fSAndroid Build Coastguard Worker
417*795d594fSAndroid Build Coastguard Worker // It should fall back to generating a minimal boot image.
418*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
419*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", core_oj_jar_)),
420*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--dex-file=", framework_jar_))))))
421*795d594fSAndroid Build Coastguard Worker .Times(2)
422*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
423*795d594fSAndroid Build Coastguard Worker
424*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
425*795d594fSAndroid Build Coastguard Worker *metrics_,
426*795d594fSAndroid Build Coastguard Worker CompilationOptions{
427*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
428*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
429*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}},
430*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86,
431*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
432*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
433*795d594fSAndroid Build Coastguard Worker }),
434*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationFailed);
435*795d594fSAndroid Build Coastguard Worker }
436*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,AllSystemServerJars)437*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, AllSystemServerJars) {
438*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
439*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", location_provider_jar_)),
440*795d594fSAndroid Build Coastguard Worker Contains("--class-loader-context=PCL[]"),
441*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--class-loader-context-fds=", _))),
442*795d594fSAndroid Build Coastguard Worker Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))))))
443*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
444*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
445*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
446*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
447*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", services_jar_)),
448*795d594fSAndroid Build Coastguard Worker Contains(Flag("--class-loader-context=", ART_FORMAT("PCL[{}]", location_provider_jar_))),
449*795d594fSAndroid Build Coastguard Worker Contains(Flag("--class-loader-context-fds=", FdOf(location_provider_jar_))),
450*795d594fSAndroid Build Coastguard Worker Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))))))
451*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
452*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
453*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
454*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
455*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", services_foo_jar_)),
456*795d594fSAndroid Build Coastguard Worker Contains(Flag("--class-loader-context=",
457*795d594fSAndroid Build Coastguard Worker ART_FORMAT("PCL[];PCL[{}:{}]", location_provider_jar_, services_jar_))),
458*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--class-loader-context-fds=",
459*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(location_provider_jar_), FdOf(services_jar_)))),
460*795d594fSAndroid Build Coastguard Worker Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))))))
461*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
462*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
463*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
464*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
465*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", services_bar_jar_)),
466*795d594fSAndroid Build Coastguard Worker Contains(Flag("--class-loader-context=",
467*795d594fSAndroid Build Coastguard Worker ART_FORMAT("PCL[];PCL[{}:{}]", location_provider_jar_, services_jar_))),
468*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--class-loader-context-fds=",
469*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(location_provider_jar_), FdOf(services_jar_)))),
470*795d594fSAndroid Build Coastguard Worker Contains(Flag("--cache-info-fd=", FdOf(cache_info_xml_))))))
471*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
472*795d594fSAndroid Build Coastguard Worker
473*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
474*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
475*795d594fSAndroid Build Coastguard Worker CompilationOptions{
476*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
477*795d594fSAndroid Build Coastguard Worker }),
478*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
479*795d594fSAndroid Build Coastguard Worker }
480*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,PartialSystemServerJars)481*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, PartialSystemServerJars) {
482*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
483*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
484*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
485*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", services_jar_)),
486*795d594fSAndroid Build Coastguard Worker Contains(Flag("--class-loader-context=", ART_FORMAT("PCL[{}]", location_provider_jar_))),
487*795d594fSAndroid Build Coastguard Worker Contains(Flag("--class-loader-context-fds=", FdOf(location_provider_jar_))))))
488*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
489*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
490*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
491*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
492*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", services_bar_jar_)),
493*795d594fSAndroid Build Coastguard Worker Contains(Flag("--class-loader-context=",
494*795d594fSAndroid Build Coastguard Worker ART_FORMAT("PCL[];PCL[{}:{}]", location_provider_jar_, services_jar_))),
495*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--class-loader-context-fds=",
496*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(location_provider_jar_), FdOf(services_jar_)))))))
497*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
498*795d594fSAndroid Build Coastguard Worker
499*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
500*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
501*795d594fSAndroid Build Coastguard Worker CompilationOptions{
502*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = {services_jar_, services_bar_jar_},
503*795d594fSAndroid Build Coastguard Worker }),
504*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
505*795d594fSAndroid Build Coastguard Worker }
506*795d594fSAndroid Build Coastguard Worker
507*795d594fSAndroid Build Coastguard Worker // Verifies that odrefresh can run properly when the STANDALONE_SYSTEM_SERVER_JARS variable is
508*795d594fSAndroid Build Coastguard Worker // missing, which is expected on Android S.
TEST_F(OdRefreshTest,MissingStandaloneSystemServerJars)509*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, MissingStandaloneSystemServerJars) {
510*795d594fSAndroid Build Coastguard Worker config_.SetStandaloneSystemServerJars("");
511*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_, DoExecAndReturnCode(_)).WillRepeatedly(Return(0));
512*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
513*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
514*795d594fSAndroid Build Coastguard Worker CompilationOptions{
515*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
516*795d594fSAndroid Build Coastguard Worker }),
517*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
518*795d594fSAndroid Build Coastguard Worker }
519*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,ContinueWhenBcpCompilationFailed)520*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, ContinueWhenBcpCompilationFailed) {
521*795d594fSAndroid Build Coastguard Worker // Simulate that the compilation of BCP for the system server ISA succeeds.
522*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
523*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains("--instruction-set=x86_64"),
524*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", core_oj_jar_)))))
525*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
526*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
527*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains("--instruction-set=x86_64"),
528*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", conscrypt_jar_)))))
529*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
530*795d594fSAndroid Build Coastguard Worker
531*795d594fSAndroid Build Coastguard Worker // Simulate that the compilation of BCP for the other ISA fails.
532*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
533*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains("--instruction-set=x86"),
534*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", core_oj_jar_)))))
535*795d594fSAndroid Build Coastguard Worker .Times(2)
536*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(1));
537*795d594fSAndroid Build Coastguard Worker
538*795d594fSAndroid Build Coastguard Worker // It should still compile system server.
539*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
540*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(Contains(Flag("--dex-file=", location_provider_jar_))))
541*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
542*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_, DoExecAndReturnCode(Contains(Flag("--dex-file=", services_jar_))))
543*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
544*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
545*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(Contains(Flag("--dex-file=", services_foo_jar_))))
546*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
547*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
548*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(Contains(Flag("--dex-file=", services_bar_jar_))))
549*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
550*795d594fSAndroid Build Coastguard Worker
551*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
552*795d594fSAndroid Build Coastguard Worker *metrics_,
553*795d594fSAndroid Build Coastguard Worker CompilationOptions{
554*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
555*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
556*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}},
557*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86,
558*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
559*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
560*795d594fSAndroid Build Coastguard Worker }),
561*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationFailed);
562*795d594fSAndroid Build Coastguard Worker }
563*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,ContinueWhenSystemServerCompilationFailed)564*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, ContinueWhenSystemServerCompilationFailed) {
565*795d594fSAndroid Build Coastguard Worker // Simulate that the compilation of "services.jar" fails, while others still succeed.
566*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
567*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(Contains(Flag("--dex-file=", location_provider_jar_))))
568*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
569*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_, DoExecAndReturnCode(Contains(Flag("--dex-file=", services_jar_))))
570*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(1));
571*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
572*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(Contains(Flag("--dex-file=", services_foo_jar_))))
573*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
574*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
575*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(Contains(Flag("--dex-file=", services_bar_jar_))))
576*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
577*795d594fSAndroid Build Coastguard Worker
578*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
579*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
580*795d594fSAndroid Build Coastguard Worker CompilationOptions{
581*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
582*795d594fSAndroid Build Coastguard Worker }),
583*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationFailed);
584*795d594fSAndroid Build Coastguard Worker }
585*795d594fSAndroid Build Coastguard Worker
586*795d594fSAndroid Build Coastguard Worker // Test setup: The compiler filter is explicitly set to "speed-profile". Use it regardless of
587*795d594fSAndroid Build Coastguard Worker // whether the profile exists or not. Dex2oat will fall back to "verify" if the profile doesn't
588*795d594fSAndroid Build Coastguard Worker // exist.
TEST_F(OdRefreshTest,CompileSetsCompilerFilterWithExplicitValue)589*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, CompileSetsCompilerFilterWithExplicitValue) {
590*795d594fSAndroid Build Coastguard Worker config_.SetSystemServerCompilerFilter("speed-profile");
591*795d594fSAndroid Build Coastguard Worker
592*795d594fSAndroid Build Coastguard Worker // Uninteresting calls.
593*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_, DoExecAndReturnCode(_))
594*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size() - 2)
595*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
596*795d594fSAndroid Build Coastguard Worker
597*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
598*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", location_provider_jar_)),
599*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--profile-file-fd=", _))),
600*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=speed-profile"))))
601*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
602*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
603*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
604*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", services_jar_)),
605*795d594fSAndroid Build Coastguard Worker Contains(Flag("--profile-file-fd=", FdOf(services_jar_profile_))),
606*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=speed-profile"))))
607*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
608*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
609*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
610*795d594fSAndroid Build Coastguard Worker CompilationOptions{
611*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
612*795d594fSAndroid Build Coastguard Worker }),
613*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
614*795d594fSAndroid Build Coastguard Worker }
615*795d594fSAndroid Build Coastguard Worker
616*795d594fSAndroid Build Coastguard Worker // Test setup: The compiler filter is not explicitly set. Use "speed-profile" if there is a vetted
617*795d594fSAndroid Build Coastguard Worker // profile (on U+), otherwise fall back to "speed".
TEST_F(OdRefreshTest,CompileSetsCompilerFilterWithDefaultValue)618*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, CompileSetsCompilerFilterWithDefaultValue) {
619*795d594fSAndroid Build Coastguard Worker // Uninteresting calls.
620*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_, DoExecAndReturnCode(_))
621*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size() - 2)
622*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
623*795d594fSAndroid Build Coastguard Worker
624*795d594fSAndroid Build Coastguard Worker // services.jar has a profile, while location.provider.jar does not.
625*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
626*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", location_provider_jar_)),
627*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--profile-file-fd=", _))),
628*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=speed"))))
629*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
630*795d594fSAndroid Build Coastguard Worker // Only on U+ should we use the profile by default if available.
631*795d594fSAndroid Build Coastguard Worker if (IsAtLeastU()) {
632*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
633*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
634*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", services_jar_)),
635*795d594fSAndroid Build Coastguard Worker Contains(Flag("--profile-file-fd=", FdOf(services_jar_profile_))),
636*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=speed-profile"))))
637*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
638*795d594fSAndroid Build Coastguard Worker } else {
639*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
640*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", services_jar_)),
641*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--profile-file-fd=", _))),
642*795d594fSAndroid Build Coastguard Worker Contains("--compiler-filter=speed"))))
643*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
644*795d594fSAndroid Build Coastguard Worker }
645*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
646*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
647*795d594fSAndroid Build Coastguard Worker CompilationOptions{
648*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
649*795d594fSAndroid Build Coastguard Worker }),
650*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
651*795d594fSAndroid Build Coastguard Worker }
652*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,OutputFilesAndIsa)653*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, OutputFilesAndIsa) {
654*795d594fSAndroid Build Coastguard Worker config_.MutableSystemProperties()->emplace("dalvik.vm.isa.x86_64.features", "foo");
655*795d594fSAndroid Build Coastguard Worker config_.MutableSystemProperties()->emplace("dalvik.vm.isa.x86_64.variant", "bar");
656*795d594fSAndroid Build Coastguard Worker
657*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
658*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains("--instruction-set=x86_64"),
659*795d594fSAndroid Build Coastguard Worker Contains(Flag("--instruction-set-features=", "foo")),
660*795d594fSAndroid Build Coastguard Worker Contains(Flag("--instruction-set-variant=", "bar")),
661*795d594fSAndroid Build Coastguard Worker Contains(Flag("--image-fd=", FdOf(_))),
662*795d594fSAndroid Build Coastguard Worker Contains(Flag("--output-vdex-fd=", FdOf(_))),
663*795d594fSAndroid Build Coastguard Worker Contains(Flag("--oat-fd=", FdOf(_))))))
664*795d594fSAndroid Build Coastguard Worker .Times(2)
665*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
666*795d594fSAndroid Build Coastguard Worker
667*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
668*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains("--instruction-set=x86_64"),
669*795d594fSAndroid Build Coastguard Worker Contains(Flag("--instruction-set-features=", "foo")),
670*795d594fSAndroid Build Coastguard Worker Contains(Flag("--instruction-set-variant=", "bar")),
671*795d594fSAndroid Build Coastguard Worker Contains(Flag("--app-image-fd=", FdOf(_))),
672*795d594fSAndroid Build Coastguard Worker Contains(Flag("--output-vdex-fd=", FdOf(_))),
673*795d594fSAndroid Build Coastguard Worker Contains(Flag("--oat-fd=", FdOf(_))))))
674*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size())
675*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
676*795d594fSAndroid Build Coastguard Worker
677*795d594fSAndroid Build Coastguard Worker // No instruction set features or variant set for x86.
678*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
679*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains("--instruction-set=x86"),
680*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--instruction-set-features=", _))),
681*795d594fSAndroid Build Coastguard Worker Not(Contains(Flag("--instruction-set-variant=", _))))))
682*795d594fSAndroid Build Coastguard Worker .Times(2)
683*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
684*795d594fSAndroid Build Coastguard Worker
685*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
686*795d594fSAndroid Build Coastguard Worker *metrics_,
687*795d594fSAndroid Build Coastguard Worker CompilationOptions{
688*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
689*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
690*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}},
691*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86,
692*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
693*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
694*795d594fSAndroid Build Coastguard Worker }),
695*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
696*795d594fSAndroid Build Coastguard Worker }
697*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,RuntimeOptions)698*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, RuntimeOptions) {
699*795d594fSAndroid Build Coastguard Worker config_.MutableSystemProperties()->emplace("dalvik.vm.image-dex2oat-Xms", "10");
700*795d594fSAndroid Build Coastguard Worker config_.MutableSystemProperties()->emplace("dalvik.vm.image-dex2oat-Xmx", "20");
701*795d594fSAndroid Build Coastguard Worker config_.MutableSystemProperties()->emplace("dalvik.vm.dex2oat-Xms", "30");
702*795d594fSAndroid Build Coastguard Worker config_.MutableSystemProperties()->emplace("dalvik.vm.dex2oat-Xmx", "40");
703*795d594fSAndroid Build Coastguard Worker
704*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
705*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--image-fd=", FdOf(_))),
706*795d594fSAndroid Build Coastguard Worker Contains(Flag("-Xms", "10")),
707*795d594fSAndroid Build Coastguard Worker Contains(Flag("-Xmx", "20")))))
708*795d594fSAndroid Build Coastguard Worker .Times(2)
709*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
710*795d594fSAndroid Build Coastguard Worker
711*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
712*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--app-image-fd=", FdOf(_))),
713*795d594fSAndroid Build Coastguard Worker Contains(Flag("-Xms", "30")),
714*795d594fSAndroid Build Coastguard Worker Contains(Flag("-Xmx", "40")))))
715*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size())
716*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
717*795d594fSAndroid Build Coastguard Worker
718*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
719*795d594fSAndroid Build Coastguard Worker *metrics_,
720*795d594fSAndroid Build Coastguard Worker CompilationOptions{
721*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
722*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
723*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
724*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
725*795d594fSAndroid Build Coastguard Worker }),
726*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
727*795d594fSAndroid Build Coastguard Worker }
728*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,GenerateBootImageMainlineExtensionChoosesBootImage_OnData)729*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, GenerateBootImageMainlineExtensionChoosesBootImage_OnData) {
730*795d594fSAndroid Build Coastguard Worker // Primary boot image is on /data.
731*795d594fSAndroid Build Coastguard Worker OdrArtifacts primary = OdrArtifacts::ForBootImage(dalvik_cache_dir_ + "/x86_64/boot.art");
732*795d594fSAndroid Build Coastguard Worker auto file1 = ScopedCreateEmptyFile(primary.ImagePath());
733*795d594fSAndroid Build Coastguard Worker auto file2 = ScopedCreateEmptyFile(primary.VdexPath());
734*795d594fSAndroid Build Coastguard Worker auto file3 = ScopedCreateEmptyFile(primary.OatPath());
735*795d594fSAndroid Build Coastguard Worker
736*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
737*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
738*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", conscrypt_jar_)),
739*795d594fSAndroid Build Coastguard Worker Contains(Flag("--boot-image=", dalvik_cache_dir_ + "/boot.art")),
740*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathimagefds:",
741*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.ImagePath()), "-1", "-1", "-1"))),
742*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathvdexfds:",
743*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.VdexPath()), "-1", "-1", "-1"))),
744*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathoatfds:",
745*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.OatPath()), "-1", "-1", "-1"))))))
746*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
747*795d594fSAndroid Build Coastguard Worker
748*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
749*795d594fSAndroid Build Coastguard Worker *metrics_,
750*795d594fSAndroid Build Coastguard Worker CompilationOptions{
751*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
752*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64, {.boot_image_mainline_extension = true}}},
753*795d594fSAndroid Build Coastguard Worker }),
754*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
755*795d594fSAndroid Build Coastguard Worker }
756*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,GenerateBootImageMainlineExtensionChoosesBootImage_OnSystem)757*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, GenerateBootImageMainlineExtensionChoosesBootImage_OnSystem) {
758*795d594fSAndroid Build Coastguard Worker // Primary boot image and framework extension are on /system.
759*795d594fSAndroid Build Coastguard Worker OdrArtifacts primary = OdrArtifacts::ForBootImage(framework_dir_ + "/x86_64/boot.art");
760*795d594fSAndroid Build Coastguard Worker auto file1 = ScopedCreateEmptyFile(primary.ImagePath());
761*795d594fSAndroid Build Coastguard Worker auto file2 = ScopedCreateEmptyFile(primary.VdexPath());
762*795d594fSAndroid Build Coastguard Worker auto file3 = ScopedCreateEmptyFile(primary.OatPath());
763*795d594fSAndroid Build Coastguard Worker OdrArtifacts framework_ext =
764*795d594fSAndroid Build Coastguard Worker OdrArtifacts::ForBootImage(framework_dir_ + "/x86_64/boot-framework.art");
765*795d594fSAndroid Build Coastguard Worker auto file4 = ScopedCreateEmptyFile(framework_ext.ImagePath());
766*795d594fSAndroid Build Coastguard Worker auto file5 = ScopedCreateEmptyFile(framework_ext.VdexPath());
767*795d594fSAndroid Build Coastguard Worker auto file6 = ScopedCreateEmptyFile(framework_ext.OatPath());
768*795d594fSAndroid Build Coastguard Worker
769*795d594fSAndroid Build Coastguard Worker if (IsAtLeastU()) {
770*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
771*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
772*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
773*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", conscrypt_jar_)),
774*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--boot-image=", ElementsAre(framework_dir_ + "/boot.art"))),
775*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
776*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathimagefds:",
777*795d594fSAndroid Build Coastguard Worker ElementsAre(
778*795d594fSAndroid Build Coastguard Worker FdOf(primary.ImagePath()), FdOf(framework_ext.ImagePath()), "-1", "-1"))),
779*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
780*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathvdexfds:",
781*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.VdexPath()), FdOf(framework_ext.VdexPath()), "-1", "-1"))),
782*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
783*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathoatfds:",
784*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.OatPath()), FdOf(framework_ext.OatPath()), "-1", "-1"))))))
785*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
786*795d594fSAndroid Build Coastguard Worker } else {
787*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
788*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
789*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
790*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", conscrypt_jar_)),
791*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
792*795d594fSAndroid Build Coastguard Worker "--boot-image=",
793*795d594fSAndroid Build Coastguard Worker ElementsAre(framework_dir_ + "/boot.art", framework_dir_ + "/boot-framework.art"))),
794*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
795*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathimagefds:",
796*795d594fSAndroid Build Coastguard Worker ElementsAre(
797*795d594fSAndroid Build Coastguard Worker FdOf(primary.ImagePath()), FdOf(framework_ext.ImagePath()), "-1", "-1"))),
798*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
799*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathvdexfds:",
800*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.VdexPath()), FdOf(framework_ext.VdexPath()), "-1", "-1"))),
801*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
802*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathoatfds:",
803*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.OatPath()), FdOf(framework_ext.OatPath()), "-1", "-1"))))))
804*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
805*795d594fSAndroid Build Coastguard Worker }
806*795d594fSAndroid Build Coastguard Worker
807*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
808*795d594fSAndroid Build Coastguard Worker *metrics_,
809*795d594fSAndroid Build Coastguard Worker CompilationOptions{
810*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
811*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64, {.boot_image_mainline_extension = true}}},
812*795d594fSAndroid Build Coastguard Worker }),
813*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
814*795d594fSAndroid Build Coastguard Worker }
815*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,CompileSystemServerChoosesBootImage_OnData)816*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, CompileSystemServerChoosesBootImage_OnData) {
817*795d594fSAndroid Build Coastguard Worker // Boot images are on /data.
818*795d594fSAndroid Build Coastguard Worker OdrArtifacts primary = OdrArtifacts::ForBootImage(dalvik_cache_dir_ + "/x86_64/boot.art");
819*795d594fSAndroid Build Coastguard Worker auto file1 = ScopedCreateEmptyFile(primary.ImagePath());
820*795d594fSAndroid Build Coastguard Worker auto file2 = ScopedCreateEmptyFile(primary.VdexPath());
821*795d594fSAndroid Build Coastguard Worker auto file3 = ScopedCreateEmptyFile(primary.OatPath());
822*795d594fSAndroid Build Coastguard Worker OdrArtifacts mainline_ext =
823*795d594fSAndroid Build Coastguard Worker OdrArtifacts::ForBootImage(dalvik_cache_dir_ + "/x86_64/boot-conscrypt.art");
824*795d594fSAndroid Build Coastguard Worker auto file4 = ScopedCreateEmptyFile(mainline_ext.ImagePath());
825*795d594fSAndroid Build Coastguard Worker auto file5 = ScopedCreateEmptyFile(mainline_ext.VdexPath());
826*795d594fSAndroid Build Coastguard Worker auto file6 = ScopedCreateEmptyFile(mainline_ext.OatPath());
827*795d594fSAndroid Build Coastguard Worker
828*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(
829*795d594fSAndroid Build Coastguard Worker *mock_exec_utils_,
830*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
831*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--boot-image=",
832*795d594fSAndroid Build Coastguard Worker ElementsAre(dalvik_cache_dir_ + "/boot.art",
833*795d594fSAndroid Build Coastguard Worker dalvik_cache_dir_ + "/boot-conscrypt.art"))),
834*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
835*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathimagefds:",
836*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.ImagePath()), "-1", FdOf(mainline_ext.ImagePath()), "-1"))),
837*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
838*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathvdexfds:",
839*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.VdexPath()), "-1", FdOf(mainline_ext.VdexPath()), "-1"))),
840*795d594fSAndroid Build Coastguard Worker Contains(ListFlag(
841*795d594fSAndroid Build Coastguard Worker "-Xbootclasspathoatfds:",
842*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.OatPath()), "-1", FdOf(mainline_ext.OatPath()), "-1"))))))
843*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size())
844*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
845*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
846*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
847*795d594fSAndroid Build Coastguard Worker CompilationOptions{
848*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
849*795d594fSAndroid Build Coastguard Worker }),
850*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
851*795d594fSAndroid Build Coastguard Worker }
852*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,CompileSystemServerChoosesBootImage_OnSystemAndData)853*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, CompileSystemServerChoosesBootImage_OnSystemAndData) {
854*795d594fSAndroid Build Coastguard Worker // The mainline extension is on /data, while others are on /system.
855*795d594fSAndroid Build Coastguard Worker OdrArtifacts primary = OdrArtifacts::ForBootImage(framework_dir_ + "/x86_64/boot.art");
856*795d594fSAndroid Build Coastguard Worker auto file1 = ScopedCreateEmptyFile(primary.ImagePath());
857*795d594fSAndroid Build Coastguard Worker auto file2 = ScopedCreateEmptyFile(primary.VdexPath());
858*795d594fSAndroid Build Coastguard Worker auto file3 = ScopedCreateEmptyFile(primary.OatPath());
859*795d594fSAndroid Build Coastguard Worker OdrArtifacts framework_ext =
860*795d594fSAndroid Build Coastguard Worker OdrArtifacts::ForBootImage(framework_dir_ + "/x86_64/boot-framework.art");
861*795d594fSAndroid Build Coastguard Worker auto file4 = ScopedCreateEmptyFile(framework_ext.ImagePath());
862*795d594fSAndroid Build Coastguard Worker auto file5 = ScopedCreateEmptyFile(framework_ext.VdexPath());
863*795d594fSAndroid Build Coastguard Worker auto file6 = ScopedCreateEmptyFile(framework_ext.OatPath());
864*795d594fSAndroid Build Coastguard Worker OdrArtifacts mainline_ext =
865*795d594fSAndroid Build Coastguard Worker OdrArtifacts::ForBootImage(dalvik_cache_dir_ + "/x86_64/boot-conscrypt.art");
866*795d594fSAndroid Build Coastguard Worker auto file7 = ScopedCreateEmptyFile(mainline_ext.ImagePath());
867*795d594fSAndroid Build Coastguard Worker auto file8 = ScopedCreateEmptyFile(mainline_ext.VdexPath());
868*795d594fSAndroid Build Coastguard Worker auto file9 = ScopedCreateEmptyFile(mainline_ext.OatPath());
869*795d594fSAndroid Build Coastguard Worker
870*795d594fSAndroid Build Coastguard Worker if (IsAtLeastU()) {
871*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
872*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
873*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--boot-image=",
874*795d594fSAndroid Build Coastguard Worker ElementsAre(GetPrebuiltPrimaryBootImageDir() + "/boot.art",
875*795d594fSAndroid Build Coastguard Worker dalvik_cache_dir_ + "/boot-conscrypt.art"))),
876*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathimagefds:",
877*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.ImagePath()),
878*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.ImagePath()),
879*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.ImagePath()),
880*795d594fSAndroid Build Coastguard Worker "-1"))),
881*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathvdexfds:",
882*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.VdexPath()),
883*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.VdexPath()),
884*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.VdexPath()),
885*795d594fSAndroid Build Coastguard Worker "-1"))),
886*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathoatfds:",
887*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.OatPath()),
888*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.OatPath()),
889*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.OatPath()),
890*795d594fSAndroid Build Coastguard Worker "-1"))))))
891*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size())
892*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
893*795d594fSAndroid Build Coastguard Worker } else {
894*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
895*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
896*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--boot-image=",
897*795d594fSAndroid Build Coastguard Worker ElementsAre(GetPrebuiltPrimaryBootImageDir() + "/boot.art",
898*795d594fSAndroid Build Coastguard Worker framework_dir_ + "/boot-framework.art",
899*795d594fSAndroid Build Coastguard Worker dalvik_cache_dir_ + "/boot-conscrypt.art"))),
900*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathimagefds:",
901*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.ImagePath()),
902*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.ImagePath()),
903*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.ImagePath()),
904*795d594fSAndroid Build Coastguard Worker "-1"))),
905*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathvdexfds:",
906*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.VdexPath()),
907*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.VdexPath()),
908*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.VdexPath()),
909*795d594fSAndroid Build Coastguard Worker "-1"))),
910*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathoatfds:",
911*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.OatPath()),
912*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.OatPath()),
913*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.OatPath()),
914*795d594fSAndroid Build Coastguard Worker "-1"))))))
915*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size())
916*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
917*795d594fSAndroid Build Coastguard Worker }
918*795d594fSAndroid Build Coastguard Worker
919*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
920*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
921*795d594fSAndroid Build Coastguard Worker CompilationOptions{
922*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
923*795d594fSAndroid Build Coastguard Worker }),
924*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
925*795d594fSAndroid Build Coastguard Worker }
926*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,CompileSystemServerChoosesBootImage_OnSystem)927*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, CompileSystemServerChoosesBootImage_OnSystem) {
928*795d594fSAndroid Build Coastguard Worker // Boot images are on /system.
929*795d594fSAndroid Build Coastguard Worker OdrArtifacts primary = OdrArtifacts::ForBootImage(framework_dir_ + "/x86_64/boot.art");
930*795d594fSAndroid Build Coastguard Worker auto file1 = ScopedCreateEmptyFile(primary.ImagePath());
931*795d594fSAndroid Build Coastguard Worker auto file2 = ScopedCreateEmptyFile(primary.VdexPath());
932*795d594fSAndroid Build Coastguard Worker auto file3 = ScopedCreateEmptyFile(primary.OatPath());
933*795d594fSAndroid Build Coastguard Worker OdrArtifacts framework_ext =
934*795d594fSAndroid Build Coastguard Worker OdrArtifacts::ForBootImage(framework_dir_ + "/x86_64/boot-framework.art");
935*795d594fSAndroid Build Coastguard Worker auto file4 = ScopedCreateEmptyFile(framework_ext.ImagePath());
936*795d594fSAndroid Build Coastguard Worker auto file5 = ScopedCreateEmptyFile(framework_ext.VdexPath());
937*795d594fSAndroid Build Coastguard Worker auto file6 = ScopedCreateEmptyFile(framework_ext.OatPath());
938*795d594fSAndroid Build Coastguard Worker OdrArtifacts mainline_ext =
939*795d594fSAndroid Build Coastguard Worker OdrArtifacts::ForBootImage(framework_dir_ + "/x86_64/boot-conscrypt.art");
940*795d594fSAndroid Build Coastguard Worker auto file7 = ScopedCreateEmptyFile(mainline_ext.ImagePath());
941*795d594fSAndroid Build Coastguard Worker auto file8 = ScopedCreateEmptyFile(mainline_ext.VdexPath());
942*795d594fSAndroid Build Coastguard Worker auto file9 = ScopedCreateEmptyFile(mainline_ext.OatPath());
943*795d594fSAndroid Build Coastguard Worker
944*795d594fSAndroid Build Coastguard Worker if (IsAtLeastU()) {
945*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
946*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
947*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--boot-image=",
948*795d594fSAndroid Build Coastguard Worker ElementsAre(GetPrebuiltPrimaryBootImageDir() + "/boot.art",
949*795d594fSAndroid Build Coastguard Worker framework_dir_ + "/boot-conscrypt.art"))),
950*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathimagefds:",
951*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.ImagePath()),
952*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.ImagePath()),
953*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.ImagePath()),
954*795d594fSAndroid Build Coastguard Worker "-1"))),
955*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathvdexfds:",
956*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.VdexPath()),
957*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.VdexPath()),
958*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.VdexPath()),
959*795d594fSAndroid Build Coastguard Worker "-1"))),
960*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathoatfds:",
961*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.OatPath()),
962*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.OatPath()),
963*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.OatPath()),
964*795d594fSAndroid Build Coastguard Worker "-1"))))))
965*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size())
966*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
967*795d594fSAndroid Build Coastguard Worker } else {
968*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
969*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
970*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("--boot-image=",
971*795d594fSAndroid Build Coastguard Worker ElementsAre(GetPrebuiltPrimaryBootImageDir() + "/boot.art",
972*795d594fSAndroid Build Coastguard Worker framework_dir_ + "/boot-framework.art",
973*795d594fSAndroid Build Coastguard Worker framework_dir_ + "/boot-conscrypt.art"))),
974*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathimagefds:",
975*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.ImagePath()),
976*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.ImagePath()),
977*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.ImagePath()),
978*795d594fSAndroid Build Coastguard Worker "-1"))),
979*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathvdexfds:",
980*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.VdexPath()),
981*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.VdexPath()),
982*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.VdexPath()),
983*795d594fSAndroid Build Coastguard Worker "-1"))),
984*795d594fSAndroid Build Coastguard Worker Contains(ListFlag("-Xbootclasspathoatfds:",
985*795d594fSAndroid Build Coastguard Worker ElementsAre(FdOf(primary.OatPath()),
986*795d594fSAndroid Build Coastguard Worker FdOf(framework_ext.OatPath()),
987*795d594fSAndroid Build Coastguard Worker FdOf(mainline_ext.OatPath()),
988*795d594fSAndroid Build Coastguard Worker "-1"))))))
989*795d594fSAndroid Build Coastguard Worker .Times(odrefresh_->AllSystemServerJars().size())
990*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
991*795d594fSAndroid Build Coastguard Worker }
992*795d594fSAndroid Build Coastguard Worker
993*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(
994*795d594fSAndroid Build Coastguard Worker odrefresh_->Compile(*metrics_,
995*795d594fSAndroid Build Coastguard Worker CompilationOptions{
996*795d594fSAndroid Build Coastguard Worker .system_server_jars_to_compile = odrefresh_->AllSystemServerJars(),
997*795d594fSAndroid Build Coastguard Worker }),
998*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
999*795d594fSAndroid Build Coastguard Worker }
1000*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,OnlyBootImages)1001*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, OnlyBootImages) {
1002*795d594fSAndroid Build Coastguard Worker config_.SetOnlyBootImages(true);
1003*795d594fSAndroid Build Coastguard Worker
1004*795d594fSAndroid Build Coastguard Worker // Primary.
1005*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_, DoExecAndReturnCode(Contains(Flag("--dex-file=", core_oj_jar_))))
1006*795d594fSAndroid Build Coastguard Worker .Times(2)
1007*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
1008*795d594fSAndroid Build Coastguard Worker
1009*795d594fSAndroid Build Coastguard Worker // Mainline extension.
1010*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_, DoExecAndReturnCode(Contains(Flag("--dex-file=", conscrypt_jar_))))
1011*795d594fSAndroid Build Coastguard Worker .Times(2)
1012*795d594fSAndroid Build Coastguard Worker .WillRepeatedly(Return(0));
1013*795d594fSAndroid Build Coastguard Worker
1014*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(*metrics_, CompilationOptions::CompileAll(*odrefresh_)),
1015*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
1016*795d594fSAndroid Build Coastguard Worker }
1017*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,DirtyImageObjects)1018*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, DirtyImageObjects) {
1019*795d594fSAndroid Build Coastguard Worker // Primary.
1020*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
1021*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
1022*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dirty-image-objects-fd=", FdOf(dirty_image_objects_file_))),
1023*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", core_oj_jar_)))))
1024*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
1025*795d594fSAndroid Build Coastguard Worker
1026*795d594fSAndroid Build Coastguard Worker // Mainline extension.
1027*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
1028*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", conscrypt_jar_)))))
1029*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
1030*795d594fSAndroid Build Coastguard Worker
1031*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
1032*795d594fSAndroid Build Coastguard Worker *metrics_,
1033*795d594fSAndroid Build Coastguard Worker CompilationOptions{
1034*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
1035*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
1036*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
1037*795d594fSAndroid Build Coastguard Worker }),
1038*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
1039*795d594fSAndroid Build Coastguard Worker }
1040*795d594fSAndroid Build Coastguard Worker
TEST_F(OdRefreshTest,DirtyImageObjectsMultipleFiles)1041*795d594fSAndroid Build Coastguard Worker TEST_F(OdRefreshTest, DirtyImageObjectsMultipleFiles) {
1042*795d594fSAndroid Build Coastguard Worker std::string art_dirty_image_objects = art_etc_dir_ + "/dirty-image-objects";
1043*795d594fSAndroid Build Coastguard Worker auto file = ScopedCreateEmptyFile(art_dirty_image_objects);
1044*795d594fSAndroid Build Coastguard Worker
1045*795d594fSAndroid Build Coastguard Worker // Primary.
1046*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
1047*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(
1048*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dirty-image-objects-fd=", FdOf(dirty_image_objects_file_))),
1049*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dirty-image-objects-fd=", FdOf(art_dirty_image_objects))),
1050*795d594fSAndroid Build Coastguard Worker Contains(Flag("--dex-file=", core_oj_jar_)))))
1051*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
1052*795d594fSAndroid Build Coastguard Worker
1053*795d594fSAndroid Build Coastguard Worker // Mainline extension.
1054*795d594fSAndroid Build Coastguard Worker EXPECT_CALL(*mock_exec_utils_,
1055*795d594fSAndroid Build Coastguard Worker DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", conscrypt_jar_)))))
1056*795d594fSAndroid Build Coastguard Worker .WillOnce(Return(0));
1057*795d594fSAndroid Build Coastguard Worker
1058*795d594fSAndroid Build Coastguard Worker EXPECT_EQ(odrefresh_->Compile(
1059*795d594fSAndroid Build Coastguard Worker *metrics_,
1060*795d594fSAndroid Build Coastguard Worker CompilationOptions{
1061*795d594fSAndroid Build Coastguard Worker .boot_images_to_generate_for_isas{
1062*795d594fSAndroid Build Coastguard Worker {InstructionSet::kX86_64,
1063*795d594fSAndroid Build Coastguard Worker {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
1064*795d594fSAndroid Build Coastguard Worker }),
1065*795d594fSAndroid Build Coastguard Worker ExitCode::kCompilationSuccess);
1066*795d594fSAndroid Build Coastguard Worker }
1067*795d594fSAndroid Build Coastguard Worker
1068*795d594fSAndroid Build Coastguard Worker } // namespace odrefresh
1069*795d594fSAndroid Build Coastguard Worker } // namespace art
1070