summaryrefslogtreecommitdiff
path: root/runtime/class_loader_context_test.cc
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2022-09-29 15:53:14 +0100
committer Treehugger Robot <treehugger-gerrit@google.com> 2022-09-30 11:15:02 +0000
commit742160318a3de2c10622b97dfe37473ef2b1985b (patch)
treea0499bbf71a7a55447805ff1d4bf193a68005b42 /runtime/class_loader_context_test.cc
parentd46716b7fae296d48dff663ced83889a7e2a9a11 (diff)
Resolve symlinks when checking class loader context.
There is some inconsistency in the build system. When /system_ext is a symlink to /system/system_ext and there is a shared library in /system_ext, the oat file generated by dexpreopt has the dex location starting with /system/system_ext, while the metadata in /system_ext/etc/permissions has the dex location starting with /system_ext. This inconsitency causes the class loader context to fail. This CL works around the inconsistency by resolving symlinks when checking class loader context. Bug: 247914536 Test: m test-art-host-gtest-art_runtime_tests Change-Id: I7a177bda08e179c3d5417108be6411a84fdd5c40
Diffstat (limited to 'runtime/class_loader_context_test.cc')
-rw-r--r--runtime/class_loader_context_test.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc
index 073b4b61e2..fd14476b19 100644
--- a/runtime/class_loader_context_test.cc
+++ b/runtime/class_loader_context_test.cc
@@ -18,6 +18,10 @@
#include <gtest/gtest.h>
+#include <filesystem>
+#include <fstream>
+
+#include "android-base/stringprintf.h"
#include "android-base/strings.h"
#include "art_field-inl.h"
#include "base/dchecked_vector.h"
@@ -42,6 +46,19 @@ namespace art {
class ClassLoaderContextTest : public CommonRuntimeTest {
public:
+ void SetUp() override {
+ CommonRuntimeTest::SetUp();
+ scratch_dir_ = std::make_unique<ScratchDir>();
+ scratch_path_ = scratch_dir_->GetPath();
+ // Remove the trailing '/';
+ scratch_path_.resize(scratch_path_.length() - 1);
+ }
+
+ void TearDown() override {
+ scratch_dir_.reset();
+ CommonRuntimeTest::TearDown();
+ }
+
void VerifyContextSize(ClassLoaderContext* context, size_t expected_size) {
ASSERT_TRUE(context != nullptr);
ASSERT_EQ(expected_size, context->GetParentChainSize());
@@ -340,6 +357,9 @@ class ClassLoaderContextTest : public CommonRuntimeTest {
return true;
}
+ std::unique_ptr<ScratchDir> scratch_dir_;
+ std::string scratch_path_;
+
private:
void VerifyClassLoaderInfo(ClassLoaderContext* context,
size_t index,
@@ -1600,6 +1620,28 @@ TEST_F(ClassLoaderContextTest, VerifyClassLoaderContextMatchWithIMCSL) {
ClassLoaderContext::VerificationResult::kVerifies);
}
+TEST_F(ClassLoaderContextTest, VerifyClassLoaderContextMatchAfterResolvingSymlinks) {
+ {
+ std::ofstream ofs(scratch_path_ + "/foo.jar");
+ ASSERT_TRUE(ofs);
+ }
+ std::filesystem::create_directory_symlink(scratch_path_, scratch_path_ + "/bar");
+
+ std::string context_spec =
+ android::base::StringPrintf("PCL[%s/foo.jar*123:%s/foo.jar!classes2.dex*456]",
+ scratch_path_.c_str(),
+ scratch_path_.c_str());
+ std::unique_ptr<ClassLoaderContext> context = ParseContextWithChecksums(context_spec);
+ PretendContextOpenedDexFilesForChecksums(context.get());
+
+ std::string context_spec_with_symlinks =
+ android::base::StringPrintf("PCL[%s/bar/foo.jar*123:%s/bar/foo.jar!classes2.dex*456]",
+ scratch_path_.c_str(),
+ scratch_path_.c_str());
+ ASSERT_EQ(context->VerifyClassLoaderContextMatch(context_spec_with_symlinks),
+ ClassLoaderContext::VerificationResult::kVerifies);
+}
+
TEST_F(ClassLoaderContextTest, VerifyClassLoaderContextMatchAfterEncoding) {
jobject class_loader_a = LoadDexInPathClassLoader("ForClassLoaderA", nullptr);
jobject class_loader_b = LoadDexInDelegateLastClassLoader("ForClassLoaderB", class_loader_a);