diff options
author | Martin Stjernholm <mast@google.com> | 2018-12-19 14:28:33 +0000 |
---|---|---|
committer | Martin Stjernholm <mast@google.com> | 2018-12-19 21:04:35 +0000 |
commit | bb4f2b440a5c970a3a522e94d69dae5fbaea81c6 (patch) | |
tree | 0792f75b20c1a2cfd8edc400b4ca7e8be0cf47bf /libunwindstack/tests/DexFileTest.cpp | |
parent | 1baa19b1a6bec9c0b1b067eef378646c62d9bf1b (diff) |
Revert^2 "Use libdexfile external API in libunwindstack."
This reverts commit cacf5bf6bca7e9806739a27589d8b6101c567c32.
Reason for revert: Re-apply with proper fix for VNDK visibility on marlin and sailfish.
Test: Manual repro of http://b/121110092#comment1 on reported branch
Test: atest CtsRenderscriptTestCases
Test: mmma system/core/{libunwindstack,libbacktrace}, run host gtests
Test: Make image, flash, and reboot device.
Test: Forrest cts/art/gce-all: https://android-build.googleplex.com/builds/forrest/run/L00300000240828791
Test: Forrest cts/bionic/gce-all: https://android-build.googleplex.com/builds/forrest/run/L05600000240682947 (shows 27/2958 failed, but it doesn't pass on Blackbox either: http://screen/xbjioEf6UgR)
Test: Forrest cts/renderscript/gce-all: https://android-build.googleplex.com/builds/forrest/run/L66200000240680523
Bug: 119632407
Change-Id: I601aa97eac8127e30d753405f8bc1fc4ae7f849f
Diffstat (limited to 'libunwindstack/tests/DexFileTest.cpp')
-rw-r--r-- | libunwindstack/tests/DexFileTest.cpp | 66 |
1 files changed, 20 insertions, 46 deletions
diff --git a/libunwindstack/tests/DexFileTest.cpp b/libunwindstack/tests/DexFileTest.cpp index 95d217631..21ca47b52 100644 --- a/libunwindstack/tests/DexFileTest.cpp +++ b/libunwindstack/tests/DexFileTest.cpp @@ -21,44 +21,37 @@ #include <unordered_map> #include <android-base/file.h> - +#include <dex/dex_file.h> +#include <gtest/gtest.h> #include <unwindstack/MapInfo.h> #include <unwindstack/Memory.h> -#include <dex/code_item_accessors-inl.h> -#include <dex/standard_dex_file.h> - -#include <gtest/gtest.h> - #include "DexFile.h" - #include "DexFileData.h" #include "MemoryFake.h" namespace unwindstack { TEST(DexFileTest, from_file_open_non_exist) { - DexFileFromFile dex_file; - ASSERT_FALSE(dex_file.Open(0, "/file/does/not/exist")); + EXPECT_TRUE(DexFileFromFile::Create(0, "/file/does/not/exist") == nullptr); } TEST(DexFileTest, from_file_open_too_small) { TemporaryFile tf; ASSERT_TRUE(tf.fd != -1); - ASSERT_EQ(sizeof(art::DexFile::Header) - 2, + ASSERT_EQ(sizeof(art::DexFile::Header) - 1, static_cast<size_t>( - TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(art::DexFile::Header)) - 2))); + TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(art::DexFile::Header) - 1)))); // Header too small. - DexFileFromFile dex_file; - ASSERT_FALSE(dex_file.Open(0, tf.path)); + EXPECT_TRUE(DexFileFromFile::Create(0, tf.path) == nullptr); // Header correct, file too small. ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)); ASSERT_EQ(sizeof(art::DexFile::Header), static_cast<size_t>(TEMP_FAILURE_RETRY(write( tf.fd, kDexData, sizeof(art::DexFile::Header))))); - ASSERT_FALSE(dex_file.Open(0, tf.path)); + EXPECT_TRUE(DexFileFromFile::Create(0, tf.path) == nullptr); } TEST(DexFileTest, from_file_open) { @@ -68,8 +61,7 @@ TEST(DexFileTest, from_file_open) { ASSERT_EQ(sizeof(kDexData), static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData))))); - DexFileFromFile dex_file; - ASSERT_TRUE(dex_file.Open(0, tf.path)); + EXPECT_TRUE(DexFileFromFile::Create(0, tf.path) != nullptr); } TEST(DexFileTest, from_file_open_non_zero_offset) { @@ -80,35 +72,31 @@ TEST(DexFileTest, from_file_open_non_zero_offset) { ASSERT_EQ(sizeof(kDexData), static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData))))); - DexFileFromFile dex_file; - ASSERT_TRUE(dex_file.Open(0x100, tf.path)); + EXPECT_TRUE(DexFileFromFile::Create(0x100, tf.path) != nullptr); } TEST(DexFileTest, from_memory_fail_too_small_for_header) { MemoryFake memory; memory.SetMemory(0x1000, kDexData, sizeof(art::DexFile::Header) - 1); - DexFileFromMemory dex_file; - ASSERT_FALSE(dex_file.Open(0x1000, &memory)); + EXPECT_TRUE(DexFileFromMemory::Create(0x1000, &memory, "") == nullptr); } TEST(DexFileTest, from_memory_fail_too_small_for_data) { MemoryFake memory; memory.SetMemory(0x1000, kDexData, sizeof(kDexData) - 2); - DexFileFromMemory dex_file; - ASSERT_FALSE(dex_file.Open(0x1000, &memory)); + EXPECT_TRUE(DexFileFromMemory::Create(0x1000, &memory, "") == nullptr); } TEST(DexFileTest, from_memory_open) { MemoryFake memory; memory.SetMemory(0x1000, kDexData, sizeof(kDexData)); - DexFileFromMemory dex_file; - ASSERT_TRUE(dex_file.Open(0x1000, &memory)); + EXPECT_TRUE(DexFileFromMemory::Create(0x1000, &memory, "") != nullptr); } TEST(DexFileTest, create_using_file) { @@ -121,8 +109,7 @@ TEST(DexFileTest, create_using_file) { MemoryFake memory; MapInfo info(nullptr, 0, 0x10000, 0, 0x5, tf.path); - std::unique_ptr<DexFile> dex_file(DexFile::Create(0x500, &memory, &info)); - ASSERT_TRUE(dex_file != nullptr); + EXPECT_TRUE(DexFile::Create(0x500, &memory, &info) != nullptr); } TEST(DexFileTest, create_using_file_non_zero_start) { @@ -135,8 +122,7 @@ TEST(DexFileTest, create_using_file_non_zero_start) { MemoryFake memory; MapInfo info(nullptr, 0x100, 0x10000, 0, 0x5, tf.path); - std::unique_ptr<DexFile> dex_file(DexFile::Create(0x600, &memory, &info)); - ASSERT_TRUE(dex_file != nullptr); + EXPECT_TRUE(DexFile::Create(0x600, &memory, &info) != nullptr); } TEST(DexFileTest, create_using_file_non_zero_offset) { @@ -149,24 +135,21 @@ TEST(DexFileTest, create_using_file_non_zero_offset) { MemoryFake memory; MapInfo info(nullptr, 0x100, 0x10000, 0x200, 0x5, tf.path); - std::unique_ptr<DexFile> dex_file(DexFile::Create(0x400, &memory, &info)); - ASSERT_TRUE(dex_file != nullptr); + EXPECT_TRUE(DexFile::Create(0x400, &memory, &info) != nullptr); } TEST(DexFileTest, create_using_memory_empty_file) { MemoryFake memory; memory.SetMemory(0x4000, kDexData, sizeof(kDexData)); MapInfo info(nullptr, 0x100, 0x10000, 0x200, 0x5, ""); - std::unique_ptr<DexFile> dex_file(DexFile::Create(0x4000, &memory, &info)); - ASSERT_TRUE(dex_file != nullptr); + EXPECT_TRUE(DexFile::Create(0x4000, &memory, &info) != nullptr); } TEST(DexFileTest, create_using_memory_file_does_not_exist) { MemoryFake memory; memory.SetMemory(0x4000, kDexData, sizeof(kDexData)); MapInfo info(nullptr, 0x100, 0x10000, 0x200, 0x5, "/does/not/exist"); - std::unique_ptr<DexFile> dex_file(DexFile::Create(0x4000, &memory, &info)); - ASSERT_TRUE(dex_file != nullptr); + EXPECT_TRUE(DexFile::Create(0x4000, &memory, &info) != nullptr); } TEST(DexFileTest, create_using_memory_file_is_malformed) { @@ -179,22 +162,13 @@ TEST(DexFileTest, create_using_memory_file_is_malformed) { MemoryFake memory; memory.SetMemory(0x4000, kDexData, sizeof(kDexData)); MapInfo info(nullptr, 0x4000, 0x10000, 0x200, 0x5, "/does/not/exist"); - std::unique_ptr<DexFile> dex_file(DexFile::Create(0x4000, &memory, &info)); + std::unique_ptr<DexFile> dex_file = DexFile::Create(0x4000, &memory, &info); ASSERT_TRUE(dex_file != nullptr); // Check it came from memory by clearing memory and verifying it fails. memory.Clear(); - dex_file.reset(DexFile::Create(0x4000, &memory, &info)); - ASSERT_TRUE(dex_file == nullptr); -} - -TEST(DexFileTest, get_method_not_opened) { - std::string method("something"); - uint64_t method_offset = 100; - DexFile dex_file; - dex_file.GetMethodInformation(0x100, &method, &method_offset); - EXPECT_EQ("something", method); - EXPECT_EQ(100U, method_offset); + dex_file = DexFile::Create(0x4000, &memory, &info); + EXPECT_TRUE(dex_file == nullptr); } TEST(DexFileTest, get_method) { |