diff options
author | 2016-12-01 19:09:15 +0000 | |
---|---|---|
committer | 2016-12-01 19:09:15 +0000 | |
commit | 48d08a4233ee4450b0d5073d41445f9dd1f17191 (patch) | |
tree | 0655c5ee28c54ad99b30eba3e324fc2f27c922cf | |
parent | 75d564e45061e1a9d28a89d3c8fa60af04ef28a8 (diff) | |
parent | 41fba6aefbbd42a66b24582da7304e96b52bbab4 (diff) |
Merge "Change Dex2oatLayoutTest to generate profile itself."
-rw-r--r-- | dex2oat/dex2oat_test.cc | 44 | ||||
-rw-r--r-- | runtime/jit/offline_profiling_info.h | 1 |
2 files changed, 24 insertions, 21 deletions
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc index 714a58c8e5..b6b62a80dc 100644 --- a/dex2oat/dex2oat_test.cc +++ b/dex2oat/dex2oat_test.cc @@ -26,6 +26,7 @@ #include "base/stringprintf.h" #include "dex_file-inl.h" #include "dex2oat_environment_test.h" +#include "jit/offline_profiling_info.h" #include "oat.h" #include "oat_file.h" #include "utils.h" @@ -552,26 +553,6 @@ TEST_F(Dex2oatVeryLargeTest, UseVeryLarge) { RunTest(CompilerFilter::kSpeed, true, { "--very-large-app-threshold=100" }); } -static const char kDexFileLayoutInputProfile[] = "cHJvADAwMgABAAwAAQABAOqMEeFEZXhOb09hdC5qYXIBAAEA"; - -static void WriteFileBase64(const char* base64, const char* location) { - // Decode base64. - CHECK(base64 != nullptr); - size_t length; - std::unique_ptr<uint8_t[]> bytes(DecodeBase64(base64, &length)); - CHECK(bytes.get() != nullptr); - - // Write to provided file. - std::unique_ptr<File> file(OS::CreateEmptyFile(location)); - CHECK(file.get() != nullptr); - if (!file->WriteFully(bytes.get(), length)) { - PLOG(FATAL) << "Failed to write base64 as file"; - } - if (file->FlushCloseOrErase() != 0) { - PLOG(FATAL) << "Could not flush and close test file."; - } -} - class Dex2oatLayoutTest : public Dex2oatTest { protected: void CheckFilter(CompilerFilter::Filter input ATTRIBUTE_UNUSED, @@ -579,13 +560,34 @@ class Dex2oatLayoutTest : public Dex2oatTest { // Ignore, we'll do our own checks. } + // Emits a profile with a single dex file with the given location and a single class index of 1. + void GenerateProfile(const std::string& test_profile, + const std::string& dex_location, + uint32_t checksum) { + int profile_test_fd = open(test_profile.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0644); + CHECK_GE(profile_test_fd, 0); + + ProfileCompilationInfo info; + std::string profile_key = ProfileCompilationInfo::GetProfileDexFileKey(dex_location); + info.AddClassIndex(profile_key, checksum, dex::TypeIndex(1)); + bool result = info.Save(profile_test_fd); + close(profile_test_fd); + ASSERT_TRUE(result); + } + void RunTest() { std::string dex_location = GetScratchDir() + "/DexNoOat.jar"; std::string profile_location = GetScratchDir() + "/primary.prof"; std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex"; Copy(GetDexSrc2(), dex_location); - WriteFileBase64(kDexFileLayoutInputProfile, profile_location.c_str()); + const char* location = dex_location.c_str(); + std::string error_msg; + std::vector<std::unique_ptr<const DexFile>> dex_files; + ASSERT_TRUE(DexFile::Open(location, location, true, &error_msg, &dex_files)); + EXPECT_EQ(dex_files.size(), 1U); + std::unique_ptr<const DexFile>& dex_file = dex_files[0]; + GenerateProfile(profile_location, dex_location, dex_file->GetLocationChecksum()); const std::vector<std::string>& extra_args = { "--profile-file=" + profile_location }; GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kLayoutProfile, extra_args); diff --git a/runtime/jit/offline_profiling_info.h b/runtime/jit/offline_profiling_info.h index 413648829a..53d0eea932 100644 --- a/runtime/jit/offline_profiling_info.h +++ b/runtime/jit/offline_profiling_info.h @@ -180,6 +180,7 @@ class ProfileCompilationInfo { friend class ProfileCompilationInfoTest; friend class CompilerDriverProfileTest; friend class ProfileAssistantTest; + friend class Dex2oatLayoutTest; DexFileToProfileInfoMap info_; }; |