xref: /aosp_15_r20/art/artd/path_utils_test.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2022 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 "path_utils.h"
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker #include "aidl/com/android/server/art/BnArtd.h"
20*795d594fSAndroid Build Coastguard Worker #include "android-base/result-gmock.h"
21*795d594fSAndroid Build Coastguard Worker #include "base/common_art_test.h"
22*795d594fSAndroid Build Coastguard Worker #include "gmock/gmock.h"
23*795d594fSAndroid Build Coastguard Worker #include "gtest/gtest.h"
24*795d594fSAndroid Build Coastguard Worker 
25*795d594fSAndroid Build Coastguard Worker namespace art {
26*795d594fSAndroid Build Coastguard Worker namespace artd {
27*795d594fSAndroid Build Coastguard Worker namespace {
28*795d594fSAndroid Build Coastguard Worker 
29*795d594fSAndroid Build Coastguard Worker using ::aidl::com::android::server::art::ArtifactsPath;
30*795d594fSAndroid Build Coastguard Worker using ::aidl::com::android::server::art::DexMetadataPath;
31*795d594fSAndroid Build Coastguard Worker using ::aidl::com::android::server::art::ProfilePath;
32*795d594fSAndroid Build Coastguard Worker using ::android::base::testing::HasError;
33*795d594fSAndroid Build Coastguard Worker using ::android::base::testing::HasValue;
34*795d594fSAndroid Build Coastguard Worker using ::android::base::testing::WithMessage;
35*795d594fSAndroid Build Coastguard Worker using ::testing::AllOf;
36*795d594fSAndroid Build Coastguard Worker using ::testing::Field;
37*795d594fSAndroid Build Coastguard Worker 
38*795d594fSAndroid Build Coastguard Worker using PrebuiltProfilePath = ProfilePath::PrebuiltProfilePath;
39*795d594fSAndroid Build Coastguard Worker using PrimaryCurProfilePath = ProfilePath::PrimaryCurProfilePath;
40*795d594fSAndroid Build Coastguard Worker using PrimaryRefProfilePath = ProfilePath::PrimaryRefProfilePath;
41*795d594fSAndroid Build Coastguard Worker using SecondaryCurProfilePath = ProfilePath::SecondaryCurProfilePath;
42*795d594fSAndroid Build Coastguard Worker using SecondaryRefProfilePath = ProfilePath::SecondaryRefProfilePath;
43*795d594fSAndroid Build Coastguard Worker using TmpProfilePath = ProfilePath::TmpProfilePath;
44*795d594fSAndroid Build Coastguard Worker 
45*795d594fSAndroid Build Coastguard Worker using std::literals::operator""s;  // NOLINT
46*795d594fSAndroid Build Coastguard Worker 
47*795d594fSAndroid Build Coastguard Worker class PathUtilsTest : public CommonArtTest {};
48*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildArtBinPath)49*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildArtBinPath) {
50*795d594fSAndroid Build Coastguard Worker   auto scratch_dir = std::make_unique<ScratchDir>();
51*795d594fSAndroid Build Coastguard Worker   auto art_root_env = ScopedUnsetEnvironmentVariable("ANDROID_ART_ROOT");
52*795d594fSAndroid Build Coastguard Worker   setenv("ANDROID_ART_ROOT", scratch_dir->GetPath().c_str(), /*overwrite=*/1);
53*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildArtBinPath("foo"), HasValue(scratch_dir->GetPath() + "/bin/foo"));
54*795d594fSAndroid Build Coastguard Worker }
55*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildArtifactsPath)56*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildArtifactsPath) {
57*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
58*795d594fSAndroid Build Coastguard Worker       BuildArtifactsPath(ArtifactsPath{
59*795d594fSAndroid Build Coastguard Worker           .dexPath = "/a/b.apk", .isa = "arm64", .isInDalvikCache = false, .isPreReboot = false}),
60*795d594fSAndroid Build Coastguard Worker       HasValue(AllOf(Field(&RawArtifactsPath::oat_path, "/a/oat/arm64/b.odex"),
61*795d594fSAndroid Build Coastguard Worker                      Field(&RawArtifactsPath::vdex_path, "/a/oat/arm64/b.vdex"),
62*795d594fSAndroid Build Coastguard Worker                      Field(&RawArtifactsPath::art_path, "/a/oat/arm64/b.art"))));
63*795d594fSAndroid Build Coastguard Worker }
64*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildArtifactsPathPreReboot)65*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildArtifactsPathPreReboot) {
66*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
67*795d594fSAndroid Build Coastguard Worker       BuildArtifactsPath(ArtifactsPath{
68*795d594fSAndroid Build Coastguard Worker           .dexPath = "/a/b.apk", .isa = "arm64", .isInDalvikCache = false, .isPreReboot = true}),
69*795d594fSAndroid Build Coastguard Worker       HasValue(AllOf(Field(&RawArtifactsPath::oat_path, "/a/oat/arm64/b.odex.staged"),
70*795d594fSAndroid Build Coastguard Worker                      Field(&RawArtifactsPath::vdex_path, "/a/oat/arm64/b.vdex.staged"),
71*795d594fSAndroid Build Coastguard Worker                      Field(&RawArtifactsPath::art_path, "/a/oat/arm64/b.art.staged"))));
72*795d594fSAndroid Build Coastguard Worker }
73*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildArtifactsPathDalvikCache)74*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildArtifactsPathDalvikCache) {
75*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
76*795d594fSAndroid Build Coastguard Worker       BuildArtifactsPath(ArtifactsPath{
77*795d594fSAndroid Build Coastguard Worker           .dexPath = "/a/b.apk", .isa = "arm64", .isInDalvikCache = true, .isPreReboot = false}),
78*795d594fSAndroid Build Coastguard Worker       HasValue(AllOf(Field(&RawArtifactsPath::oat_path,
79*795d594fSAndroid Build Coastguard Worker                            android_data_ + "/dalvik-cache/arm64/[email protected]@classes.dex"),
80*795d594fSAndroid Build Coastguard Worker                      Field(&RawArtifactsPath::vdex_path,
81*795d594fSAndroid Build Coastguard Worker                            android_data_ + "/dalvik-cache/arm64/[email protected]@classes.vdex"),
82*795d594fSAndroid Build Coastguard Worker                      Field(&RawArtifactsPath::art_path,
83*795d594fSAndroid Build Coastguard Worker                            android_data_ + "/dalvik-cache/arm64/[email protected]@classes.art"))));
84*795d594fSAndroid Build Coastguard Worker }
85*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildArtifactsPathDalvikCachePreReboot)86*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildArtifactsPathDalvikCachePreReboot) {
87*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
88*795d594fSAndroid Build Coastguard Worker       BuildArtifactsPath(ArtifactsPath{
89*795d594fSAndroid Build Coastguard Worker           .dexPath = "/a/b.apk", .isa = "arm64", .isInDalvikCache = true, .isPreReboot = true}),
90*795d594fSAndroid Build Coastguard Worker       HasValue(AllOf(Field(&RawArtifactsPath::oat_path,
91*795d594fSAndroid Build Coastguard Worker                            android_data_ + "/dalvik-cache/arm64/[email protected]@classes.dex.staged"),
92*795d594fSAndroid Build Coastguard Worker                      Field(&RawArtifactsPath::vdex_path,
93*795d594fSAndroid Build Coastguard Worker                            android_data_ + "/dalvik-cache/arm64/[email protected]@classes.vdex.staged"),
94*795d594fSAndroid Build Coastguard Worker                      Field(&RawArtifactsPath::art_path,
95*795d594fSAndroid Build Coastguard Worker                            android_data_ + "/dalvik-cache/arm64/[email protected]@classes.art.staged"))));
96*795d594fSAndroid Build Coastguard Worker }
97*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildOatPathInvalidDexPath)98*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildOatPathInvalidDexPath) {
99*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
100*795d594fSAndroid Build Coastguard Worker       BuildArtifactsPath(ArtifactsPath{
101*795d594fSAndroid Build Coastguard Worker           .dexPath = "a/b.apk", .isa = "arm64", .isInDalvikCache = false, .isPreReboot = false}),
102*795d594fSAndroid Build Coastguard Worker       HasError(WithMessage("Path 'a/b.apk' is not an absolute path")));
103*795d594fSAndroid Build Coastguard Worker }
104*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildOatPathInvalidIsa)105*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildOatPathInvalidIsa) {
106*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
107*795d594fSAndroid Build Coastguard Worker       BuildArtifactsPath(ArtifactsPath{
108*795d594fSAndroid Build Coastguard Worker           .dexPath = "/a/b.apk", .isa = "invalid", .isInDalvikCache = false, .isPreReboot = false}),
109*795d594fSAndroid Build Coastguard Worker       HasError(WithMessage("Instruction set 'invalid' is invalid")));
110*795d594fSAndroid Build Coastguard Worker }
111*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildPrimaryRefProfilePath)112*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildPrimaryRefProfilePath) {
113*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
114*795d594fSAndroid Build Coastguard Worker       BuildPrimaryRefProfilePath(PrimaryRefProfilePath{
115*795d594fSAndroid Build Coastguard Worker           .packageName = "com.android.foo", .profileName = "primary", .isPreReboot = false}),
116*795d594fSAndroid Build Coastguard Worker       HasValue(android_data_ + "/misc/profiles/ref/com.android.foo/primary.prof"));
117*795d594fSAndroid Build Coastguard Worker }
118*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildPrimaryRefProfilePathPreReboot)119*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildPrimaryRefProfilePathPreReboot) {
120*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildPrimaryRefProfilePath(PrimaryRefProfilePath{
121*795d594fSAndroid Build Coastguard Worker                   .packageName = "com.android.foo", .profileName = "primary", .isPreReboot = true}),
122*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/misc/profiles/ref/com.android.foo/primary.prof.staged"));
123*795d594fSAndroid Build Coastguard Worker }
124*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildPrimaryRefProfilePathPackageNameOk)125*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildPrimaryRefProfilePathPackageNameOk) {
126*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildPrimaryRefProfilePath(PrimaryRefProfilePath{
127*795d594fSAndroid Build Coastguard Worker                   .packageName = "...", .profileName = "primary", .isPreReboot = false}),
128*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/misc/profiles/ref/.../primary.prof"));
129*795d594fSAndroid Build Coastguard Worker }
130*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildPrimaryRefProfilePathPackageNameWrong)131*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildPrimaryRefProfilePathPackageNameWrong) {
132*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildPrimaryRefProfilePath(PrimaryRefProfilePath{
133*795d594fSAndroid Build Coastguard Worker                   .packageName = "..", .profileName = "primary", .isPreReboot = false}),
134*795d594fSAndroid Build Coastguard Worker               HasError(WithMessage("Invalid packageName '..'")));
135*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildPrimaryRefProfilePath(PrimaryRefProfilePath{
136*795d594fSAndroid Build Coastguard Worker                   .packageName = "a/b", .profileName = "primary", .isPreReboot = false}),
137*795d594fSAndroid Build Coastguard Worker               HasError(WithMessage("packageName 'a/b' has invalid character '/'")));
138*795d594fSAndroid Build Coastguard Worker }
139*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildPrimaryRefProfilePathProfileNameOk)140*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildPrimaryRefProfilePathProfileNameOk) {
141*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildPrimaryRefProfilePath(PrimaryRefProfilePath{
142*795d594fSAndroid Build Coastguard Worker                   .packageName = "com.android.foo", .profileName = "..", .isPreReboot = false}),
143*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/misc/profiles/ref/com.android.foo/...prof"));
144*795d594fSAndroid Build Coastguard Worker }
145*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildPrimaryRefProfilePathProfileNameWrong)146*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildPrimaryRefProfilePathProfileNameWrong) {
147*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildPrimaryRefProfilePath(PrimaryRefProfilePath{
148*795d594fSAndroid Build Coastguard Worker                   .packageName = "com.android.foo", .profileName = "a/b", .isPreReboot = false}),
149*795d594fSAndroid Build Coastguard Worker               HasError(WithMessage("profileName 'a/b' has invalid character '/'")));
150*795d594fSAndroid Build Coastguard Worker }
151*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildFinalProfilePathForPrimary)152*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildFinalProfilePathForPrimary) {
153*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildFinalProfilePath(TmpProfilePath{
154*795d594fSAndroid Build Coastguard Worker                   .finalPath = PrimaryRefProfilePath{.packageName = "com.android.foo",
155*795d594fSAndroid Build Coastguard Worker                                                      .profileName = "primary",
156*795d594fSAndroid Build Coastguard Worker                                                      .isPreReboot = false},
157*795d594fSAndroid Build Coastguard Worker                   .id = "12345"}),
158*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/misc/profiles/ref/com.android.foo/primary.prof"));
159*795d594fSAndroid Build Coastguard Worker }
160*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildFinalProfilePathForSecondary)161*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildFinalProfilePathForSecondary) {
162*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildFinalProfilePath(TmpProfilePath{
163*795d594fSAndroid Build Coastguard Worker                   .finalPath = SecondaryRefProfilePath{.dexPath = android_data_ +
164*795d594fSAndroid Build Coastguard Worker                                                                   "/user/0/com.android.foo/a.apk",
165*795d594fSAndroid Build Coastguard Worker                                                        .isPreReboot = false},
166*795d594fSAndroid Build Coastguard Worker                   .id = "12345"}),
167*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/user/0/com.android.foo/oat/a.apk.prof"));
168*795d594fSAndroid Build Coastguard Worker }
169*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildTmpProfilePathForPrimary)170*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildTmpProfilePathForPrimary) {
171*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
172*795d594fSAndroid Build Coastguard Worker       BuildTmpProfilePath(TmpProfilePath{
173*795d594fSAndroid Build Coastguard Worker           .finalPath =
174*795d594fSAndroid Build Coastguard Worker               PrimaryRefProfilePath{
175*795d594fSAndroid Build Coastguard Worker                   .packageName = "com.android.foo", .profileName = "primary", .isPreReboot = false},
176*795d594fSAndroid Build Coastguard Worker           .id = "12345"}),
177*795d594fSAndroid Build Coastguard Worker       HasValue(android_data_ + "/misc/profiles/ref/com.android.foo/primary.prof.12345.tmp"));
178*795d594fSAndroid Build Coastguard Worker }
179*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildTmpProfilePathForSecondary)180*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildTmpProfilePathForSecondary) {
181*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildTmpProfilePath(TmpProfilePath{
182*795d594fSAndroid Build Coastguard Worker                   .finalPath = SecondaryRefProfilePath{.dexPath = android_data_ +
183*795d594fSAndroid Build Coastguard Worker                                                                   "/user/0/com.android.foo/a.apk",
184*795d594fSAndroid Build Coastguard Worker                                                        .isPreReboot = false},
185*795d594fSAndroid Build Coastguard Worker                   .id = "12345"}),
186*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/user/0/com.android.foo/oat/a.apk.prof.12345.tmp"));
187*795d594fSAndroid Build Coastguard Worker }
188*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildTmpProfilePathIdWrong)189*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildTmpProfilePathIdWrong) {
190*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildTmpProfilePath(TmpProfilePath{
191*795d594fSAndroid Build Coastguard Worker                   .finalPath = PrimaryRefProfilePath{.packageName = "com.android.foo",
192*795d594fSAndroid Build Coastguard Worker                                                      .profileName = "primary",
193*795d594fSAndroid Build Coastguard Worker                                                      .isPreReboot = false},
194*795d594fSAndroid Build Coastguard Worker                   .id = "123/45"}),
195*795d594fSAndroid Build Coastguard Worker               HasError(WithMessage("id '123/45' has invalid character '/'")));
196*795d594fSAndroid Build Coastguard Worker }
197*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildPrebuiltProfilePath)198*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildPrebuiltProfilePath) {
199*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildPrebuiltProfilePath(PrebuiltProfilePath{.dexPath = "/a/b.apk"}),
200*795d594fSAndroid Build Coastguard Worker               HasValue("/a/b.apk.prof"));
201*795d594fSAndroid Build Coastguard Worker }
202*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildPrimaryCurProfilePath)203*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildPrimaryCurProfilePath) {
204*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildPrimaryCurProfilePath(PrimaryCurProfilePath{
205*795d594fSAndroid Build Coastguard Worker                   .userId = 1, .packageName = "com.android.foo", .profileName = "primary"}),
206*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/misc/profiles/cur/1/com.android.foo/primary.prof"));
207*795d594fSAndroid Build Coastguard Worker }
208*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildSecondaryRefProfilePath)209*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildSecondaryRefProfilePath) {
210*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
211*795d594fSAndroid Build Coastguard Worker       BuildSecondaryRefProfilePath(SecondaryRefProfilePath{
212*795d594fSAndroid Build Coastguard Worker           .dexPath = android_data_ + "/user/0/com.android.foo/a.apk", .isPreReboot = false}),
213*795d594fSAndroid Build Coastguard Worker       HasValue(android_data_ + "/user/0/com.android.foo/oat/a.apk.prof"));
214*795d594fSAndroid Build Coastguard Worker }
215*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildSecondaryRefProfilePathPreReboot)216*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildSecondaryRefProfilePathPreReboot) {
217*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildSecondaryRefProfilePath(SecondaryRefProfilePath{
218*795d594fSAndroid Build Coastguard Worker                   .dexPath = android_data_ + "/user/0/com.android.foo/a.apk", .isPreReboot = true}),
219*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/user/0/com.android.foo/oat/a.apk.prof.staged"));
220*795d594fSAndroid Build Coastguard Worker }
221*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildSecondaryCurProfilePath)222*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildSecondaryCurProfilePath) {
223*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildSecondaryCurProfilePath(SecondaryCurProfilePath{
224*795d594fSAndroid Build Coastguard Worker                   .dexPath = android_data_ + "/user/0/com.android.foo/a.apk"}),
225*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/user/0/com.android.foo/oat/a.apk.cur.prof"));
226*795d594fSAndroid Build Coastguard Worker }
227*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildDexMetadataPath)228*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildDexMetadataPath) {
229*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildDexMetadataPath(DexMetadataPath{.dexPath = "/a/b.apk"}), HasValue("/a/b.dm"));
230*795d594fSAndroid Build Coastguard Worker }
231*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildProfilePath)232*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildProfilePath) {
233*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
234*795d594fSAndroid Build Coastguard Worker       BuildProfileOrDmPath(PrimaryRefProfilePath{
235*795d594fSAndroid Build Coastguard Worker           .packageName = "com.android.foo", .profileName = "primary", .isPreReboot = false}),
236*795d594fSAndroid Build Coastguard Worker       HasValue(android_data_ + "/misc/profiles/ref/com.android.foo/primary.prof"));
237*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
238*795d594fSAndroid Build Coastguard Worker       BuildProfileOrDmPath(TmpProfilePath{
239*795d594fSAndroid Build Coastguard Worker           .finalPath =
240*795d594fSAndroid Build Coastguard Worker               PrimaryRefProfilePath{
241*795d594fSAndroid Build Coastguard Worker                   .packageName = "com.android.foo", .profileName = "primary", .isPreReboot = false},
242*795d594fSAndroid Build Coastguard Worker           .id = "12345"}),
243*795d594fSAndroid Build Coastguard Worker       HasValue(android_data_ + "/misc/profiles/ref/com.android.foo/primary.prof.12345.tmp"));
244*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildProfileOrDmPath(PrebuiltProfilePath{.dexPath = "/a/b.apk"}),
245*795d594fSAndroid Build Coastguard Worker               HasValue("/a/b.apk.prof"));
246*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildProfileOrDmPath(PrimaryCurProfilePath{
247*795d594fSAndroid Build Coastguard Worker                   .userId = 1, .packageName = "com.android.foo", .profileName = "primary"}),
248*795d594fSAndroid Build Coastguard Worker               HasValue(android_data_ + "/misc/profiles/cur/1/com.android.foo/primary.prof"));
249*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(BuildProfileOrDmPath(DexMetadataPath{.dexPath = "/a/b.apk"}), HasValue("/a/b.dm"));
250*795d594fSAndroid Build Coastguard Worker }
251*795d594fSAndroid Build Coastguard Worker 
TEST_F(PathUtilsTest,BuildVdexPath)252*795d594fSAndroid Build Coastguard Worker TEST_F(PathUtilsTest, BuildVdexPath) {
253*795d594fSAndroid Build Coastguard Worker   EXPECT_THAT(
254*795d594fSAndroid Build Coastguard Worker       BuildVdexPath(ArtifactsPath{.dexPath = "/a/b.apk", .isa = "arm64", .isInDalvikCache = false}),
255*795d594fSAndroid Build Coastguard Worker       HasValue("/a/oat/arm64/b.vdex"));
256*795d594fSAndroid Build Coastguard Worker }
257*795d594fSAndroid Build Coastguard Worker 
258*795d594fSAndroid Build Coastguard Worker }  // namespace
259*795d594fSAndroid Build Coastguard Worker }  // namespace artd
260*795d594fSAndroid Build Coastguard Worker }  // namespace art
261