• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "odrefresh/odrefresh.h"
23 
24 namespace art {
25 namespace odrefresh {
26 
27 static constexpr const char* kOdrefreshArtifactDirectory = "/test/dir";
28 
TEST(OdrArtifactsTest,ForBootImage)29 TEST(OdrArtifactsTest, ForBootImage) {
30   ScopedUnsetEnvironmentVariable no_env("ART_APEX_DATA");
31   setenv("ART_APEX_DATA", kOdrefreshArtifactDirectory, /* overwrite */ 1);
32 
33   const std::string image_location = GetApexDataBootImage("/system/framework/framework.jar");
34   EXPECT_TRUE(image_location.starts_with(GetArtApexData()));
35 
36   const std::string image_filename =
37       GetSystemImageFilename(image_location.c_str(), InstructionSet::kArm64);
38 
39   const auto artifacts = OdrArtifacts::ForBootImage(image_filename);
40   CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.art",
41            artifacts.ImagePath());
42   CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.oat",
43            artifacts.OatPath());
44   CHECK_EQ(std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/arm64/boot-framework.vdex",
45            artifacts.VdexPath());
46 }
47 
TEST(OdrArtifactsTest,ForSystemServer)48 TEST(OdrArtifactsTest, ForSystemServer) {
49   ScopedUnsetEnvironmentVariable no_env("ART_APEX_DATA");
50   setenv("ART_APEX_DATA", kOdrefreshArtifactDirectory, /* overwrite */ 1);
51 
52   const std::string image_location = GetApexDataImage("/system/framework/services.jar");
53   EXPECT_TRUE(image_location.starts_with(GetArtApexData()));
54 
55   const std::string image_filename =
56       GetSystemImageFilename(image_location.c_str(), InstructionSet::kX86);
57   const auto artifacts = OdrArtifacts::ForSystemServer(image_filename);
58   CHECK_EQ(
59       std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.art",
60       artifacts.ImagePath());
61   CHECK_EQ(
62       std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.odex",
63       artifacts.OatPath());
64   CHECK_EQ(
65       std::string(kOdrefreshArtifactDirectory) + "/dalvik-cache/x86/system@framework@services.jar@classes.vdex",
66       artifacts.VdexPath());
67 }
68 
69 }  // namespace odrefresh
70 }  // namespace art
71