summaryrefslogtreecommitdiff
path: root/runtime/class_loader_context_test.cc
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2023-06-15 15:48:20 +0100
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2023-07-04 07:44:18 +0000
commitb1c6f5736a8f661de45a9aeac462df998a2f0a98 (patch)
tree04c7bcf3112d18311326e945ac13858c8d79b45b /runtime/class_loader_context_test.cc
parent4ffd7596ff79ce7f9dfb8b279642cfb8bdd855b0 (diff)
Revert^2 "Reduce multidex checksum to single scalar value."
Change GetMultiDexChecksums to return a single value rather than a vector. The single checksum represents the whole multidex set, and will change if any dex file within the multidex set changes. Fundamentally, we need a value to represent a .zip/.jar archive, so that we can check whether our build artifacts are up to date. We previously used a vector of CRC32 values (one per dex file), however, one combined checksum per archive is also sufficient. This is necessary, since the future multidex format will have single zip entry, so we need to adjust the code to expect just one checksum per zip file. This separates the change to own CL. The two sides of the checksum comparison are trivially reduced: * Zip files are reduced by XORing the individual CRC values. * Likewise, checksums of already open DexFiles are XORed. As a consequence, ClassLoader path needs to be reduced to print only single checksum per jar file as well. Bug: 266950186 Test: ./art/test.py -b --host Change-Id: I2782d7204e913d9f8e12ce80438ed98af5d42991
Diffstat (limited to 'runtime/class_loader_context_test.cc')
-rw-r--r--runtime/class_loader_context_test.cc90
1 files changed, 58 insertions, 32 deletions
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc
index ce9780a74e..98b8eed5d5 100644
--- a/runtime/class_loader_context_test.cc
+++ b/runtime/class_loader_context_test.cc
@@ -20,6 +20,8 @@
#include <filesystem>
#include <fstream>
+#include <optional>
+#include <vector>
#include "android-base/stringprintf.h"
#include "android-base/strings.h"
@@ -27,6 +29,7 @@
#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"
@@ -184,41 +187,62 @@ class ClassLoaderContextTest : public CommonRuntimeTest {
ClassLoaderContext::ContextDexFilesState::kDexFilesOpened);
}
ClassLoaderContext::ClassLoaderInfo& info = *context->GetParent(index);
- ASSERT_EQ(all_dex_files->size(), info.classpath.size());
- ASSERT_EQ(all_dex_files->size(), info.checksums.size());
+
+ 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());
+
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, 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);
+ 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);
+ }
}
}
}
@@ -1202,9 +1226,11 @@ 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(dex2[0]->GetLocationChecksum())
- + "];PCL[" + CreateClassPathWithChecksums(dex1) + "]";
+ std::string expected_encoding = "IMC[<unknown>*" + std::to_string(expected_checksum) + "];PCL[" +
+ CreateClassPathWithChecksums(dex1) + "]";
ASSERT_EQ(expected_encoding, context->EncodeContextForOatFile(""));
}