David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 "base/file_utils.h" |
| 18 | |
| 19 | #include <libgen.h> |
| 20 | #include <stdlib.h> |
| 21 | |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 22 | #include <optional> |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 23 | #include <vector> |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 24 | |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 25 | #include "base/stl_util.h" |
David Sehr | 7d43242 | 2018-05-25 10:49:02 -0700 | [diff] [blame] | 26 | #include "common_art_test.h" |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 30 | static constexpr const char kAndroidWifiApexDefaultPath[] = "/apex/com.android.wifi"; |
| 31 | |
David Sehr | 7d43242 | 2018-05-25 10:49:02 -0700 | [diff] [blame] | 32 | class FileUtilsTest : public CommonArtTest {}; |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 33 | |
| 34 | TEST_F(FileUtilsTest, GetDalvikCacheFilename) { |
| 35 | std::string name; |
| 36 | std::string error; |
| 37 | |
| 38 | EXPECT_TRUE(GetDalvikCacheFilename("/system/app/Foo.apk", "/foo", &name, &error)) << error; |
| 39 | EXPECT_EQ("/foo/system@app@Foo.apk@classes.dex", name); |
| 40 | |
| 41 | EXPECT_TRUE(GetDalvikCacheFilename("/data/app/foo-1.apk", "/foo", &name, &error)) << error; |
| 42 | EXPECT_EQ("/foo/data@app@foo-1.apk@classes.dex", name); |
| 43 | |
| 44 | EXPECT_TRUE(GetDalvikCacheFilename("/system/framework/core.jar", "/foo", &name, &error)) << error; |
| 45 | EXPECT_EQ("/foo/system@framework@core.jar@classes.dex", name); |
| 46 | |
| 47 | EXPECT_TRUE(GetDalvikCacheFilename("/system/framework/boot.art", "/foo", &name, &error)) << error; |
| 48 | EXPECT_EQ("/foo/system@framework@boot.art", name); |
| 49 | |
| 50 | EXPECT_TRUE(GetDalvikCacheFilename("/system/framework/boot.oat", "/foo", &name, &error)) << error; |
| 51 | EXPECT_EQ("/foo/system@framework@boot.oat", name); |
| 52 | } |
| 53 | |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 54 | TEST_F(FileUtilsTest, GetSystemImageFilename) { |
| 55 | EXPECT_STREQ("/system/framework/arm/boot.art", |
| 56 | GetSystemImageFilename("/system/framework/boot.art", InstructionSet::kArm).c_str()); |
| 57 | } |
| 58 | |
David Srbecky | 7400a54 | 2020-07-09 13:40:57 +0100 | [diff] [blame] | 59 | // TODO(dsrbecky): b/160885380: This test is failing in eng-prod because libartbase |
| 60 | // is loaded from different path (under testcases). |
| 61 | TEST_F(FileUtilsTest, DISABLED_GetAndroidRootSafe) { |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 62 | std::string error_msg; |
| 63 | |
| 64 | // We don't expect null returns for most cases, so don't check and let std::string crash. |
| 65 | |
David Sehr | 7d43242 | 2018-05-25 10:49:02 -0700 | [diff] [blame] | 66 | // CommonArtTest sets ANDROID_ROOT, so expect this to be the same. |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 67 | std::string android_root = GetAndroidRootSafe(&error_msg); |
| 68 | std::string android_root_env = getenv("ANDROID_ROOT"); |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 69 | EXPECT_EQ(android_root, android_root_env) << error_msg; |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 70 | |
| 71 | // Set ANDROID_ROOT to something else (but the directory must exist). So use dirname. |
Andreas Gampe | dbf5403 | 2018-06-18 14:47:01 -0700 | [diff] [blame] | 72 | UniqueCPtr<char> root_dup(strdup(android_root_env.c_str())); |
| 73 | char* dir = dirname(root_dup.get()); |
Andreas Gampe | 0de385f | 2018-10-11 11:11:13 -0700 | [diff] [blame] | 74 | ASSERT_EQ(0, setenv("ANDROID_ROOT", dir, /* overwrite */ 1)); |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 75 | std::string android_root2 = GetAndroidRootSafe(&error_msg); |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 76 | EXPECT_STREQ(dir, android_root2.c_str()) << error_msg; |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 77 | |
| 78 | // Set a bogus value for ANDROID_ROOT. This should be an error. |
Andreas Gampe | 0de385f | 2018-10-11 11:11:13 -0700 | [diff] [blame] | 79 | ASSERT_EQ(0, setenv("ANDROID_ROOT", "/this/is/obviously/bogus", /* overwrite */ 1)); |
David Sehr | 7d43242 | 2018-05-25 10:49:02 -0700 | [diff] [blame] | 80 | EXPECT_EQ(GetAndroidRootSafe(&error_msg), ""); |
David Srbecky | 7400a54 | 2020-07-09 13:40:57 +0100 | [diff] [blame] | 81 | error_msg = ""; |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 82 | |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 83 | // Inferring the Android Root from the location of libartbase only works on host. |
| 84 | if (!kIsTargetBuild) { |
| 85 | // Unset ANDROID_ROOT and see that it still returns something (as libartbase code is running). |
| 86 | ASSERT_EQ(0, unsetenv("ANDROID_ROOT")); |
| 87 | std::string android_root3 = GetAndroidRootSafe(&error_msg); |
| 88 | // This should be the same as the other root (modulo realpath), otherwise the test setup is |
| 89 | // broken. On non-bionic. On bionic we can be running with a different libartbase that lives |
| 90 | // outside of ANDROID_ROOT. |
| 91 | UniqueCPtr<char> real_root3(realpath(android_root3.c_str(), nullptr)); |
Alex Light | 680cbf2 | 2018-10-31 11:00:19 -0700 | [diff] [blame] | 92 | #if !defined(__BIONIC__ ) || defined(__ANDROID__) |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 93 | UniqueCPtr<char> real_root(realpath(android_root.c_str(), nullptr)); |
| 94 | EXPECT_STREQ(real_root.get(), real_root3.get()) << error_msg; |
Alex Light | 680cbf2 | 2018-10-31 11:00:19 -0700 | [diff] [blame] | 95 | #else |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 96 | EXPECT_STRNE(real_root3.get(), "") << error_msg; |
Alex Light | 680cbf2 | 2018-10-31 11:00:19 -0700 | [diff] [blame] | 97 | #endif |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 98 | } |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 99 | |
| 100 | // Reset ANDROID_ROOT, as other things may depend on it. |
Andreas Gampe | 0de385f | 2018-10-11 11:11:13 -0700 | [diff] [blame] | 101 | ASSERT_EQ(0, setenv("ANDROID_ROOT", android_root_env.c_str(), /* overwrite */ 1)); |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 104 | TEST_F(FileUtilsTest, GetArtRootSafe) { |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 105 | std::string error_msg; |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 106 | std::string android_art_root; |
| 107 | std::string android_art_root_env; |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 108 | |
Victor Chang | 6461124 | 2019-07-05 16:32:41 +0100 | [diff] [blame] | 109 | // TODO(b/130295968): Re-enable this part when the directory exists on host |
| 110 | if (kIsTargetBuild) { |
| 111 | // We don't expect null returns for most cases, so don't check and let std::string crash. |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 112 | |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 113 | // CommonArtTest sets ANDROID_ART_ROOT, so expect this to be the same. |
| 114 | android_art_root = GetArtRootSafe(&error_msg); |
| 115 | android_art_root_env = getenv("ANDROID_ART_ROOT"); |
| 116 | EXPECT_EQ(android_art_root, android_art_root_env) << error_msg; |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 117 | |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 118 | // Set ANDROID_ART_ROOT to something else (but the directory must exist). So use dirname. |
| 119 | UniqueCPtr<char> root_dup(strdup(android_art_root_env.c_str())); |
Victor Chang | 6461124 | 2019-07-05 16:32:41 +0100 | [diff] [blame] | 120 | char* dir = dirname(root_dup.get()); |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 121 | ASSERT_EQ(0, setenv("ANDROID_ART_ROOT", dir, /* overwrite */ 1)); |
| 122 | std::string android_art_root2 = GetArtRootSafe(&error_msg); |
| 123 | EXPECT_STREQ(dir, android_art_root2.c_str()) << error_msg; |
Victor Chang | 6461124 | 2019-07-05 16:32:41 +0100 | [diff] [blame] | 124 | } |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 125 | |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 126 | // Set a bogus value for ANDROID_ART_ROOT. This should be an error. |
| 127 | ASSERT_EQ(0, setenv("ANDROID_ART_ROOT", "/this/is/obviously/bogus", /* overwrite */ 1)); |
| 128 | EXPECT_EQ(GetArtRootSafe(&error_msg), ""); |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 129 | |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 130 | // Inferring the ART root from the location of libartbase only works on target. |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 131 | if (kIsTargetBuild) { |
| 132 | // Disabled for now, as we cannot reliably use `GetRootContainingLibartbase` |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 133 | // to find the ART root on target yet (see comment in `GetArtRootSafe`). |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 134 | // |
| 135 | // TODO(b/129534335): Re-enable this part of the test on target when the |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 136 | // only instance of libartbase is the one from the ART APEX. |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 137 | if ((false)) { |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 138 | // Unset ANDROID_ART_ROOT and see that it still returns something (as |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 139 | // libartbase code is running). |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 140 | ASSERT_EQ(0, unsetenv("ANDROID_ART_ROOT")); |
| 141 | std::string android_art_root3 = GetArtRootSafe(&error_msg); |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 142 | // This should be the same as the other root (modulo realpath), otherwise |
| 143 | // the test setup is broken. On non-bionic. On bionic we can be running |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 144 | // with a different libartbase that lives outside of ANDROID_ART_ROOT. |
| 145 | UniqueCPtr<char> real_root3(realpath(android_art_root3.c_str(), nullptr)); |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 146 | #if !defined(__BIONIC__ ) || defined(__ANDROID__) |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 147 | UniqueCPtr<char> real_root(realpath(android_art_root.c_str(), nullptr)); |
Roland Levillain | 50eec3d | 2019-04-05 18:53:58 +0100 | [diff] [blame] | 148 | EXPECT_STREQ(real_root.get(), real_root3.get()) << error_msg; |
| 149 | #else |
| 150 | EXPECT_STRNE(real_root3.get(), "") << error_msg; |
| 151 | #endif |
| 152 | } |
| 153 | } |
| 154 | |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 155 | // Reset ANDROID_ART_ROOT, as other things may depend on it. |
| 156 | ASSERT_EQ(0, setenv("ANDROID_ART_ROOT", android_art_root_env.c_str(), /* overwrite */ 1)); |
Roland Levillain | 1ea8a62 | 2019-03-29 19:08:56 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Vladimir Marko | 62c2d71 | 2018-03-09 12:54:05 +0000 | [diff] [blame] | 159 | TEST_F(FileUtilsTest, ReplaceFileExtension) { |
| 160 | EXPECT_EQ("/directory/file.vdex", ReplaceFileExtension("/directory/file.oat", "vdex")); |
| 161 | EXPECT_EQ("/.directory/file.vdex", ReplaceFileExtension("/.directory/file.oat", "vdex")); |
| 162 | EXPECT_EQ("/directory/file.vdex", ReplaceFileExtension("/directory/file", "vdex")); |
| 163 | EXPECT_EQ("/.directory/file.vdex", ReplaceFileExtension("/.directory/file", "vdex")); |
| 164 | } |
| 165 | |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 166 | TEST_F(FileUtilsTest, GetApexDataOatFilename) { |
| 167 | ScopedUnsetEnvironmentVariable android_root("ANDROID_ROOT"); |
| 168 | ScopedUnsetEnvironmentVariable i18n_root("ANDROID_I18N_ROOT"); |
| 169 | ScopedUnsetEnvironmentVariable art_apex_data("ART_APEX_DATA"); |
| 170 | |
| 171 | EXPECT_EQ(GetArtApexData() + "/dalvik-cache/arm/boot-beep.oat", |
| 172 | GetApexDataOatFilename("/product/javalib/beep.jar", InstructionSet::kArm)); |
| 173 | |
| 174 | const std::string art_apex_jar = std::string {kAndroidArtApexDefaultPath} + "/javalib/some.jar"; |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 175 | EXPECT_EQ(std::string {}, GetApexDataOatFilename(art_apex_jar.c_str(), InstructionSet::kArm)); |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 176 | |
| 177 | const std::string i18n_jar = |
| 178 | std::string {kAndroidI18nApexDefaultPath} + "/javalib/core-icu4j.jar"; |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 179 | EXPECT_EQ(std::string {}, GetApexDataOatFilename(i18n_jar, InstructionSet::kArm)); |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 180 | |
| 181 | const std::string system_jar_apexdata_oat = GetArtApexData() + "/dalvik-cache/x86/boot-lace.oat"; |
| 182 | EXPECT_EQ(system_jar_apexdata_oat, |
| 183 | GetApexDataOatFilename("/system/framework/lace.jar", InstructionSet::kX86)); |
| 184 | } |
| 185 | |
| 186 | TEST_F(FileUtilsTest, GetApexDataOdexFilename) { |
| 187 | ScopedUnsetEnvironmentVariable android_root("ANDROID_ROOT"); |
| 188 | ScopedUnsetEnvironmentVariable art_apex_data("ART_APEX_DATA"); |
| 189 | |
| 190 | EXPECT_EQ(GetArtApexData() + "/dalvik-cache/arm/data@some@code.odex", |
| 191 | GetApexDataOdexFilename("/data/some/code.dex", InstructionSet::kArm)); |
| 192 | |
| 193 | const std::string art_apex_jar = std::string {kAndroidArtApexDefaultPath} + "/javalib/some.jar"; |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 194 | EXPECT_EQ( |
| 195 | GetArtApexData() + "/dalvik-cache/arm/apex@com.android.art@javalib@some.jar@classes.odex", |
| 196 | GetApexDataOdexFilename(art_apex_jar.c_str(), InstructionSet::kArm)); |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 197 | |
| 198 | const std::string i18n_jar = |
| 199 | std::string {kAndroidI18nApexDefaultPath} + "/javalib/core-icu4j.jar"; |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 200 | EXPECT_EQ(GetArtApexData() + |
| 201 | "/dalvik-cache/arm/apex@com.android.i18n@javalib@core-icu4j.jar@classes.odex", |
| 202 | GetApexDataOdexFilename(i18n_jar.c_str(), InstructionSet::kArm)); |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 203 | |
| 204 | const std::string system_jar_apexdata_odex = |
| 205 | GetArtApexData() + "/dalvik-cache/x86/system@framework@cookie.jar@classes.odex"; |
| 206 | EXPECT_EQ(system_jar_apexdata_odex, |
| 207 | GetApexDataOdexFilename("/system/framework/cookie.jar", InstructionSet::kX86)); |
| 208 | } |
| 209 | |
| 210 | TEST_F(FileUtilsTest, GetApexDataBootImage) { |
| 211 | ScopedUnsetEnvironmentVariable android_root("ANDROID_ROOT"); |
| 212 | ScopedUnsetEnvironmentVariable art_apex_data("ART_APEX_DATA"); |
| 213 | |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 214 | EXPECT_EQ(std::string {}, |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 215 | GetApexDataBootImage(std::string {kAndroidI18nApexDefaultPath} + "/javalib/bar.jar")); |
| 216 | |
| 217 | // Check image location has the prefix "boot-" in front of the basename of dex location and |
| 218 | // that image suffix is .art. |
| 219 | const std::string system_jar = "/system/framework/disk.jar"; |
| 220 | const std::string boot_image = GetApexDataBootImage(system_jar.c_str()); |
| 221 | EXPECT_EQ(GetArtApexData() + "/dalvik-cache/boot-disk.art", boot_image); |
| 222 | |
| 223 | // Check the image filename corresponds to the oat file for the same system jar. |
| 224 | const InstructionSet isa = InstructionSet::kArm64; |
| 225 | const std::string boot_image_filename = GetSystemImageFilename(boot_image.c_str(), isa); |
| 226 | const std::string accompanying_oat_file = ReplaceFileExtension(boot_image_filename, "oat"); |
| 227 | EXPECT_EQ(accompanying_oat_file, GetApexDataOatFilename(system_jar.c_str(), isa)); |
| 228 | } |
| 229 | |
| 230 | TEST_F(FileUtilsTest, GetApexDataImage) { |
| 231 | ScopedUnsetEnvironmentVariable android_root("ANDROID_ROOT"); |
| 232 | ScopedUnsetEnvironmentVariable art_apex_data("ART_APEX_DATA"); |
| 233 | |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 234 | EXPECT_EQ( |
| 235 | GetArtApexData() + "/dalvik-cache/apex@com.android.wifi@lib@javalib@bar.jar@classes.art", |
| 236 | GetApexDataImage(std::string {kAndroidWifiApexDefaultPath} + "/lib/javalib/bar.jar")); |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 237 | |
| 238 | // Check image has basename of dex location with the .art suffix. |
| 239 | const char* jar = "/system/framework/mcguffin/test.jar"; |
| 240 | const std::string image = GetApexDataImage(jar); |
| 241 | EXPECT_EQ(GetArtApexData() + "/dalvik-cache/system@framework@mcguffin@test.jar@classes.art", |
| 242 | image); |
| 243 | |
| 244 | // Check the image filename corresponds to the .odex file for the same system jar. |
| 245 | const InstructionSet isa = InstructionSet::kX86_64; |
| 246 | const std::string image_filename = GetSystemImageFilename(image.c_str(), isa); |
| 247 | const std::string accompanying_odex_file = ReplaceFileExtension(image_filename, "odex"); |
| 248 | EXPECT_EQ(accompanying_odex_file, GetApexDataOdexFilename(jar, isa)); |
| 249 | } |
| 250 | |
| 251 | TEST_F(FileUtilsTest, GetApexDataDalvikCacheFilename) { |
Jiakai Zhang | d61b021 | 2021-07-08 10:20:26 +0800 | [diff] [blame] | 252 | const std::string apex_jar = std::string {kAndroidWifiApexDefaultPath} + "/lib/javalib/bar.jar"; |
| 253 | EXPECT_EQ(GetArtApexData() + |
| 254 | "/dalvik-cache/x86_64/apex@com.android.wifi@lib@javalib@bar.jar@classes.art", |
Orion Hodson | d6e00a7 | 2021-02-10 13:52:40 +0000 | [diff] [blame] | 255 | GetApexDataDalvikCacheFilename(apex_jar, InstructionSet::kX86_64, "art")); |
| 256 | |
| 257 | // Check dalvik-cache filename follows convention. |
| 258 | const std::string non_apex_jar = "/vendor/javalib/test.jar"; |
| 259 | const std::string art_filename = |
| 260 | GetApexDataDalvikCacheFilename(non_apex_jar, InstructionSet::kArm, "art"); |
| 261 | CHECK_EQ(GetArtApexData() + "/dalvik-cache/arm/vendor@javalib@test.jar@classes.art", |
| 262 | art_filename); |
| 263 | |
| 264 | // Check ".art", ".odex" and ".vdex" filenames are the same with the appropriate extensions |
| 265 | // substituted. |
| 266 | const std::string odex_filename = |
| 267 | GetApexDataDalvikCacheFilename(non_apex_jar, InstructionSet::kArm, "odex"); |
| 268 | CHECK_EQ(odex_filename, ReplaceFileExtension(art_filename, "odex")); |
| 269 | const std::string vdex_filename = |
| 270 | GetApexDataDalvikCacheFilename(non_apex_jar, InstructionSet::kArm, "vdex"); |
| 271 | CHECK_EQ(vdex_filename, ReplaceFileExtension(art_filename, "vdex")); |
| 272 | } |
| 273 | |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 274 | } // namespace art |