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

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

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/trace_event/memory_allocator_dump.h ('k') | base/trace_event/memory_dump_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 MemoryAllocatorDump::kUnitsObjects, 3); 45 MemoryAllocatorDump::kUnitsObjects, 3);
46 46
47 pmd->CreateAllocatorDump("foobar_allocator/sub_heap/empty"); 47 pmd->CreateAllocatorDump("foobar_allocator/sub_heap/empty");
48 // Leave the rest of sub heap deliberately uninitialized, to check that 48 // Leave the rest of sub heap deliberately uninitialized, to check that
49 // CreateAllocatorDump returns a properly zero-initialized object. 49 // CreateAllocatorDump returns a properly zero-initialized object.
50 50
51 return true; 51 return true;
52 } 52 }
53 }; 53 };
54 54
55 scoped_ptr<Value> CheckAttribute(const MemoryAllocatorDump* dump, 55 std::unique_ptr<Value> CheckAttribute(const MemoryAllocatorDump* dump,
56 const std::string& name, 56 const std::string& name,
57 const char* expected_type, 57 const char* expected_type,
58 const char* expected_units) { 58 const char* expected_units) {
59 scoped_ptr<Value> raw_attrs = dump->attributes_for_testing()->ToBaseValue(); 59 std::unique_ptr<Value> raw_attrs =
60 dump->attributes_for_testing()->ToBaseValue();
60 DictionaryValue* args = nullptr; 61 DictionaryValue* args = nullptr;
61 DictionaryValue* arg = nullptr; 62 DictionaryValue* arg = nullptr;
62 std::string arg_value; 63 std::string arg_value;
63 const Value* out_value = nullptr; 64 const Value* out_value = nullptr;
64 EXPECT_TRUE(raw_attrs->GetAsDictionary(&args)); 65 EXPECT_TRUE(raw_attrs->GetAsDictionary(&args));
65 EXPECT_TRUE(args->GetDictionary(name, &arg)); 66 EXPECT_TRUE(args->GetDictionary(name, &arg));
66 EXPECT_TRUE(arg->GetString("type", &arg_value)); 67 EXPECT_TRUE(arg->GetString("type", &arg_value));
67 EXPECT_EQ(expected_type, arg_value); 68 EXPECT_EQ(expected_type, arg_value);
68 EXPECT_TRUE(arg->GetString("units", &arg_value)); 69 EXPECT_TRUE(arg->GetString("units", &arg_value));
69 EXPECT_EQ(expected_units, arg_value); 70 EXPECT_EQ(expected_units, arg_value);
70 EXPECT_TRUE(arg->Get("value", &out_value)); 71 EXPECT_TRUE(arg->Get("value", &out_value));
71 return out_value ? out_value->CreateDeepCopy() : scoped_ptr<Value>(); 72 return out_value ? out_value->CreateDeepCopy() : std::unique_ptr<Value>();
72 } 73 }
73 74
74 void CheckString(const MemoryAllocatorDump* dump, 75 void CheckString(const MemoryAllocatorDump* dump,
75 const std::string& name, 76 const std::string& name,
76 const char* expected_type, 77 const char* expected_type,
77 const char* expected_units, 78 const char* expected_units,
78 const std::string& expected_value) { 79 const std::string& expected_value) {
79 std::string attr_str_value; 80 std::string attr_str_value;
80 auto attr_value = CheckAttribute(dump, name, expected_type, expected_units); 81 auto attr_value = CheckAttribute(dump, name, expected_type, expected_units);
81 EXPECT_TRUE(attr_value->GetAsString(&attr_str_value)); 82 EXPECT_TRUE(attr_value->GetAsString(&attr_str_value));
(...skipping 15 matching lines...) Expand all
97 auto attr_value = CheckAttribute(dump, name, MemoryAllocatorDump::kTypeScalar, 98 auto attr_value = CheckAttribute(dump, name, MemoryAllocatorDump::kTypeScalar,
98 expected_units); 99 expected_units);
99 double attr_double_value; 100 double attr_double_value;
100 EXPECT_TRUE(attr_value->GetAsDouble(&attr_double_value)); 101 EXPECT_TRUE(attr_value->GetAsDouble(&attr_double_value));
101 EXPECT_EQ(expected_value, attr_double_value); 102 EXPECT_EQ(expected_value, attr_double_value);
102 } 103 }
103 104
104 } // namespace 105 } // namespace
105 106
106 TEST(MemoryAllocatorDumpTest, GuidGeneration) { 107 TEST(MemoryAllocatorDumpTest, GuidGeneration) {
107 scoped_ptr<MemoryAllocatorDump> mad( 108 std::unique_ptr<MemoryAllocatorDump> mad(
108 new MemoryAllocatorDump("foo", nullptr, MemoryAllocatorDumpGuid(0x42u))); 109 new MemoryAllocatorDump("foo", nullptr, MemoryAllocatorDumpGuid(0x42u)));
109 ASSERT_EQ("42", mad->guid().ToString()); 110 ASSERT_EQ("42", mad->guid().ToString());
110 111
111 // If the dumper does not provide a Guid, the MAD will make one up on the 112 // If the dumper does not provide a Guid, the MAD will make one up on the
112 // flight. Furthermore that Guid will stay stable across across multiple 113 // flight. Furthermore that Guid will stay stable across across multiple
113 // snapshots if the |absolute_name| of the dump doesn't change 114 // snapshots if the |absolute_name| of the dump doesn't change
114 mad.reset(new MemoryAllocatorDump("bar", nullptr)); 115 mad.reset(new MemoryAllocatorDump("bar", nullptr));
115 const MemoryAllocatorDumpGuid guid_bar = mad->guid(); 116 const MemoryAllocatorDumpGuid guid_bar = mad->guid();
116 ASSERT_FALSE(guid_bar.empty()); 117 ASSERT_FALSE(guid_bar.empty());
117 ASSERT_FALSE(guid_bar.ToString().empty()); 118 ASSERT_FALSE(guid_bar.ToString().empty());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 pmd.GetAllocatorDump("foobar_allocator/sub_heap/empty"); 161 pmd.GetAllocatorDump("foobar_allocator/sub_heap/empty");
161 ASSERT_NE(nullptr, empty_sub_heap); 162 ASSERT_NE(nullptr, empty_sub_heap);
162 EXPECT_EQ("foobar_allocator/sub_heap/empty", empty_sub_heap->absolute_name()); 163 EXPECT_EQ("foobar_allocator/sub_heap/empty", empty_sub_heap->absolute_name());
163 auto raw_attrs = empty_sub_heap->attributes_for_testing()->ToBaseValue(); 164 auto raw_attrs = empty_sub_heap->attributes_for_testing()->ToBaseValue();
164 DictionaryValue* attrs = nullptr; 165 DictionaryValue* attrs = nullptr;
165 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); 166 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
166 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameSize)); 167 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameSize));
167 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameObjectCount)); 168 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameObjectCount));
168 169
169 // Check that the AsValueInfo doesn't hit any DCHECK. 170 // Check that the AsValueInfo doesn't hit any DCHECK.
170 scoped_ptr<TracedValue> traced_value(new TracedValue); 171 std::unique_ptr<TracedValue> traced_value(new TracedValue);
171 pmd.AsValueInto(traced_value.get()); 172 pmd.AsValueInto(traced_value.get());
172 } 173 }
173 174
174 // DEATH tests are not supported in Android / iOS. 175 // DEATH tests are not supported in Android / iOS.
175 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) 176 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS)
176 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) { 177 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) {
177 FakeMemoryAllocatorDumpProvider fmadp; 178 FakeMemoryAllocatorDumpProvider fmadp;
178 ProcessMemoryDump pmd(new MemoryDumpSessionState); 179 ProcessMemoryDump pmd(new MemoryDumpSessionState);
179 pmd.CreateAllocatorDump("foo_allocator"); 180 pmd.CreateAllocatorDump("foo_allocator");
180 pmd.CreateAllocatorDump("bar_allocator/heap"); 181 pmd.CreateAllocatorDump("bar_allocator/heap");
181 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); 182 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), "");
182 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); 183 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), "");
183 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); 184 ASSERT_DEATH(pmd.CreateAllocatorDump(""), "");
184 } 185 }
185 #endif 186 #endif
186 187
187 } // namespace trace_event 188 } // namespace trace_event
188 } // namespace base 189 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_allocator_dump.h ('k') | base/trace_event/memory_dump_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698