Chromium Code Reviews| 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/process_memory_dump.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/trace_event/trace_event_argument.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace base { | |
| 12 namespace trace_event { | |
| 13 | |
| 14 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { | |
| 15 scoped_refptr<TracedValue> traced_value(new TracedValue()); | |
| 16 | |
| 17 scoped_ptr<ProcessMemoryDump> pmd1(new ProcessMemoryDump(nullptr)); | |
| 18 pmd1->CreateAllocatorDump("pmd1/mad1"); | |
| 19 pmd1->CreateAllocatorDump("pmd1/mad2"); | |
| 20 | |
| 21 scoped_ptr<ProcessMemoryDump> pmd2(new ProcessMemoryDump(nullptr)); | |
| 22 pmd2->CreateAllocatorDump("pmd2/mad1"); | |
| 23 pmd2->CreateAllocatorDump("pmd2/mad2"); | |
| 24 | |
| 25 pmd1->TakeAllDumpsFrom(pmd2.get()); | |
| 26 | |
| 27 // Make sure that pmd2 is empty but still usable after it has been emptied. | |
| 28 ASSERT_TRUE(pmd2->allocator_dumps().empty()); | |
| 29 pmd2->CreateAllocatorDump("pmd2/this_mad_stays_with_pmd2"); | |
| 30 ASSERT_EQ(1u, pmd2->allocator_dumps().size()); | |
| 31 ASSERT_EQ(1u, pmd2->allocator_dumps().count("pmd2/this_mad_stays_with_pmd2")); | |
| 32 | |
| 33 // Check that the AsValueInto doesn't cause a crash. | |
| 34 pmd2->AsValueInto(traced_value.get()); | |
| 35 | |
| 36 // Free the |pmd2| to check that the memory ownership of the two MAD(s) is | |
|
petrcermak
2015/05/21 08:17:38
nit: s/is/has been/
P.S. I don't think you need t
Primiano Tucci (use gerrit)
2015/05/21 08:33:46
Done
| |
| 37 // effectively moved to |pmd1|. | |
| 38 pmd2.reset(); | |
| 39 | |
| 40 // Now check that |pmd1| has been effectively merged. | |
| 41 ASSERT_EQ(4u, pmd1->allocator_dumps().size()); | |
| 42 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad1")); | |
| 43 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); | |
| 44 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd2/mad1")); | |
| 45 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); | |
| 46 | |
| 47 // Check that the AsValueInto doesn't cause a crash. | |
| 48 traced_value = new TracedValue(); | |
| 49 pmd1->AsValueInto(traced_value.get()); | |
| 50 | |
| 51 pmd1.reset(); | |
| 52 } | |
| 53 | |
| 54 } // namespace trace_event | |
| 55 } // namespace base | |
| OLD | NEW |