summaryrefslogtreecommitdiff
path: root/artd/path_utils_test.cc
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2022-08-10 15:35:28 +0100
committer TreeHugger Robot <treehugger-gerrit@google.com> 2022-08-31 16:55:25 +0000
commit3aaecf0e678a241a25ac358dbf280a35a5c48efc (patch)
tree1e85d793126b9863c9428511620967a46d46b932 /artd/path_utils_test.cc
parent0332ab40ba7e71dbf0a759a96017a96991d0ac19 (diff)
ART services: optimize package - Add artd methods.
This change adds two artd methods: `getDexoptNeeded` and `dexopt`, which are used for app compilation. Also, this CL replaces all `StringPrintf` with `_format`. Bug: 229268202 Test: m test-art-host-gtest-art_artd_tests Ignore-AOSP-First: ART Services. Change-Id: I51a42816750ff39c768658f739c7e6337cfe3e1c
Diffstat (limited to 'artd/path_utils_test.cc')
-rw-r--r--artd/path_utils_test.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/artd/path_utils_test.cc b/artd/path_utils_test.cc
index 9ce40c5d41..4162da33f6 100644
--- a/artd/path_utils_test.cc
+++ b/artd/path_utils_test.cc
@@ -26,12 +26,23 @@ namespace artd {
namespace {
using ::aidl::com::android::server::art::ArtifactsPath;
+using ::aidl::com::android::server::art::DexMetadataPath;
+using ::aidl::com::android::server::art::VdexPath;
using ::android::base::testing::HasError;
using ::android::base::testing::HasValue;
using ::android::base::testing::WithMessage;
+using std::literals::operator""s; // NOLINT
+
class PathUtilsTest : public CommonArtTest {};
+TEST_F(PathUtilsTest, BuildArtBinPath) {
+ auto scratch_dir = std::make_unique<ScratchDir>();
+ auto art_root_env = ScopedUnsetEnvironmentVariable("ANDROID_ART_ROOT");
+ setenv("ANDROID_ART_ROOT", scratch_dir->GetPath().c_str(), /*overwrite=*/1);
+ EXPECT_THAT(BuildArtBinPath("foo"), HasValue(scratch_dir->GetPath() + "/bin/foo"));
+}
+
TEST_F(PathUtilsTest, BuildOatPath) {
EXPECT_THAT(
BuildOatPath(ArtifactsPath{.dexPath = "/a/b.apk", .isa = "arm64", .isInDalvikCache = false}),
@@ -61,6 +72,12 @@ TEST_F(PathUtilsTest, BuildOatPathNonNormalDexPath) {
HasError(WithMessage("Path '/a/c/../b.apk' is not in normal form")));
}
+TEST_F(PathUtilsTest, BuildOatPathNul) {
+ EXPECT_THAT(BuildOatPath(ArtifactsPath{
+ .dexPath = "/a/\0/b.apk"s, .isa = "arm64", .isInDalvikCache = false}),
+ HasError(WithMessage("Path '/a/\0/b.apk' has invalid character '\\0'"s)));
+}
+
TEST_F(PathUtilsTest, BuildOatPathInvalidDexExtension) {
EXPECT_THAT(BuildOatPath(ArtifactsPath{
.dexPath = "/a/b.invalid", .isa = "arm64", .isInDalvikCache = false}),
@@ -81,6 +98,21 @@ TEST_F(PathUtilsTest, OatPathToArtPath) {
EXPECT_EQ(OatPathToArtPath("/a/oat/arm64/b.odex"), "/a/oat/arm64/b.art");
}
+TEST_F(PathUtilsTest, BuildDexMetadataPath) {
+ EXPECT_THAT(BuildDexMetadataPath(DexMetadataPath{.dexPath = "/a/b.apk"}), HasValue("/a/b.dm"));
+}
+
+TEST_F(PathUtilsTest, BuildDexMetadataPathForVdex) {
+ EXPECT_THAT(BuildDexMetadataPath(VdexPath(DexMetadataPath{.dexPath = "/a/b.apk"})),
+ HasValue("/a/b.dm"));
+}
+
+TEST_F(PathUtilsTest, BuildVdexPath) {
+ EXPECT_THAT(
+ BuildVdexPath(ArtifactsPath{.dexPath = "/a/b.apk", .isa = "arm64", .isInDalvikCache = false}),
+ HasValue("/a/oat/arm64/b.vdex"));
+}
+
} // namespace
} // namespace artd
} // namespace art