summaryrefslogtreecommitdiffstats
path: root/runtime/class_loader_context_test.cc
diff options
context:
space:
mode:
authorCalin Juravle <calin@google.com>2017-09-06 02:22:57 +0000
committerCalin Juravle <calin@google.com>2017-11-13 15:54:36 -0800
commit92003fe2d5f9031f56c8b0407d8d934023fb4cb2 (patch)
tree42c0d7a799d8fe9b4e95607d4d72df9d79ea45e6 /runtime/class_loader_context_test.cc
parent099f8d6955700913af2610793928ae3e29f3002d (diff)
downloadart-92003fe2d5f9031f56c8b0407d8d934023fb4cb2.tar.gz
art-92003fe2d5f9031f56c8b0407d8d934023fb4cb2.tar.bz2
art-92003fe2d5f9031f56c8b0407d8d934023fb4cb2.zip
Revert "Use real locations when opening dex files from the context"
This reverts commit 821a2595e2438554424879d6cb3594810ca8e636. Reason for revert: Oat file assistant logic was updated to not use realpaths anymore. So this is no longer needed. Test: m test-art-host-gtest Change-Id: Ia63a50f60b82ec3e20606d0be852607c9d2eb26e
Diffstat (limited to 'runtime/class_loader_context_test.cc')
-rw-r--r--runtime/class_loader_context_test.cc70
1 files changed, 20 insertions, 50 deletions
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc
index be6acde4a9..fc3446c3f9 100644
--- a/runtime/class_loader_context_test.cc
+++ b/runtime/class_loader_context_test.cc
@@ -17,17 +17,13 @@
#include "class_loader_context.h"
#include <gtest/gtest.h>
-#include <stdlib.h>
#include "android-base/strings.h"
-
#include "base/dchecked_vector.h"
#include "base/stl_util.h"
-#include "class_loader_context.h"
#include "class_linker.h"
#include "common_runtime_test.h"
#include "dex_file.h"
-#include "dex2oat_environment_test.h"
#include "handle_scope-inl.h"
#include "mirror/class.h"
#include "mirror/class_loader.h"
@@ -84,6 +80,10 @@ class ClassLoaderContextTest : public CommonRuntimeTest {
kEndsWith
};
+ static bool IsAbsoluteLocation(const std::string& location) {
+ return !location.empty() && location[0] == '/';
+ }
+
void VerifyOpenDexFiles(
ClassLoaderContext* context,
size_t index,
@@ -100,17 +100,22 @@ class ClassLoaderContextTest : public CommonRuntimeTest {
info.opened_dex_files[cur_open_dex_index++];
std::unique_ptr<const DexFile>& expected_dex_file = (*all_dex_files)[k];
- std::string expected_location =
- DexFileLoader::GetBaseLocation(expected_dex_file->GetLocation());
- UniqueCPtr<const char[]> expected_real_location(
- realpath(expected_location.c_str(), nullptr));
- ASSERT_TRUE(expected_real_location != nullptr) << expected_location;
- expected_location.assign(expected_real_location.get());
- expected_location += DexFileLoader::GetMultiDexSuffix(expected_dex_file->GetLocation());
-
- ASSERT_EQ(expected_location, opened_dex_file->GetLocation());
+ std::string expected_location = expected_dex_file->GetLocation();
+
+ const std::string& opened_location = opened_dex_file->GetLocation();
+ if (!IsAbsoluteLocation(opened_location)) {
+ // If the opened location is relative (it was open from a relative path without a
+ // classpath_dir) it might not match the expected location which is absolute in tests).
+ // So we compare the endings (the checksum will validate it's actually the same file).
+ ASSERT_EQ(0, expected_location.compare(
+ expected_location.length() - opened_location.length(),
+ opened_location.length(),
+ opened_location));
+ } else {
+ ASSERT_EQ(expected_location, opened_location);
+ }
ASSERT_EQ(expected_dex_file->GetLocationChecksum(), opened_dex_file->GetLocationChecksum());
- ASSERT_EQ(info.classpath[k], opened_dex_file->GetLocation());
+ ASSERT_EQ(info.classpath[k], opened_location);
}
}
@@ -252,6 +257,7 @@ TEST_F(ClassLoaderContextTest, OpenValidDexFiles) {
std::string myclass_dex_name = GetTestDexFileName("MyClass");
std::string dex_name = GetTestDexFileName("Main");
+
std::unique_ptr<ClassLoaderContext> context =
ClassLoaderContext::Create(
"PCL[" + multidex_name + ":" + myclass_dex_name + "];" +
@@ -272,42 +278,6 @@ TEST_F(ClassLoaderContextTest, OpenValidDexFiles) {
VerifyOpenDexFiles(context.get(), 1, &all_dex_files1);
}
-class ScratchSymLink {
- public:
- explicit ScratchSymLink(const std::string& file) {
- // Use a temporary scratch file to get a unique name for the link.
- ScratchFile scratchFile;
- scratch_link_name_ = scratchFile.GetFilename() + ".link.jar";
- CHECK_EQ(0, symlink(file.c_str(), scratch_link_name_.c_str()));
- }
-
- ~ScratchSymLink() {
- CHECK_EQ(0, unlink(scratch_link_name_.c_str()));
- }
-
- const std::string& GetFilename() { return scratch_link_name_; }
-
- private:
- std::string scratch_link_name_;
-};
-
-TEST_F(ClassLoaderContextTest, OpenValidDexFilesSymLink) {
- std::string myclass_dex_name = GetTestDexFileName("MyClass");
- // Now replace the dex location with a symlink.
- ScratchSymLink link(myclass_dex_name);
-
- std::unique_ptr<ClassLoaderContext> context =
- ClassLoaderContext::Create("PCL[" + link.GetFilename() + "]");
-
- ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, /*classpath_dir*/ ""));
-
- VerifyContextSize(context.get(), 1);
-
- std::vector<std::unique_ptr<const DexFile>> myclass_dex_files = OpenTestDexFiles("MyClass");
-
- VerifyOpenDexFiles(context.get(), 0, &myclass_dex_files);
-}
-
static std::string CreateRelativeString(const std::string& in, const char* cwd) {
int cwd_len = strlen(cwd);
if (!android::base::StartsWith(in, cwd) || (cwd_len < 1)) {