summaryrefslogtreecommitdiff
path: root/libunwindstack/tests/MemoryBufferTest.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-09-26 14:11:37 -0700
committerJosh Gao <jmgao@google.com>2017-11-15 15:38:13 -0800
commit29c5378e91720b7befabc91fbab0f25d59a23bf1 (patch)
treebbbad7bd899927a5e6f9e15891be0e4de31fc7c4 /libunwindstack/tests/MemoryBufferTest.cpp
parent37eb97d911087992fb7dc986331e10a3c5a18d30 (diff)
unwindstack: add Memory::ReadPartially.
Add a way to read while allowing for partial reads. Test: new tests added to libunwindstack_test, ran 32/64 on hikey960, sailfish Test: ran unwind on hikey960/sailfish Change-Id: I8b11d9230fcd3122148ef3f980863ac1404ad70a
Diffstat (limited to 'libunwindstack/tests/MemoryBufferTest.cpp')
-rw-r--r--libunwindstack/tests/MemoryBufferTest.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/libunwindstack/tests/MemoryBufferTest.cpp b/libunwindstack/tests/MemoryBufferTest.cpp
index 50a8a1b6c..be5a52003 100644
--- a/libunwindstack/tests/MemoryBufferTest.cpp
+++ b/libunwindstack/tests/MemoryBufferTest.cpp
@@ -78,4 +78,24 @@ TEST_F(MemoryBufferTest, read_failure_overflow) {
ASSERT_FALSE(memory_->Read(UINT64_MAX - 100, buffer.data(), 200));
}
+TEST_F(MemoryBufferTest, ReadPartially) {
+ memory_->Resize(256);
+ ASSERT_EQ(256U, memory_->Size());
+ ASSERT_TRUE(memory_->GetPtr(0) != nullptr);
+ ASSERT_TRUE(memory_->GetPtr(1) != nullptr);
+ ASSERT_TRUE(memory_->GetPtr(255) != nullptr);
+ ASSERT_TRUE(memory_->GetPtr(256) == nullptr);
+
+ uint8_t* data = memory_->GetPtr(0);
+ for (size_t i = 0; i < memory_->Size(); i++) {
+ data[i] = i;
+ }
+
+ std::vector<uint8_t> buffer(memory_->Size());
+ ASSERT_EQ(128U, memory_->ReadPartially(128, buffer.data(), buffer.size()));
+ for (size_t i = 0; i < 128; i++) {
+ ASSERT_EQ(128 + i, buffer[i]) << "Failed at byte " << i;
+ }
+}
+
} // namespace unwindstack