diff options
author | 2023-09-08 20:52:59 +0100 | |
---|---|---|
committer | 2023-10-10 19:01:06 +0000 | |
commit | cde2f060a732c431308cbdce33ae12cd51679460 (patch) | |
tree | f666db997ecbf3b51db1ee208c3ee4de5bb36760 | |
parent | f1b8f88172bd9862ad1651cc03c456508d3ee937 (diff) |
Eliminate the remaining need for root access in artd_tests.
Bug: 289037540
Test: atest art_standalone_artd_tests
Change-Id: Ie4399e85bcfb3c5d51388a8591c212d8ae9c037d
Merged-In: Ie4399e85bcfb3c5d51388a8591c212d8ae9c037d
-rw-r--r-- | artd/artd_test.cc | 19 | ||||
-rw-r--r-- | artd/path_utils.cc | 9 | ||||
-rw-r--r-- | artd/path_utils.h | 5 |
3 files changed, 14 insertions, 19 deletions
diff --git a/artd/artd_test.cc b/artd/artd_test.cc index a1f5d6453a..4af8f17e5a 100644 --- a/artd/artd_test.cc +++ b/artd/artd_test.cc @@ -120,8 +120,6 @@ using PrimaryCurProfilePath = ProfilePath::PrimaryCurProfilePath; using PrimaryRefProfilePath = ProfilePath::PrimaryRefProfilePath; using TmpProfilePath = ProfilePath::TmpProfilePath; -constexpr uid_t kRootUid = 0; - ScopeGuard<std::function<void()>> ScopedSetLogger(android::base::LogFunction&& logger) { android::base::LogFunction old_logger = android::base::SetLogger(std::move(logger)); return make_scope_guard([old_logger = std::move(old_logger)]() mutable { @@ -328,6 +326,8 @@ class ArtdTest : public CommonArtTest { // Remove the trailing '/'; scratch_path_.resize(scratch_path_.length() - 1); + TestOnlySetListRootDir(scratch_path_); + ON_CALL(mock_fstat_, Call).WillByDefault(fstat); // Use an arbitrary existing directory as ART root. @@ -1972,11 +1972,6 @@ TEST_F(ArtdTest, mergeProfilesWithOptionsDumpClassesAndMethods) { } TEST_F(ArtdTest, cleanup) { - // TODO(b/289037540): Fix this. - if (getuid() != kRootUid) { - GTEST_SKIP() << "This test requires root access"; - } - std::vector<std::string> gc_removed_files; std::vector<std::string> gc_kept_files; @@ -2137,11 +2132,6 @@ TEST_F(ArtdTest, isInDalvikCache) { } TEST_F(ArtdTest, deleteRuntimeArtifacts) { - // TODO(b/289037540): Fix this. - if (getuid() != kRootUid) { - GTEST_SKIP() << "This test requires root access"; - } - std::vector<std::string> removed_files; std::vector<std::string> kept_files; @@ -2188,11 +2178,6 @@ TEST_F(ArtdTest, deleteRuntimeArtifacts) { } TEST_F(ArtdTest, deleteRuntimeArtifactsSpecialChars) { - // TODO(b/289037540): Fix this. - if (getuid() != kRootUid) { - GTEST_SKIP() << "This test requires root access"; - } - std::vector<std::string> removed_files; std::vector<std::string> kept_files; diff --git a/artd/path_utils.cc b/artd/path_utils.cc index 0bf50c3b50..aa5a2b160f 100644 --- a/artd/path_utils.cc +++ b/artd/path_utils.cc @@ -58,6 +58,9 @@ using SecondaryRefProfilePath = ProfilePath::SecondaryRefProfilePath; using TmpProfilePath = ProfilePath::TmpProfilePath; using WritableProfilePath = ProfilePath::WritableProfilePath; +// Only to be changed for testing. +std::string_view gListRootDir = "/"; + Result<void> ValidateAbsoluteNormalPath(const std::string& path_str) { if (path_str.empty()) { return Errorf("Path is empty"); @@ -156,7 +159,7 @@ std::vector<std::string> ListManagedFiles(const std::string& android_data, } } - return tools::Glob(patterns); + return tools::Glob(patterns, gListRootDir); } std::vector<std::string> ListRuntimeArtifactsFiles( @@ -177,7 +180,7 @@ std::vector<std::string> ListRuntimeArtifactsFiles( } } - return tools::Glob(patterns); + return tools::Glob(patterns, gListRootDir); } Result<void> ValidateRuntimeArtifactsPath(const RuntimeArtifactsPath& runtime_artifacts_path) { @@ -336,5 +339,7 @@ Result<std::vector<FstabEntry>> GetProcMountsEntriesForPath(const std::string& p return entries; } +void TestOnlySetListRootDir(std::string_view root_dir) { gListRootDir = root_dir; } + } // namespace artd } // namespace art diff --git a/artd/path_utils.h b/artd/path_utils.h index bb1597d3bf..77aa82ab7f 100644 --- a/artd/path_utils.h +++ b/artd/path_utils.h @@ -107,6 +107,11 @@ bool PathStartsWith(std::string_view path, std::string_view prefix); android::base::Result<std::vector<android::fs_mgr::FstabEntry>> GetProcMountsEntriesForPath( const std::string& path); +// Sets the root dir for `ListManagedFiles` and `ListRuntimeImageFiles`. +// The passed string must be alive until the test ends. +// For testing use only. +void TestOnlySetListRootDir(std::string_view root_dir); + } // namespace artd } // namespace art |