summaryrefslogtreecommitdiff
path: root/runtime/dexopt_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/dexopt_test.cc')
-rw-r--r--runtime/dexopt_test.cc85
1 files changed, 36 insertions, 49 deletions
diff --git a/runtime/dexopt_test.cc b/runtime/dexopt_test.cc
index eb5b149039..3eee9e03e0 100644
--- a/runtime/dexopt_test.cc
+++ b/runtime/dexopt_test.cc
@@ -14,14 +14,17 @@
* limitations under the License.
*/
-#include <string>
-#include <vector>
+#include "dexopt_test.h"
#include <gtest/gtest.h>
#include <procinfo/process_map.h>
+#include <string>
+#include <vector>
+
#include "android-base/stringprintf.h"
#include "android-base/strings.h"
+#include "arch/instruction_set.h"
#include "base/file_utils.h"
#include "base/mem_map.h"
#include "common_runtime_test.h"
@@ -29,10 +32,10 @@
#include "dex/art_dex_file_loader.h"
#include "dex/dex_file_loader.h"
#include "dex2oat_environment_test.h"
-#include "dexopt_test.h"
#include "gc/space/image_space.h"
#include "hidden_api.h"
#include "oat.h"
+#include "oat_file_assistant.h"
#include "profile/profile_compilation_info.h"
namespace art {
@@ -46,9 +49,7 @@ void DexoptTest::PreRuntimeCreate() {
UnreserveImageSpace();
}
-void DexoptTest::PostRuntimeCreate() {
- ReserveImageSpace();
-}
+void DexoptTest::PostRuntimeCreate() { ReserveImageSpace(); }
bool DexoptTest::Dex2Oat(const std::vector<std::string>& args, std::string* error_msg) {
std::vector<std::string> argv;
@@ -80,9 +81,9 @@ std::string DexoptTest::GenerateAlternateImage(const std::string& scratch_dir) {
int mkdir_result = mkdir(image_dir.c_str(), 0700);
CHECK_EQ(0, mkdir_result) << image_dir.c_str();
- std::vector<std::string> extra_args {
- "--compiler-filter=verify",
- android::base::StringPrintf("--base=0x%08x", ART_BASE_ADDRESS),
+ std::vector<std::string> extra_args{
+ "--compiler-filter=verify",
+ android::base::StringPrintf("--base=0x%08x", ART_BASE_ADDRESS),
};
std::string filename_prefix = image_dir + "/boot-interpreter";
ArrayRef<const std::string> dex_files(libcore_dex_files);
@@ -117,10 +118,9 @@ void DexoptTest::GenerateOatForTest(const std::string& dex_location,
// doesn't get an empty profile and changes the filter to verify.
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- const ArtDexFileLoader dex_file_loader;
+ ArtDexFileLoader dex_file_loader(dex_location);
ASSERT_TRUE(dex_file_loader.Open(
- dex_location.c_str(), dex_location.c_str(), /*verify=*/ false, /*verify_checksum=*/ false,
- &error_msg, &dex_files));
+ /*verify=*/false, /*verify_checksum=*/false, &error_msg, &dex_files));
EXPECT_GE(dex_files.size(), 1U);
std::unique_ptr<const DexFile>& dex_file = dex_files[0];
ProfileCompilationInfo info;
@@ -152,33 +152,24 @@ void DexoptTest::GenerateOatForTest(const std::string& dex_location,
ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg;
// Verify the odex file was generated as expected.
- std::unique_ptr<OatFile> odex_file(OatFile::Open(/*zip_fd=*/ -1,
- oat_location.c_str(),
- oat_location.c_str(),
- /*executable=*/ false,
- /*low_4gb=*/ false,
+ std::unique_ptr<OatFile> odex_file(OatFile::Open(/*zip_fd=*/-1,
+ oat_location,
+ oat_location,
+ /*executable=*/false,
+ /*low_4gb=*/false,
dex_location,
&error_msg));
ASSERT_TRUE(odex_file.get() != nullptr) << error_msg;
EXPECT_EQ(filter, odex_file->GetCompilerFilter());
if (CompilerFilter::DependsOnImageChecksum(filter)) {
- const OatHeader& oat_header = odex_file->GetOatHeader();
- const char* oat_bcp = oat_header.GetStoreValueByKey(OatHeader::kBootClassPathKey);
- ASSERT_TRUE(oat_bcp != nullptr);
- ASSERT_EQ(oat_bcp, android::base::Join(Runtime::Current()->GetBootClassPathLocations(), ':'));
- const char* checksums = oat_header.GetStoreValueByKey(OatHeader::kBootClassPathChecksumsKey);
- ASSERT_TRUE(checksums != nullptr);
-
- bool match = gc::space::ImageSpace::VerifyBootClassPathChecksums(
- checksums,
- oat_bcp,
- ArrayRef<const std::string>(&image_location, 1),
- ArrayRef<const std::string>(Runtime::Current()->GetBootClassPathLocations()),
- ArrayRef<const std::string>(Runtime::Current()->GetBootClassPath()),
- ArrayRef<const int>(Runtime::Current()->GetBootClassPathFds()),
- kRuntimeISA,
- &error_msg);
+ std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(/*spec=*/"");
+ OatFileAssistant oat_file_assistant(dex_location.c_str(),
+ kRuntimeISA,
+ context.get(),
+ /*load_executable=*/false);
+
+ bool match = oat_file_assistant.ValidateBootClassPathChecksums(*odex_file);
ASSERT_EQ(!with_alternate_image, match) << error_msg;
}
}
@@ -191,7 +182,7 @@ void DexoptTest::GenerateOdexForTest(const std::string& dex_location,
GenerateOatForTest(dex_location,
odex_location,
filter,
- /*with_alternate_image=*/ false,
+ /*with_alternate_image=*/false,
compilation_reason,
extra_args);
}
@@ -202,15 +193,13 @@ void DexoptTest::GenerateOatForTest(const char* dex_location,
std::string oat_location;
std::string error_msg;
ASSERT_TRUE(OatFileAssistant::DexLocationToOatFilename(
- dex_location, kRuntimeISA, &oat_location, &error_msg)) << error_msg;
- GenerateOatForTest(dex_location,
- oat_location,
- filter,
- with_alternate_image);
+ dex_location, kRuntimeISA, &oat_location, &error_msg))
+ << error_msg;
+ GenerateOatForTest(dex_location, oat_location, filter, with_alternate_image);
}
void DexoptTest::GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter) {
- GenerateOatForTest(dex_location, filter, /*with_alternate_image=*/ false);
+ GenerateOatForTest(dex_location, filter, /*with_alternate_image=*/false);
}
void DexoptTest::ReserveImageSpace() {
@@ -239,19 +228,17 @@ void DexoptTest::ReserveImageSpaceChunk(uintptr_t start, uintptr_t end) {
reinterpret_cast<uint8_t*>(start),
end - start,
PROT_NONE,
- /*low_4gb=*/ false,
- /*reuse=*/ false,
- /*reservation=*/ nullptr,
+ /*low_4gb=*/false,
+ /*reuse=*/false,
+ /*reservation=*/nullptr,
&error_msg));
ASSERT_TRUE(image_reservation_.back().IsValid()) << error_msg;
- LOG(INFO) << "Reserved space for image " <<
- reinterpret_cast<void*>(image_reservation_.back().Begin()) << "-" <<
- reinterpret_cast<void*>(image_reservation_.back().End());
+ LOG(INFO) << "Reserved space for image "
+ << reinterpret_cast<void*>(image_reservation_.back().Begin()) << "-"
+ << reinterpret_cast<void*>(image_reservation_.back().End());
}
}
-void DexoptTest::UnreserveImageSpace() {
- image_reservation_.clear();
-}
+void DexoptTest::UnreserveImageSpace() { image_reservation_.clear(); }
} // namespace art