diff options
Diffstat (limited to 'compiler/image_test.cc')
| -rw-r--r-- | compiler/image_test.cc | 75 |
1 files changed, 58 insertions, 17 deletions
diff --git a/compiler/image_test.cc b/compiler/image_test.cc index 6df15279a0..5afe2db27f 100644 --- a/compiler/image_test.cc +++ b/compiler/image_test.cc @@ -23,7 +23,9 @@ #include "base/unix_file/fd_file.h" #include "class_linker-inl.h" #include "common_compiler_test.h" +#include "dwarf/method_debug_info.h" #include "elf_writer.h" +#include "elf_writer_quick.h" #include "gc/space/image_space.h" #include "image_writer.h" #include "lock_word.h" @@ -32,7 +34,6 @@ #include "scoped_thread_state_change.h" #include "signal_catcher.h" #include "utils.h" -#include "vector_output_stream.h" namespace art { @@ -42,10 +43,17 @@ class ImageTest : public CommonCompilerTest { ReserveImageSpace(); CommonCompilerTest::SetUp(); } + void TestWriteRead(ImageHeader::StorageMode storage_mode); }; -TEST_F(ImageTest, WriteRead) { - TEST_DISABLED_FOR_NON_PIC_COMPILING_WITH_OPTIMIZING(); +void ImageTest::TestWriteRead(ImageHeader::StorageMode storage_mode) { + // TODO: Test does not currently work with optimizing. + CreateCompilerDriver(Compiler::kQuick, kRuntimeISA); + ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); + // Enable write for dex2dex. + for (const DexFile* dex_file : class_linker->GetBootClassPath()) { + dex_file->EnableWrite(); + } // Create a generic location tmp file, to be the base of the .art and .oat temporary files. ScratchFile location; ScratchFile image_location(location, ".art"); @@ -67,17 +75,14 @@ TEST_F(ImageTest, WriteRead) { std::unique_ptr<ImageWriter> writer(new ImageWriter(*compiler_driver_, requested_image_base, /*compile_pic*/false, - /*compile_app_image*/false)); + /*compile_app_image*/false, + storage_mode)); // TODO: compile_pic should be a test argument. { { jobject class_loader = nullptr; - ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); TimingLogger timings("ImageTest::WriteRead", false, false); TimingLogger::ScopedTiming t("CompileAll", &timings); - for (const DexFile* dex_file : class_linker->GetBootClassPath()) { - dex_file->EnableWrite(); - } compiler_driver_->SetDexFilesForOatFile(class_linker->GetBootClassPath()); compiler_driver_->CompileAll(class_loader, class_linker->GetBootClassPath(), &timings); @@ -92,12 +97,32 @@ TEST_F(ImageTest, WriteRead) { /*compiling_boot_image*/true, &timings, &key_value_store); - bool success = writer->PrepareImageAddressSpace() && - compiler_driver_->WriteElf(GetTestAndroidRoot(), - !kIsTargetBuild, - class_linker->GetBootClassPath(), - &oat_writer, - oat_file.GetFile()); + std::unique_ptr<ElfWriter> elf_writer = CreateElfWriterQuick( + compiler_driver_->GetInstructionSet(), + &compiler_driver_->GetCompilerOptions(), + oat_file.GetFile()); + bool success = writer->PrepareImageAddressSpace(); + ASSERT_TRUE(success); + + elf_writer->Start(); + + OutputStream* rodata = elf_writer->StartRoData(); + bool rodata_ok = oat_writer.WriteRodata(rodata); + ASSERT_TRUE(rodata_ok); + elf_writer->EndRoData(rodata); + + OutputStream* text = elf_writer->StartText(); + bool text_ok = oat_writer.WriteCode(text); + ASSERT_TRUE(text_ok); + elf_writer->EndText(text); + + elf_writer->SetBssSize(oat_writer.GetBssSize()); + elf_writer->WriteDynamicSection(); + elf_writer->WriteDebugInfo(oat_writer.GetMethodDebugInfo()); + elf_writer->WritePatchLocations(oat_writer.GetAbsolutePatchLocations()); + + success = elf_writer->End(); + ASSERT_TRUE(success); } } @@ -156,7 +181,7 @@ TEST_F(ImageTest, WriteRead) { java_lang_dex_file_ = nullptr; MemMap::Init(); - std::unique_ptr<const DexFile> dex(LoadExpectSingleDexFile(GetLibCoreDexFileName().c_str())); + std::unique_ptr<const DexFile> dex(LoadExpectSingleDexFile(GetLibCoreDexFileNames()[0].c_str())); RuntimeOptions options; std::string image("-Ximage:"); @@ -183,7 +208,13 @@ TEST_F(ImageTest, WriteRead) { gc::space::ImageSpace* image_space = heap->GetBootImageSpace(); ASSERT_TRUE(image_space != nullptr); - ASSERT_LE(image_space->Size(), image_file_size); + if (storage_mode == ImageHeader::kStorageModeUncompressed) { + // Uncompressed, image should be smaller than file. + ASSERT_LE(image_space->Size(), image_file_size); + } else { + // Compressed, file should be smaller than image. + ASSERT_LE(image_file_size, image_space->Size()); + } image_space->VerifyImageAllocations(); uint8_t* image_begin = image_space->Begin(); @@ -211,6 +242,14 @@ TEST_F(ImageTest, WriteRead) { CHECK_EQ(0, rmdir_result); } +TEST_F(ImageTest, WriteReadUncompressed) { + TestWriteRead(ImageHeader::kStorageModeUncompressed); +} + +TEST_F(ImageTest, WriteReadLZ4) { + TestWriteRead(ImageHeader::kStorageModeLZ4); +} + TEST_F(ImageTest, ImageHeaderIsValid) { uint32_t image_begin = ART_BASE_ADDRESS; uint32_t image_size_ = 16 * KB; @@ -231,7 +270,9 @@ TEST_F(ImageTest, ImageHeaderIsValid) { oat_data_end, oat_file_end, sizeof(void*), - /*compile_pic*/false); + /*compile_pic*/false, + ImageHeader::kDefaultStorageMode, + /*data_size*/0u); ASSERT_TRUE(image_header.IsValid()); char* magic = const_cast<char*>(image_header.GetMagic()); |