Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: base/trace_event/memory_allocator_dump_unittest.cc

Issue 1717283003: tracing: Make ConvertableToTraceFormat move-only scoped_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/memory_allocator_dump.h" 5 #include "base/trace_event/memory_allocator_dump.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const MemoryAllocatorDumpGuid guid_bar_2 = mad->guid(); 121 const MemoryAllocatorDumpGuid guid_bar_2 = mad->guid();
122 ASSERT_EQ(guid_bar, guid_bar_2); 122 ASSERT_EQ(guid_bar, guid_bar_2);
123 123
124 mad.reset(new MemoryAllocatorDump("baz", nullptr)); 124 mad.reset(new MemoryAllocatorDump("baz", nullptr));
125 const MemoryAllocatorDumpGuid guid_baz = mad->guid(); 125 const MemoryAllocatorDumpGuid guid_baz = mad->guid();
126 ASSERT_NE(guid_bar, guid_baz); 126 ASSERT_NE(guid_bar, guid_baz);
127 } 127 }
128 128
129 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { 129 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) {
130 FakeMemoryAllocatorDumpProvider fmadp; 130 FakeMemoryAllocatorDumpProvider fmadp;
131 ProcessMemoryDump pmd(new MemoryDumpSessionState(nullptr, nullptr)); 131 ProcessMemoryDump pmd(new MemoryDumpSessionState);
132 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; 132 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED};
133 133
134 fmadp.OnMemoryDump(dump_args, &pmd); 134 fmadp.OnMemoryDump(dump_args, &pmd);
135 135
136 ASSERT_EQ(3u, pmd.allocator_dumps().size()); 136 ASSERT_EQ(3u, pmd.allocator_dumps().size());
137 137
138 const MemoryAllocatorDump* root_heap = 138 const MemoryAllocatorDump* root_heap =
139 pmd.GetAllocatorDump("foobar_allocator"); 139 pmd.GetAllocatorDump("foobar_allocator");
140 ASSERT_NE(nullptr, root_heap); 140 ASSERT_NE(nullptr, root_heap);
141 EXPECT_EQ("foobar_allocator", root_heap->absolute_name()); 141 EXPECT_EQ("foobar_allocator", root_heap->absolute_name());
(...skipping 18 matching lines...) Expand all
160 pmd.GetAllocatorDump("foobar_allocator/sub_heap/empty"); 160 pmd.GetAllocatorDump("foobar_allocator/sub_heap/empty");
161 ASSERT_NE(nullptr, empty_sub_heap); 161 ASSERT_NE(nullptr, empty_sub_heap);
162 EXPECT_EQ("foobar_allocator/sub_heap/empty", empty_sub_heap->absolute_name()); 162 EXPECT_EQ("foobar_allocator/sub_heap/empty", empty_sub_heap->absolute_name());
163 auto raw_attrs = empty_sub_heap->attributes_for_testing()->ToBaseValue(); 163 auto raw_attrs = empty_sub_heap->attributes_for_testing()->ToBaseValue();
164 DictionaryValue* attrs = nullptr; 164 DictionaryValue* attrs = nullptr;
165 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); 165 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
166 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameSize)); 166 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameSize));
167 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameObjectCount)); 167 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameObjectCount));
168 168
169 // Check that the AsValueInfo doesn't hit any DCHECK. 169 // Check that the AsValueInfo doesn't hit any DCHECK.
170 scoped_refptr<TracedValue> traced_value(new TracedValue()); 170 scoped_ptr<TracedValue> traced_value(new TracedValue);
171 pmd.AsValueInto(traced_value.get()); 171 pmd.AsValueInto(traced_value.get());
172 } 172 }
173 173
174 // DEATH tests are not supported in Android / iOS. 174 // DEATH tests are not supported in Android / iOS.
175 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) 175 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS)
176 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) { 176 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) {
177 FakeMemoryAllocatorDumpProvider fmadp; 177 FakeMemoryAllocatorDumpProvider fmadp;
178 ProcessMemoryDump pmd(new MemoryDumpSessionState(nullptr, nullptr)); 178 ProcessMemoryDump pmd(new MemoryDumpSessionState);
179 pmd.CreateAllocatorDump("foo_allocator"); 179 pmd.CreateAllocatorDump("foo_allocator");
180 pmd.CreateAllocatorDump("bar_allocator/heap"); 180 pmd.CreateAllocatorDump("bar_allocator/heap");
181 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); 181 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), "");
182 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); 182 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), "");
183 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); 183 ASSERT_DEATH(pmd.CreateAllocatorDump(""), "");
184 } 184 }
185 #endif 185 #endif
186 186
187 } // namespace trace_event 187 } // namespace trace_event
188 } // namespace base 188 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698