summaryrefslogtreecommitdiff
path: root/runtime/class_loader_context_test.cc
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2023-07-03 15:42:50 +0000
committer David Srbecky <dsrbecky@google.com> 2023-07-03 17:40:14 +0000
commit1bc114026d69fb112db5b671922e5c0c4df29e07 (patch)
tree352f60932a1bbf038a68519bf5c8d53e2da8f4c2 /runtime/class_loader_context_test.cc
parent2522715378315a4e402a80c076f58689e1a02913 (diff)
Revert "Reduce multidex checksum to single scalar value."
This reverts commit fdfa590b7b43ca70e497f1a8afe9a641b57ece56. Reason for revert: b/289784075 Change-Id: Ib114ca32dac6d1aaced372334873bfa12f74d572
Diffstat (limited to 'runtime/class_loader_context_test.cc')
-rw-r--r--runtime/class_loader_context_test.cc90
1 files changed, 32 insertions, 58 deletions
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc
index 98b8eed5d5..ce9780a74e 100644
--- a/runtime/class_loader_context_test.cc
+++ b/runtime/class_loader_context_test.cc
@@ -20,8 +20,6 @@
#include <filesystem>
#include <fstream>
-#include <optional>
-#include <vector>
#include "android-base/stringprintf.h"
#include "android-base/strings.h"
@@ -29,7 +27,6 @@
#include "art_method-alloc-inl.h"
#include "base/dchecked_vector.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "class_linker.h"
#include "class_root-inl.h"
#include "common_runtime_test.h"
@@ -187,62 +184,41 @@ class ClassLoaderContextTest : public CommonRuntimeTest {
ClassLoaderContext::ContextDexFilesState::kDexFilesOpened);
}
ClassLoaderContext::ClassLoaderInfo& info = *context->GetParent(index);
-
- std::vector<const DexFile*> primary_dex_files;
- std::vector<std::optional<uint32_t>> primary_checksums;
- for (size_t i = 0; i < all_dex_files->size();) {
- primary_dex_files.push_back((*all_dex_files)[i].get());
- primary_checksums.push_back(DexFileLoader::GetMultiDexChecksum(*all_dex_files, &i));
- }
- ASSERT_EQ(primary_dex_files.size(), info.classpath.size());
- ASSERT_EQ(primary_dex_files.size(), info.checksums.size());
-
+ ASSERT_EQ(all_dex_files->size(), info.classpath.size());
+ ASSERT_EQ(all_dex_files->size(), info.checksums.size());
if (only_read_checksums) {
ASSERT_EQ(0u, info.opened_dex_files.size());
- for (size_t k = 0; k < primary_dex_files.size(); k++) {
- const std::string& opened_location = info.classpath[k];
- uint32_t opened_checksum = info.checksums[k];
-
- const DexFile* expected_dex_file = primary_dex_files[k];
- std::string expected_location = expected_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_TRUE(EndsWith(expected_location, opened_location))
- << expected_location << " " << opened_location;
- } else {
- ASSERT_EQ(expected_location, opened_location);
- }
- ASSERT_EQ(primary_checksums[k], opened_checksum);
- if (classpath_matches_dex_location) {
- ASSERT_EQ(info.classpath[k], opened_location);
- }
- }
} else {
ASSERT_EQ(all_dex_files->size(), info.opened_dex_files.size());
+ }
- for (size_t k = 0; k < all_dex_files->size(); k++) {
- const std::string& opened_location = info.opened_dex_files[k]->GetLocation();
- uint32_t opened_checksum = info.opened_dex_files[k]->GetLocationChecksum();
-
- std::unique_ptr<const DexFile>& expected_dex_file = (*all_dex_files)[k];
- std::string expected_location = expected_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_TRUE(EndsWith(expected_location, opened_location))
- << expected_location << " " << opened_location;
- } else {
- ASSERT_EQ(expected_location, opened_location);
- }
- ASSERT_EQ(expected_dex_file->GetLocationChecksum(), opened_checksum);
- if (classpath_matches_dex_location) {
- ASSERT_EQ(info.classpath[k], opened_location);
- }
+ for (size_t k = 0, cur_open_dex_index = 0;
+ k < all_dex_files->size();
+ k++, cur_open_dex_index++) {
+ const std::string& opened_location = only_read_checksums
+ ? info.classpath[cur_open_dex_index]
+ : info.opened_dex_files[cur_open_dex_index]->GetLocation();
+ uint32_t opened_checksum = only_read_checksums
+ ? info.checksums[cur_open_dex_index]
+ : info.opened_dex_files[cur_open_dex_index]->GetLocationChecksum();
+
+ std::unique_ptr<const DexFile>& expected_dex_file = (*all_dex_files)[k];
+ std::string expected_location = expected_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_checksum);
+ if (classpath_matches_dex_location) {
+ ASSERT_EQ(info.classpath[k], opened_location);
}
}
}
@@ -1226,11 +1202,9 @@ TEST_F(ClassLoaderContextTest, EncodeInOatFileIMC) {
std::vector<std::unique_ptr<const DexFile>> dex2 = OpenTestDexFiles("MyClass");
ASSERT_EQ(dex2.size(), 1u);
- uint32_t expected_checksum = DexFileLoader::GetMultiDexChecksum(dex2);
-
std::string encoding = context->EncodeContextForOatFile("");
- std::string expected_encoding = "IMC[<unknown>*" + std::to_string(expected_checksum) + "];PCL[" +
- CreateClassPathWithChecksums(dex1) + "]";
+ std::string expected_encoding = "IMC[<unknown>*" + std::to_string(dex2[0]->GetLocationChecksum())
+ + "];PCL[" + CreateClassPathWithChecksums(dex1) + "]";
ASSERT_EQ(expected_encoding, context->EncodeContextForOatFile(""));
}