blob: ce984f9a63414cf06589261575a8847aac211bbb [file] [log] [blame]
Richard Uhler84f50ae2017-02-06 15:12:45 +00001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
Vladimir Markofdd46842020-03-25 14:57:17 +000019#include "android-base/logging.h"
Andreas Gampe178c8802017-11-07 12:23:07 -080020#include "android-base/stringprintf.h"
Vladimir Markod8302632019-11-14 13:16:16 +000021#include "android-base/strings.h"
Jiakai Zhangfb8cdb52021-12-06 18:51:28 +000022#include "base/globals.h"
Vladimir Marko3f795d22019-05-14 13:49:35 +010023#include "base/stl_util.h"
Vladimir Markod8302632019-11-14 13:16:16 +000024#include "class_linker.h"
Vladimir Markofdd46842020-03-25 14:57:17 +000025#include "dex/utf.h"
Jiakai Zhangfb8cdb52021-12-06 18:51:28 +000026#include "dexopt_test.h"
Vladimir Marko4e7b3c72021-02-23 18:13:47 +000027#include "intern_table-inl.h"
Andreas Gampe178c8802017-11-07 12:23:07 -080028#include "noop_compiler_callbacks.h"
Vladimir Markofdd46842020-03-25 14:57:17 +000029#include "oat_file.h"
Richard Uhler84f50ae2017-02-06 15:12:45 +000030
31namespace art {
32namespace gc {
33namespace space {
34
Vladimir Markofdd46842020-03-25 14:57:17 +000035class ImageSpaceTest : public CommonRuntimeTest {
36 protected:
37 void SetUpRuntimeOptions(RuntimeOptions* options) override {
Vladimir Markofdd46842020-03-25 14:57:17 +000038 // Disable relocation.
39 options->emplace_back("-Xnorelocate", nullptr);
40 }
41
42 std::string GetFilenameBase(const std::string& full_path) {
43 size_t slash_pos = full_path.rfind('/');
44 CHECK_NE(std::string::npos, slash_pos);
45 size_t dot_pos = full_path.rfind('.');
46 CHECK_NE(std::string::npos, dot_pos);
47 CHECK_GT(dot_pos, slash_pos + 1u);
48 return full_path.substr(slash_pos + 1u, dot_pos - (slash_pos + 1u));
49 }
50};
51
52TEST_F(ImageSpaceTest, StringDeduplication) {
53 const char* const kBaseNames[] = { "Extension1", "Extension2" };
54
55 ScratchDir scratch;
56 const std::string& scratch_dir = scratch.GetPath();
57 std::string image_dir = scratch_dir + GetInstructionSetString(kRuntimeISA);
58 int mkdir_result = mkdir(image_dir.c_str(), 0700);
59 ASSERT_EQ(0, mkdir_result);
60
Victor Changd20e51d2020-05-05 16:01:19 +010061 // Prepare boot class path variables, exclude core-icu4j and conscrypt
62 // which are not in the primary boot image.
Vladimir Markofdd46842020-03-25 14:57:17 +000063 std::vector<std::string> bcp = GetLibCoreDexFileNames();
64 std::vector<std::string> bcp_locations = GetLibCoreDexLocations();
65 CHECK_EQ(bcp.size(), bcp_locations.size());
66 ASSERT_NE(std::string::npos, bcp.back().find("conscrypt"));
67 bcp.pop_back();
68 bcp_locations.pop_back();
Victor Changd20e51d2020-05-05 16:01:19 +010069 ASSERT_NE(std::string::npos, bcp.back().find("core-icu4j"));
70 bcp.pop_back();
71 bcp_locations.pop_back();
Vladimir Markofdd46842020-03-25 14:57:17 +000072 std::string base_bcp_string = android::base::Join(bcp, ':');
73 std::string base_bcp_locations_string = android::base::Join(bcp_locations, ':');
74 std::string base_image_location = GetImageLocation();
75
76 // Compile the two extensions independently.
77 std::vector<std::string> extension_image_locations;
78 for (const char* base_name : kBaseNames) {
79 std::string jar_name = GetTestDexFileName(base_name);
80 ArrayRef<const std::string> dex_files(&jar_name, /*size=*/ 1u);
81 ScratchFile profile_file;
Vladimir Markoa2209802021-04-23 13:28:29 +000082 GenerateBootProfile(dex_files, profile_file.GetFile());
Vladimir Markofdd46842020-03-25 14:57:17 +000083 std::vector<std::string> extra_args = {
84 "--profile-file=" + profile_file.GetFilename(),
85 "--runtime-arg",
86 "-Xbootclasspath:" + base_bcp_string + ':' + jar_name,
87 "--runtime-arg",
88 "-Xbootclasspath-locations:" + base_bcp_locations_string + ':' + jar_name,
89 "--boot-image=" + base_image_location,
90 };
91 std::string prefix = GetFilenameBase(base_image_location);
92 std::string error_msg;
93 bool success = CompileBootImage(extra_args, image_dir + '/' + prefix, dex_files, &error_msg);
94 ASSERT_TRUE(success) << error_msg;
95 bcp.push_back(jar_name);
96 bcp_locations.push_back(jar_name);
97 extension_image_locations.push_back(
98 scratch_dir + prefix + '-' + GetFilenameBase(jar_name) + ".art");
99 }
100
101 // Also compile the second extension as an app with app image.
102 const char* app_base_name = kBaseNames[std::size(kBaseNames) - 1u];
103 std::string app_jar_name = GetTestDexFileName(app_base_name);
104 std::string app_odex_name = scratch_dir + app_base_name + ".odex";
105 std::string app_image_name = scratch_dir + app_base_name + ".art";
106 {
107 ArrayRef<const std::string> dex_files(&app_jar_name, /*size=*/ 1u);
108 ScratchFile profile_file;
109 GenerateProfile(dex_files, profile_file.GetFile());
110 std::vector<std::string> argv;
111 std::string error_msg;
112 bool success = StartDex2OatCommandLine(&argv, &error_msg, /*use_runtime_bcp_and_image=*/ false);
113 ASSERT_TRUE(success) << error_msg;
114 argv.insert(argv.end(), {
115 "--profile-file=" + profile_file.GetFilename(),
116 "--runtime-arg",
117 "-Xbootclasspath:" + base_bcp_string,
118 "--runtime-arg",
119 "-Xbootclasspath-locations:" + base_bcp_locations_string,
120 "--boot-image=" + base_image_location,
121 "--dex-file=" + app_jar_name,
122 "--dex-location=" + app_jar_name,
123 "--oat-file=" + app_odex_name,
124 "--app-image-file=" + app_image_name,
125 "--initialize-app-image-classes=true",
126 });
127 success = RunDex2Oat(argv, &error_msg);
128 ASSERT_TRUE(success) << error_msg;
129 }
130
Victor Hsieh61ffd042021-05-20 15:14:25 -0700131 std::vector<std::string> full_image_locations;
Vladimir Markofdd46842020-03-25 14:57:17 +0000132 std::vector<std::unique_ptr<gc::space::ImageSpace>> boot_image_spaces;
133 MemMap extra_reservation;
134 auto load_boot_image = [&]() REQUIRES_SHARED(Locks::mutator_lock_) {
135 boot_image_spaces.clear();
136 extra_reservation = MemMap::Invalid();
137 return ImageSpace::LoadBootImage(bcp,
138 bcp_locations,
Victor Hsieha09d8b72021-05-24 14:21:55 -0700139 /*boot_class_path_fds=*/ std::vector<int>(),
Victor Hsiehce9b9022021-07-21 10:44:06 -0700140 /*boot_class_path_image_fds=*/ std::vector<int>(),
141 /*boot_class_path_vdex_fds=*/ std::vector<int>(),
142 /*boot_class_path_oat_fds=*/ std::vector<int>(),
Vladimir Markofdd46842020-03-25 14:57:17 +0000143 full_image_locations,
144 kRuntimeISA,
Vladimir Markofdd46842020-03-25 14:57:17 +0000145 /*relocate=*/ false,
146 /*executable=*/ true,
Vladimir Markofdd46842020-03-25 14:57:17 +0000147 /*extra_reservation_size=*/ 0u,
148 &boot_image_spaces,
149 &extra_reservation);
150 };
151
152 const char test_string[] = "SharedBootImageExtensionTestString";
153 size_t test_string_length = std::size(test_string) - 1u; // Equals UTF-16 length.
154 uint32_t hash = ComputeUtf16HashFromModifiedUtf8(test_string, test_string_length);
155 InternTable::Utf8String utf8_test_string(test_string_length, test_string, hash);
156 auto contains_test_string = [utf8_test_string](ImageSpace* space)
157 REQUIRES_SHARED(Locks::mutator_lock_) {
158 const ImageHeader& image_header = space->GetImageHeader();
159 if (image_header.GetInternedStringsSection().Size() != 0u) {
160 const uint8_t* data = space->Begin() + image_header.GetInternedStringsSection().Offset();
161 size_t read_count;
162 InternTable::UnorderedSet temp_set(data, /*make_copy_of_data=*/ false, &read_count);
163 return temp_set.find(utf8_test_string) != temp_set.end();
164 } else {
165 return false;
166 }
167 };
168
169 // Load extensions and test for the presence of the test string.
170 ScopedObjectAccess soa(Thread::Current());
171 ASSERT_EQ(2u, extension_image_locations.size());
Victor Hsieh61ffd042021-05-20 15:14:25 -0700172 full_image_locations = {
173 base_image_location, extension_image_locations[0], extension_image_locations[1]
174 };
Vladimir Markofdd46842020-03-25 14:57:17 +0000175 bool success = load_boot_image();
176 ASSERT_TRUE(success);
177 ASSERT_EQ(bcp.size(), boot_image_spaces.size());
178 EXPECT_TRUE(contains_test_string(boot_image_spaces[boot_image_spaces.size() - 2u].get()));
179 // The string in the second extension should be replaced and removed from interned string section.
180 EXPECT_FALSE(contains_test_string(boot_image_spaces[boot_image_spaces.size() - 1u].get()));
181
182 // Reload extensions in reverse order and test for the presence of the test string.
183 std::swap(bcp[bcp.size() - 2u], bcp[bcp.size() - 1u]);
184 std::swap(bcp_locations[bcp_locations.size() - 2u], bcp_locations[bcp_locations.size() - 1u]);
Victor Hsieh61ffd042021-05-20 15:14:25 -0700185 full_image_locations = {
186 base_image_location, extension_image_locations[1], extension_image_locations[0]
187 };
Vladimir Markofdd46842020-03-25 14:57:17 +0000188 success = load_boot_image();
189 ASSERT_TRUE(success);
190 ASSERT_EQ(bcp.size(), boot_image_spaces.size());
191 EXPECT_TRUE(contains_test_string(boot_image_spaces[boot_image_spaces.size() - 2u].get()));
192 // The string in the second extension should be replaced and removed from interned string section.
193 EXPECT_FALSE(contains_test_string(boot_image_spaces[boot_image_spaces.size() - 1u].get()));
194
195 // Reload the image without the second extension.
196 bcp.erase(bcp.end() - 2u);
197 bcp_locations.erase(bcp_locations.end() - 2u);
Victor Hsieh61ffd042021-05-20 15:14:25 -0700198 full_image_locations = {base_image_location, extension_image_locations[0]};
Vladimir Markofdd46842020-03-25 14:57:17 +0000199 success = load_boot_image();
200 ASSERT_TRUE(success);
201 ASSERT_EQ(bcp.size(), boot_image_spaces.size());
202 ASSERT_TRUE(contains_test_string(boot_image_spaces[boot_image_spaces.size() - 1u].get()));
203
204 // Load the app odex file and app image.
205 std::string error_msg;
206 std::unique_ptr<OatFile> odex_file(OatFile::Open(/*zip_fd=*/ -1,
207 app_odex_name.c_str(),
208 app_odex_name.c_str(),
209 /*executable=*/ false,
210 /*low_4gb=*/ false,
211 app_jar_name,
212 &error_msg));
213 ASSERT_TRUE(odex_file != nullptr) << error_msg;
214 std::vector<ImageSpace*> non_owning_boot_image_spaces =
215 MakeNonOwningPointerVector(boot_image_spaces);
216 std::unique_ptr<ImageSpace> app_image_space = ImageSpace::CreateFromAppImage(
217 app_image_name.c_str(),
218 odex_file.get(),
219 ArrayRef<ImageSpace* const>(non_owning_boot_image_spaces),
220 &error_msg);
221 ASSERT_TRUE(app_image_space != nullptr) << error_msg;
222
223 // The string in the app image should be replaced and removed from interned string section.
224 EXPECT_FALSE(contains_test_string(app_image_space.get()));
225}
226
Richard Uhler84f50ae2017-02-06 15:12:45 +0000227TEST_F(DexoptTest, ValidateOatFile) {
228 std::string dex1 = GetScratchDir() + "/Dex1.jar";
229 std::string multidex1 = GetScratchDir() + "/MultiDex1.jar";
230 std::string dex2 = GetScratchDir() + "/Dex2.jar";
231 std::string oat_location = GetScratchDir() + "/Oat.oat";
232
233 Copy(GetDexSrc1(), dex1);
234 Copy(GetMultiDexSrc1(), multidex1);
235 Copy(GetDexSrc2(), dex2);
236
237 std::string error_msg;
238 std::vector<std::string> args;
239 args.push_back("--dex-file=" + dex1);
240 args.push_back("--dex-file=" + multidex1);
241 args.push_back("--dex-file=" + dex2);
242 args.push_back("--oat-file=" + oat_location);
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +0000243 ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg;
Richard Uhler84f50ae2017-02-06 15:12:45 +0000244
Vladimir Markof4efa9e2018-10-17 14:12:45 +0100245 std::unique_ptr<OatFile> oat(OatFile::Open(/*zip_fd=*/ -1,
Nicolas Geoffray30025092018-04-19 14:43:29 +0100246 oat_location.c_str(),
Richard Uhler84f50ae2017-02-06 15:12:45 +0000247 oat_location.c_str(),
Vladimir Markof4efa9e2018-10-17 14:12:45 +0100248 /*executable=*/ false,
249 /*low_4gb=*/ false,
Richard Uhler84f50ae2017-02-06 15:12:45 +0000250 &error_msg));
251 ASSERT_TRUE(oat != nullptr) << error_msg;
252
Vladimir Markob7bf8432019-12-03 13:18:50 +0000253 {
254 // Test opening the oat file also with explicit dex filenames.
255 std::vector<std::string> dex_filenames{ dex1, multidex1, dex2 };
256 std::unique_ptr<OatFile> oat2(OatFile::Open(/*zip_fd=*/ -1,
257 oat_location.c_str(),
258 oat_location.c_str(),
259 /*executable=*/ false,
260 /*low_4gb=*/ false,
261 ArrayRef<const std::string>(dex_filenames),
Victor Hsiehf667c332021-05-27 11:35:44 -0700262 /*dex_fds=*/ ArrayRef<const int>(),
Vladimir Markob7bf8432019-12-03 13:18:50 +0000263 /*reservation=*/ nullptr,
264 &error_msg));
265 ASSERT_TRUE(oat2 != nullptr) << error_msg;
266 }
267
Richard Uhler84f50ae2017-02-06 15:12:45 +0000268 // Originally all the dex checksums should be up to date.
269 EXPECT_TRUE(ImageSpace::ValidateOatFile(*oat, &error_msg)) << error_msg;
270
271 // Invalidate the dex1 checksum.
272 Copy(GetDexSrc2(), dex1);
273 EXPECT_FALSE(ImageSpace::ValidateOatFile(*oat, &error_msg));
274
275 // Restore the dex1 checksum.
276 Copy(GetDexSrc1(), dex1);
277 EXPECT_TRUE(ImageSpace::ValidateOatFile(*oat, &error_msg)) << error_msg;
278
279 // Invalidate the non-main multidex checksum.
280 Copy(GetMultiDexSrc2(), multidex1);
281 EXPECT_FALSE(ImageSpace::ValidateOatFile(*oat, &error_msg));
282
283 // Restore the multidex checksum.
284 Copy(GetMultiDexSrc1(), multidex1);
285 EXPECT_TRUE(ImageSpace::ValidateOatFile(*oat, &error_msg)) << error_msg;
286
287 // Invalidate the dex2 checksum.
288 Copy(GetDexSrc1(), dex2);
289 EXPECT_FALSE(ImageSpace::ValidateOatFile(*oat, &error_msg));
290
291 // restore the dex2 checksum.
292 Copy(GetDexSrc2(), dex2);
293 EXPECT_TRUE(ImageSpace::ValidateOatFile(*oat, &error_msg)) << error_msg;
294
295 // Replace the multidex file with a non-multidex file.
296 Copy(GetDexSrc1(), multidex1);
297 EXPECT_FALSE(ImageSpace::ValidateOatFile(*oat, &error_msg));
298
299 // Restore the multidex file
300 Copy(GetMultiDexSrc1(), multidex1);
301 EXPECT_TRUE(ImageSpace::ValidateOatFile(*oat, &error_msg)) << error_msg;
302
303 // Replace dex1 with a multidex file.
304 Copy(GetMultiDexSrc1(), dex1);
305 EXPECT_FALSE(ImageSpace::ValidateOatFile(*oat, &error_msg));
306
307 // Restore the dex1 file.
308 Copy(GetDexSrc1(), dex1);
309 EXPECT_TRUE(ImageSpace::ValidateOatFile(*oat, &error_msg)) << error_msg;
310
311 // Remove the dex2 file.
312 EXPECT_EQ(0, unlink(dex2.c_str()));
313 EXPECT_FALSE(ImageSpace::ValidateOatFile(*oat, &error_msg));
314
315 // Restore the dex2 file.
316 Copy(GetDexSrc2(), dex2);
317 EXPECT_TRUE(ImageSpace::ValidateOatFile(*oat, &error_msg)) << error_msg;
318
319 // Remove the multidex file.
320 EXPECT_EQ(0, unlink(multidex1.c_str()));
321 EXPECT_FALSE(ImageSpace::ValidateOatFile(*oat, &error_msg));
322}
323
Vladimir Markod8302632019-11-14 13:16:16 +0000324TEST_F(DexoptTest, Checksums) {
325 Runtime* runtime = Runtime::Current();
326 ASSERT_TRUE(runtime != nullptr);
327 ASSERT_FALSE(runtime->GetHeap()->GetBootImageSpaces().empty());
328
329 std::vector<std::string> bcp = runtime->GetBootClassPath();
330 std::vector<std::string> bcp_locations = runtime->GetBootClassPathLocations();
331 std::vector<const DexFile*> dex_files = runtime->GetClassLinker()->GetBootClassPath();
332
333 std::string error_msg;
334 auto create_and_verify = [&]() {
335 std::string checksums = gc::space::ImageSpace::GetBootClassPathChecksums(
336 ArrayRef<gc::space::ImageSpace* const>(runtime->GetHeap()->GetBootImageSpaces()),
337 ArrayRef<const DexFile* const>(dex_files));
338 return gc::space::ImageSpace::VerifyBootClassPathChecksums(
339 checksums,
340 android::base::Join(bcp_locations, ':'),
Victor Hsieh61ffd042021-05-20 15:14:25 -0700341 ArrayRef<const std::string>(runtime->GetImageLocations()),
Vladimir Markod8302632019-11-14 13:16:16 +0000342 ArrayRef<const std::string>(bcp_locations),
343 ArrayRef<const std::string>(bcp),
Victor Hsieha09d8b72021-05-24 14:21:55 -0700344 /*boot_class_path_fds=*/ ArrayRef<const int>(),
Vladimir Markod8302632019-11-14 13:16:16 +0000345 kRuntimeISA,
Vladimir Markod8302632019-11-14 13:16:16 +0000346 &error_msg);
347 };
348
349 ASSERT_TRUE(create_and_verify()) << error_msg;
350
351 std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
352 for (const std::string& src : { GetDexSrc1(), GetDexSrc2() }) {
353 std::vector<std::unique_ptr<const DexFile>> new_dex_files;
354 const ArtDexFileLoader dex_file_loader;
355 ASSERT_TRUE(dex_file_loader.Open(src.c_str(),
356 src,
357 /*verify=*/ true,
358 /*verify_checksum=*/ false,
359 &error_msg,
360 &new_dex_files))
361 << error_msg;
362
363 bcp.push_back(src);
364 bcp_locations.push_back(src);
365 for (std::unique_ptr<const DexFile>& df : new_dex_files) {
366 dex_files.push_back(df.get());
367 opened_dex_files.push_back(std::move(df));
368 }
369
370 ASSERT_TRUE(create_and_verify()) << error_msg;
371 }
372}
373
Jiakai Zhangfb8cdb52021-12-06 18:51:28 +0000374template <bool kImage, bool kRelocate, bool kProfile>
Andreas Gampe178c8802017-11-07 12:23:07 -0800375class ImageSpaceLoadingTest : public CommonRuntimeTest {
376 protected:
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100377 void SetUpRuntimeOptions(RuntimeOptions* options) override {
Vladimir Markoa8f39182019-11-21 10:08:58 +0000378 std::string image_location = GetCoreArtLocation();
379 if (!kImage) {
380 missing_image_base_ = std::make_unique<ScratchFile>();
381 image_location = missing_image_base_->GetFilename() + ".art";
Andreas Gampe178c8802017-11-07 12:23:07 -0800382 }
Jiakai Zhangfb8cdb52021-12-06 18:51:28 +0000383 // Compiling the primary boot image into a single image is not allowed on host.
384 if (kProfile && kIsTargetBuild) {
385 std::vector<std::string> dex_files(GetLibCoreDexFileNames());
386 profile1_ = std::make_unique<ScratchFile>();
387 GenerateBootProfile(ArrayRef<const std::string>(dex_files),
388 profile1_->GetFile(),
389 /*method_frequency=*/6,
390 /*type_frequency=*/6);
391 profile2_ = std::make_unique<ScratchFile>();
392 GenerateBootProfile(ArrayRef<const std::string>(dex_files),
393 profile2_->GetFile(),
394 /*method_frequency=*/8,
395 /*type_frequency=*/8);
396 image_location += "!" + profile1_->GetFilename() + "!" + profile2_->GetFilename();
397 }
Vladimir Markoa8f39182019-11-21 10:08:58 +0000398 options->emplace_back(android::base::StringPrintf("-Ximage:%s", image_location.c_str()),
399 nullptr);
Andreas Gampe178c8802017-11-07 12:23:07 -0800400 options->emplace_back(kRelocate ? "-Xrelocate" : "-Xnorelocate", nullptr);
Andreas Gampe178c8802017-11-07 12:23:07 -0800401
402 // We want to test the relocation behavior of ImageSpace. As such, don't pretend we're a
403 // compiler.
404 callbacks_.reset();
Vladimir Marko3f795d22019-05-14 13:49:35 +0100405
406 // Clear DEX2OATBOOTCLASSPATH environment variable used for boot image compilation.
407 // We don't want that environment variable to affect the behavior of this test.
408 CHECK(old_dex2oat_bcp_ == nullptr);
409 const char* old_dex2oat_bcp = getenv("DEX2OATBOOTCLASSPATH");
410 if (old_dex2oat_bcp != nullptr) {
411 old_dex2oat_bcp_.reset(strdup(old_dex2oat_bcp));
412 CHECK(old_dex2oat_bcp_ != nullptr);
413 unsetenv("DEX2OATBOOTCLASSPATH");
414 }
Andreas Gampe178c8802017-11-07 12:23:07 -0800415 }
Vladimir Marko3f795d22019-05-14 13:49:35 +0100416
417 void TearDown() override {
418 if (old_dex2oat_bcp_ != nullptr) {
419 int result = setenv("DEX2OATBOOTCLASSPATH", old_dex2oat_bcp_.get(), /* replace */ 0);
420 CHECK_EQ(result, 0);
421 old_dex2oat_bcp_.reset();
422 }
Vladimir Markoa8f39182019-11-21 10:08:58 +0000423 missing_image_base_.reset();
Vladimir Marko3f795d22019-05-14 13:49:35 +0100424 }
425
426 private:
Vladimir Markoa8f39182019-11-21 10:08:58 +0000427 std::unique_ptr<ScratchFile> missing_image_base_;
Jiakai Zhangfb8cdb52021-12-06 18:51:28 +0000428 std::unique_ptr<ScratchFile> profile1_;
429 std::unique_ptr<ScratchFile> profile2_;
Vladimir Marko3f795d22019-05-14 13:49:35 +0100430 UniqueCPtr<const char[]> old_dex2oat_bcp_;
Andreas Gampe178c8802017-11-07 12:23:07 -0800431};
432
Jiakai Zhangfb8cdb52021-12-06 18:51:28 +0000433using ImageSpaceNoDex2oatTest =
434 ImageSpaceLoadingTest</*kImage=*/true, /*kRelocate=*/true, /*kProfile=*/false>;
Vladimir Marko4df2d802018-09-27 16:42:44 +0000435TEST_F(ImageSpaceNoDex2oatTest, Test) {
Andreas Gampe178c8802017-11-07 12:23:07 -0800436 EXPECT_FALSE(Runtime::Current()->GetHeap()->GetBootImageSpaces().empty());
437}
438
Jiakai Zhangfb8cdb52021-12-06 18:51:28 +0000439using ImageSpaceNoRelocateNoDex2oatTest =
440 ImageSpaceLoadingTest</*kImage=*/true, /*kRelocate=*/false, /*kProfile=*/false>;
Vladimir Marko4df2d802018-09-27 16:42:44 +0000441TEST_F(ImageSpaceNoRelocateNoDex2oatTest, Test) {
442 EXPECT_FALSE(Runtime::Current()->GetHeap()->GetBootImageSpaces().empty());
443}
444
Jiakai Zhangfb8cdb52021-12-06 18:51:28 +0000445using ImageSpaceNoImageNoProfileTest =
446 ImageSpaceLoadingTest</*kImage=*/false, /*kRelocate=*/true, /*kProfile=*/false>;
447TEST_F(ImageSpaceNoImageNoProfileTest, Test) {
448 // Imageless mode.
449 EXPECT_TRUE(Runtime::Current()->GetHeap()->GetBootImageSpaces().empty());
450}
451
452using ImageSpaceNoImageTest =
453 ImageSpaceLoadingTest</*kImage=*/false, /*kRelocate=*/true, /*kProfile=*/true>;
454TEST_F(ImageSpaceNoImageTest, Test) {
455 // Compiling the primary boot image into a single image is not allowed on host.
456 TEST_DISABLED_FOR_HOST();
457
458 const std::vector<ImageSpace*>& image_spaces =
459 Runtime::Current()->GetHeap()->GetBootImageSpaces();
460 ASSERT_FALSE(image_spaces.empty());
461
462 const OatFile* oat_file = image_spaces[0]->GetOatFile();
463 ASSERT_TRUE(oat_file != nullptr);
464
465 // Compiled by JIT Zygote.
466 EXPECT_EQ(oat_file->GetCompilerFilter(), CompilerFilter::Filter::kVerify);
467}
468
Richard Uhler84f50ae2017-02-06 15:12:45 +0000469} // namespace space
470} // namespace gc
471} // namespace art