Chromium Code Reviews| Index: base/trace_event/winheap_dump_provider_unittest.cc |
| diff --git a/base/trace_event/winheap_dump_provider_unittest.cc b/base/trace_event/winheap_dump_provider_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b7faf38a3065ffcb33f8702185486b5b80659997 |
| --- /dev/null |
| +++ b/base/trace_event/winheap_dump_provider_unittest.cc |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/trace_event/winheap_dump_provider.h" |
| + |
| +#include <windows.h> |
| + |
| +#include "base/trace_event/memory_dump_session_state.h" |
| +#include "base/trace_event/process_memory_dump.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace base { |
| +namespace trace_event { |
| + |
| +namespace { |
| + |
| +class TestWinHeapDumpProvider : public WinHeapDumpProvider { |
|
Primiano Tucci (use gerrit)
2015/04/22 23:48:32
Uhm a bit curious about this: it seems to not add
Sébastien Marchand
2015/04/23 10:52:03
I just used this to expose some protected function
|
| + public: |
| + using WinHeapDumpProvider::GetHeapInformation; |
|
chrisha
2015/04/23 09:23:27
As suggested by Primiano, if you simply 'friend' t
Sébastien Marchand
2015/04/23 10:52:03
Yeah, I still need to put an accessor in the WinHe
|
| + |
| + static TestWinHeapDumpProvider* GetInstance() { |
| + COMPILE_ASSERT( |
| + sizeof(TestWinHeapDumpProvider) == sizeof(WinHeapDumpProvider), |
| + TestWinHeapDumpProvider_should_be_an_interface); |
| + return reinterpret_cast<TestWinHeapDumpProvider*>( |
| + WinHeapDumpProvider::GetInstance()); |
| + } |
| +}; |
| + |
| +} // namespace |
| + |
| +TEST(WinHeapDumpProviderTest, DumpInto) { |
| + ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState())); |
| + |
| + TestWinHeapDumpProvider* winheap_dump_provider = |
| + TestWinHeapDumpProvider::GetInstance(); |
| + ASSERT_NE(reinterpret_cast<TestWinHeapDumpProvider*>(nullptr), |
| + winheap_dump_provider); |
| + |
| + pmd.session_state()->allocators_attributes_type_info.Update( |
| + winheap_dump_provider->allocator_attributes_type_info()); |
|
Primiano Tucci (use gerrit)
2015/04/22 23:48:32
I think you are not using any attribute, right? th
Sébastien Marchand
2015/04/23 10:52:03
Yeah, I thought that it was required for the |set_
|
| + |
| + ASSERT_TRUE(winheap_dump_provider->DumpInto(&pmd)); |
| +} |
| + |
| +TEST(WinHeapDumpProviderTest, GetHeapInformation) { |
| + ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState())); |
| + |
| + TestWinHeapDumpProvider* winheap_dump_provider = |
| + TestWinHeapDumpProvider::GetInstance(); |
| + ASSERT_NE(reinterpret_cast<TestWinHeapDumpProvider*>(nullptr), |
| + winheap_dump_provider); |
| + |
| + HANDLE heap = ::HeapCreate(NULL, 0, 0); |
| + ASSERT_NE(nullptr, heap); |
| + |
| + const size_t kAllocSize = 42; |
| + void* alloc = ::HeapAlloc(heap, 0, kAllocSize); |
| + ASSERT_NE(nullptr, alloc); |
| + |
| + WinHeapInfo heap_info = { 0 }; |
| + heap_info.heap_id = heap; |
| + std::set<void*> block_to_skip; |
| + |
| + // Put the allocation into the skip list and make sure that the provider |
| + // ignore it. |
|
chrisha
2015/04/23 09:23:27
ignores* it
Sébastien Marchand
2015/04/23 10:52:03
Done.
|
| + block_to_skip.insert(alloc); |
| + ASSERT_TRUE(winheap_dump_provider->GetHeapInformation(&heap_info, |
| + block_to_skip)); |
| + EXPECT_EQ(0U, heap_info.block_count); |
| + EXPECT_EQ(0U, heap_info.allocated_size); |
| + // We can't check the committed size here, as it can depend on the version of |
| + // kernel32.dll. |
| + |
| + // Remove the allocation from the skip list and check if it's analysed |
| + // properlyly. |
| + block_to_skip.erase(block_to_skip.find(alloc)); |
|
Primiano Tucci (use gerrit)
2015/04/22 23:48:32
I think you can omit the block_to_skip.find here a
Sébastien Marchand
2015/04/23 10:52:03
Good point... Fixed.
|
| + ASSERT_TRUE(winheap_dump_provider->GetHeapInformation(&heap_info, |
| + block_to_skip)); |
| + EXPECT_EQ(1, heap_info.block_count); |
| + EXPECT_EQ(kAllocSize, heap_info.allocated_size); |
| + EXPECT_LT(kAllocSize, heap_info.committed_size); |
| + |
| + EXPECT_TRUE(::HeapFree(heap, 0, alloc)); |
| + EXPECT_EQ(TRUE, ::HeapDestroy(heap)); |
| +} |
| + |
| +} // namespace trace_event |
| +} // namespace base |