class Dex2oatScratchDirs { public: void SetUp(const std::string& android_data) { // Create a scratch directory to work from.
// Get the realpath of the android data. The oat dir should always point to real location // when generating oat files in dalvik-cache. This avoids complicating the unit tests // when matching the expected paths.
UniqueCPtr<constchar[]> android_data_real(realpath(android_data.c_str(), nullptr));
ASSERT_TRUE(android_data_real != nullptr)
<< "Could not get the realpath of the android data" << android_data << strerror(errno);
// Scratch directory, for dex and odex files (oat files will go in the // dalvik cache). const std::string& GetScratchDir() const { return scratch_dir_; }
// Odex directory is the subdirectory in the scratch directory where odex // files should be located. const std::string& GetOdexDir() const { return odex_dir_; }
// Test class that provides some helpers to set a test up for compilation using dex2oat. class Dex2oatEnvironmentTest : public Dex2oatScratchDirs, public CommonRuntimeTest { public: void SetUp() override {
CommonRuntimeTest::SetUp();
Dex2oatScratchDirs::SetUp(android_data_);
// Verify the environment is as we expect
std::optional<uint32_t> checksum;
std::string error_msg;
ASSERT_TRUE(OS::FileExists(GetSystemImageFile().c_str()))
<< "Expected pre-compiled boot image to be at: " << GetSystemImageFile();
ASSERT_TRUE(OS::FileExists(GetDexSrc1().c_str()))
<< "Expected dex file to be at: " << GetDexSrc1();
ASSERT_TRUE(OS::FileExists(GetResourceOnlySrc1().c_str()))
<< "Expected stripped dex file to be at: " << GetResourceOnlySrc1();
ArtDexFileLoader dex_file_loader0(GetResourceOnlySrc1());
ASSERT_TRUE(dex_file_loader0.GetMultiDexChecksum(&checksum, &error_msg))
<< "Expected stripped dex file to be stripped: " << GetResourceOnlySrc1();
ASSERT_TRUE(OS::FileExists(GetDexSrc2().c_str()))
<< "Expected dex file to be at: " << GetDexSrc2();
// GetMultiDexSrc2 should have the same primary dex checksum as // GetMultiDexSrc1, but a different secondary dex checksum. static constexpr bool kVerifyChecksum = true;
std::vector<std::unique_ptr<const DexFile>> multi1;
ArtDexFileLoader dex_file_loader1(GetMultiDexSrc1());
ASSERT_TRUE(dex_file_loader1.Open(/* verify= */ true, kVerifyChecksum, &error_msg, &multi1))
<< error_msg;
ASSERT_GT(multi1.size(), 1u);
if (multi1[0]->HasDexContainer()) { // Checksum is the CRC of the whole container, so both of them should differ.
ASSERT_NE(multi1[0]->GetLocationChecksum(), multi2[0]->GetLocationChecksum());
ASSERT_NE(multi1[1]->GetLocationChecksum(), multi2[1]->GetLocationChecksum());
} else {
ASSERT_EQ(multi1[0]->GetLocationChecksum(), multi2[0]->GetLocationChecksum());
ASSERT_NE(multi1[1]->GetLocationChecksum(), multi2[1]->GetLocationChecksum());
}
}
// Set up the image location.
options->push_back(std::make_pair("-Ximage:" + GetImageLocation(),
nullptr)); // Make sure compilercallbacks are not set so that relocation will be // enabled.
callbacks_.reset();
}
// Returns the path to a dex file equivalent to GetDexSrc1, but with the dex // file stripped.
std::string GetResourceOnlySrc1() const { return GetTestDexFileName("MainStripped");
}
// Returns the path to a multidex file equivalent to GetMultiDexSrc2, but // with the contents of the secondary dex file changed.
std::string GetMultiDexSrc2() const { return GetTestDexFileName("MultiDexModifiedSecondary");
}
// We must set --android-root. constchar* android_root = getenv("ANDROID_ROOT");
CHECK(android_root != nullptr);
argv.push_back("--android-root=" + std::string(android_root));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.