Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "odr_artifacts.h" |
| 18 | |
| 19 | #include "arch/instruction_set.h" |
| 20 | #include "base/common_art_test.h" |
| 21 | #include "base/file_utils.h" |
| 22 | #include "base/string_view_cpp20.h" |
| 23 | #include "odrefresh/odrefresh.h" |
| 24 | |
| 25 | namespace art { |
| 26 | namespace odrefresh { |
| 27 | |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 28 | static constexpr const char* kOdrefreshArtifactDirectory = "/test/dir"; |
| 29 | |
Jiakai Zhang | 884e22f | 2021-12-23 20:04:46 +0000 | [diff] [blame] | 30 | TEST(OdrArtifactsTest, ForBootImage) { |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 31 | ScopedUnsetEnvironmentVariable no_env("ART_APEX_DATA"); |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 32 | setenv("ART_APEX_DATA", kOdrefreshArtifactDirectory, /* overwrite */ 1); |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 33 | |
| 34 | const std::string image_location = GetApexDataBootImage("/system/framework/framework.jar"); |
| 35 | EXPECT_TRUE(StartsWith(image_location, GetArtApexData())); |
| 36 | |
| 37 | const std::string image_filename = |
| 38 | GetSystemImageFilename(image_location.c_str(), InstructionSet::kArm64); |
| 39 | |
Jiakai Zhang | 884e22f | 2021-12-23 20:04:46 +0000 | [diff] [blame] | 40 | const auto artifacts = OdrArtifacts::ForBootImage(image_filename); |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 41 | CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.art", |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 42 | artifacts.ImagePath()); |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 43 | CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.oat", |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 44 | artifacts.OatPath()); |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 45 | CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.vdex", |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 46 | artifacts.VdexPath()); |
| 47 | } |
| 48 | |
| 49 | TEST(OdrArtifactsTest, ForSystemServer) { |
| 50 | ScopedUnsetEnvironmentVariable no_env("ART_APEX_DATA"); |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 51 | setenv("ART_APEX_DATA", kOdrefreshArtifactDirectory, /* overwrite */ 1); |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 52 | |
| 53 | const std::string image_location = GetApexDataImage("/system/framework/services.jar"); |
| 54 | EXPECT_TRUE(StartsWith(image_location, GetArtApexData())); |
| 55 | |
| 56 | const std::string image_filename = |
| 57 | GetSystemImageFilename(image_location.c_str(), InstructionSet::kX86); |
| 58 | const auto artifacts = OdrArtifacts::ForSystemServer(image_filename); |
| 59 | CHECK_EQ( |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 60 | std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.art", |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 61 | artifacts.ImagePath()); |
| 62 | CHECK_EQ( |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 63 | std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.odex", |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 64 | artifacts.OatPath()); |
| 65 | CHECK_EQ( |
Victor Hsieh | fb00761 | 2021-12-01 16:51:20 -0800 | [diff] [blame] | 66 | std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.vdex", |
Orion Hodson | 4c3ade6 | 2021-02-10 14:07:10 +0000 | [diff] [blame] | 67 | artifacts.VdexPath()); |
| 68 | } |
| 69 | |
| 70 | } // namespace odrefresh |
| 71 | } // namespace art |