OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/trace_event/winheap_dump_provider_win.h" |
| 6 |
| 7 #include <windows.h> |
| 8 |
| 9 #include "base/trace_event/memory_dump_session_state.h" |
| 10 #include "base/trace_event/process_memory_dump.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace base { |
| 14 namespace trace_event { |
| 15 |
| 16 class WinHeapDumpProviderTest : public testing::Test { |
| 17 public: |
| 18 bool GetHeapInformation(WinHeapDumpProvider* provider, |
| 19 WinHeapInfo* heap_info, |
| 20 const std::set<void*>& block_to_skip) { |
| 21 return provider->GetHeapInformation(heap_info, block_to_skip); |
| 22 } |
| 23 }; |
| 24 |
| 25 TEST_F(WinHeapDumpProviderTest, DumpInto) { |
| 26 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState())); |
| 27 |
| 28 WinHeapDumpProvider* winheap_dump_provider = |
| 29 WinHeapDumpProvider::GetInstance(); |
| 30 ASSERT_NE(reinterpret_cast<WinHeapDumpProvider*>(nullptr), |
| 31 winheap_dump_provider); |
| 32 |
| 33 ASSERT_TRUE(winheap_dump_provider->DumpInto(&pmd)); |
| 34 } |
| 35 |
| 36 TEST_F(WinHeapDumpProviderTest, GetHeapInformation) { |
| 37 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState())); |
| 38 |
| 39 WinHeapDumpProvider* winheap_dump_provider = |
| 40 WinHeapDumpProvider::GetInstance(); |
| 41 ASSERT_NE(reinterpret_cast<WinHeapDumpProvider*>(nullptr), |
| 42 winheap_dump_provider); |
| 43 |
| 44 HANDLE heap = ::HeapCreate(NULL, 0, 0); |
| 45 ASSERT_NE(nullptr, heap); |
| 46 |
| 47 const size_t kAllocSize = 42; |
| 48 void* alloc = ::HeapAlloc(heap, 0, kAllocSize); |
| 49 ASSERT_NE(nullptr, alloc); |
| 50 |
| 51 WinHeapInfo heap_info = {0}; |
| 52 heap_info.heap_id = heap; |
| 53 std::set<void*> block_to_skip; |
| 54 |
| 55 // Put the allocation into the skip list and make sure that the provider |
| 56 // ignores it. |
| 57 block_to_skip.insert(alloc); |
| 58 ASSERT_TRUE( |
| 59 GetHeapInformation(winheap_dump_provider, &heap_info, block_to_skip)); |
| 60 EXPECT_EQ(0U, heap_info.block_count); |
| 61 EXPECT_EQ(0U, heap_info.allocated_size); |
| 62 // We can't check the committed size here, as it can depend on the version of |
| 63 // kernel32.dll. |
| 64 |
| 65 // Remove the allocation from the skip list and check if it's analysed |
| 66 // properlyly. |
| 67 block_to_skip.erase(alloc); |
| 68 ASSERT_TRUE( |
| 69 GetHeapInformation(winheap_dump_provider, &heap_info, block_to_skip)); |
| 70 EXPECT_EQ(1, heap_info.block_count); |
| 71 EXPECT_EQ(kAllocSize, heap_info.allocated_size); |
| 72 EXPECT_LT(kAllocSize, heap_info.committed_size); |
| 73 |
| 74 EXPECT_TRUE(::HeapFree(heap, 0, alloc)); |
| 75 EXPECT_EQ(TRUE, ::HeapDestroy(heap)); |
| 76 } |
| 77 |
| 78 } // namespace trace_event |
| 79 } // namespace base |
OLD | NEW |