blob: b47f2a7e3e546101f8a7de0e7a29db083a2d3899 [file] [log] [blame]
Orion Hodson4c3ade62021-02-10 14:07:10 +00001/*
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
25namespace art {
26namespace odrefresh {
27
Victor Hsiehfb007612021-12-01 16:51:20 -080028static constexpr const char* kOdrefreshArtifactDirectory = "/test/dir";
29
Jiakai Zhang884e22f2021-12-23 20:04:46 +000030TEST(OdrArtifactsTest, ForBootImage) {
Orion Hodson4c3ade62021-02-10 14:07:10 +000031 ScopedUnsetEnvironmentVariable no_env("ART_APEX_DATA");
Victor Hsiehfb007612021-12-01 16:51:20 -080032 setenv("ART_APEX_DATA", kOdrefreshArtifactDirectory, /* overwrite */ 1);
Orion Hodson4c3ade62021-02-10 14:07:10 +000033
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 Zhang884e22f2021-12-23 20:04:46 +000040 const auto artifacts = OdrArtifacts::ForBootImage(image_filename);
Victor Hsiehfb007612021-12-01 16:51:20 -080041 CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.art",
Orion Hodson4c3ade62021-02-10 14:07:10 +000042 artifacts.ImagePath());
Victor Hsiehfb007612021-12-01 16:51:20 -080043 CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.oat",
Orion Hodson4c3ade62021-02-10 14:07:10 +000044 artifacts.OatPath());
Victor Hsiehfb007612021-12-01 16:51:20 -080045 CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.vdex",
Orion Hodson4c3ade62021-02-10 14:07:10 +000046 artifacts.VdexPath());
47}
48
49TEST(OdrArtifactsTest, ForSystemServer) {
50 ScopedUnsetEnvironmentVariable no_env("ART_APEX_DATA");
Victor Hsiehfb007612021-12-01 16:51:20 -080051 setenv("ART_APEX_DATA", kOdrefreshArtifactDirectory, /* overwrite */ 1);
Orion Hodson4c3ade62021-02-10 14:07:10 +000052
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 Hsiehfb007612021-12-01 16:51:20 -080060 std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.art",
Orion Hodson4c3ade62021-02-10 14:07:10 +000061 artifacts.ImagePath());
62 CHECK_EQ(
Victor Hsiehfb007612021-12-01 16:51:20 -080063 std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.odex",
Orion Hodson4c3ade62021-02-10 14:07:10 +000064 artifacts.OatPath());
65 CHECK_EQ(
Victor Hsiehfb007612021-12-01 16:51:20 -080066 std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.vdex",
Orion Hodson4c3ade62021-02-10 14:07:10 +000067 artifacts.VdexPath());
68}
69
70} // namespace odrefresh
71} // namespace art