diff options
author | 2022-12-06 10:35:29 +0000 | |
---|---|---|
committer | 2022-12-22 23:39:06 +0000 | |
commit | d46824b955bc8e01346d225fb28ef4e0ab78e7da (patch) | |
tree | 7a8bfa77fc1e22827e4bfb46889e47f06a789881 /artd/artd_test.cc | |
parent | 20a8542b513ae1909ff7e6648153ec262ecdc5fb (diff) |
Implement shell command "dump-profiles".
This change does not add any new API because the functionality is only
used by the shell command.
This change also changes the behavior of "snapshot-app-profile" and
"snapshot-boot-image-profile" to pave the way to eventually take over
the legacy PM shell commands.
Bug: 261564086
Test: `adb shell pm art dump-profiles` with a package that has multiple
splits.
Test: `adb shell pm art snapshot-app-profile` with a package that has
multiple splits.
Ignore-AOSP-First: ART Services.
Change-Id: I67435d0ba63a655e58fe1186bddea3b16e2fa23a
Diffstat (limited to 'artd/artd_test.cc')
-rw-r--r-- | artd/artd_test.cc | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/artd/artd_test.cc b/artd/artd_test.cc index e28342b2da..8eab8add1f 100644 --- a/artd/artd_test.cc +++ b/artd/artd_test.cc @@ -1614,7 +1614,7 @@ TEST_F(ArtdTest, mergeProfilesProfilesDontExist) { EXPECT_THAT(output_profile.profilePath.tmpPath, IsEmpty()); } -TEST_F(ArtdTest, mergeProfilesWithOptions) { +TEST_F(ArtdTest, mergeProfilesWithOptionsForceMerge) { PrimaryCurProfilePath profile_0_path{ .userId = 0, .packageName = "com.android.foo", .profileName = "primary"}; std::string profile_0_file = OR_FATAL(BuildPrimaryCurProfilePath(profile_0_path)); @@ -1649,6 +1649,82 @@ TEST_F(ArtdTest, mergeProfilesWithOptions) { EXPECT_THAT(output_profile.profilePath.tmpPath, Not(IsEmpty())); } +TEST_F(ArtdTest, mergeProfilesWithOptionsDumpOnly) { + PrimaryCurProfilePath profile_0_path{ + .userId = 0, .packageName = "com.android.foo", .profileName = "primary"}; + std::string profile_0_file = OR_FATAL(BuildPrimaryCurProfilePath(profile_0_path)); + CreateFile(profile_0_file, "def"); + + OutputProfile output_profile{.profilePath = profile_path_->get<ProfilePath::tmpProfilePath>(), + .fsPermission = FsPermission{.uid = -1, .gid = -1}}; + output_profile.profilePath.id = ""; + output_profile.profilePath.tmpPath = ""; + + CreateFile(dex_file_); + + EXPECT_CALL(*mock_exec_utils_, + DoExecAndReturnCode( + WhenSplitBy("--", + _, + AllOf(Contains("--dump-only"), + Not(Contains(Flag("--reference-profile-file-fd=", _))))), + _, + _)) + .WillOnce(DoAll(WithArg<0>(WriteToFdFlag("--dump-output-to-fd=", "dump")), + Return(ProfmanResult::kSuccess))); + + bool result; + EXPECT_TRUE(artd_ + ->mergeProfiles({profile_0_path}, + std::nullopt, + &output_profile, + {dex_file_}, + {.dumpOnly = true}, + &result) + .isOk()); + EXPECT_TRUE(result); + EXPECT_THAT(output_profile.profilePath.id, Not(IsEmpty())); + CheckContent(output_profile.profilePath.tmpPath, "dump"); +} + +TEST_F(ArtdTest, mergeProfilesWithOptionsDumpClassesAndMethods) { + PrimaryCurProfilePath profile_0_path{ + .userId = 0, .packageName = "com.android.foo", .profileName = "primary"}; + std::string profile_0_file = OR_FATAL(BuildPrimaryCurProfilePath(profile_0_path)); + CreateFile(profile_0_file, "def"); + + OutputProfile output_profile{.profilePath = profile_path_->get<ProfilePath::tmpProfilePath>(), + .fsPermission = FsPermission{.uid = -1, .gid = -1}}; + output_profile.profilePath.id = ""; + output_profile.profilePath.tmpPath = ""; + + CreateFile(dex_file_); + + EXPECT_CALL(*mock_exec_utils_, + DoExecAndReturnCode( + WhenSplitBy("--", + _, + AllOf(Contains("--dump-classes-and-methods"), + Not(Contains(Flag("--reference-profile-file-fd=", _))))), + _, + _)) + .WillOnce(DoAll(WithArg<0>(WriteToFdFlag("--dump-output-to-fd=", "dump")), + Return(ProfmanResult::kSuccess))); + + bool result; + EXPECT_TRUE(artd_ + ->mergeProfiles({profile_0_path}, + std::nullopt, + &output_profile, + {dex_file_}, + {.dumpClassesAndMethods = true}, + &result) + .isOk()); + EXPECT_TRUE(result); + EXPECT_THAT(output_profile.profilePath.id, Not(IsEmpty())); + CheckContent(output_profile.profilePath.tmpPath, "dump"); +} + } // namespace } // namespace artd } // namespace art |