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

Side by Side Diff: base/debug/crash_logging_unittest.cc

Issue 12211080: Change crash keys to be registered with a maximum length instead of number of chunks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Link chrome_app_unittests.exe Created 7 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 | Annotate | Revision Log
« no previous file with comments | « base/debug/crash_logging.cc ('k') | chrome/chrome_common.gypi » ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/debug/crash_logging.h" 5 #include "base/debug/crash_logging.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 27 matching lines...) Expand all
38 (*key_values_)[key.as_string()] = value.as_string(); 38 (*key_values_)[key.as_string()] = value.as_string();
39 } 39 }
40 40
41 static void ClearKeyValue(const base::StringPiece& key) { 41 static void ClearKeyValue(const base::StringPiece& key) {
42 key_values_->erase(key.as_string()); 42 key_values_->erase(key.as_string());
43 } 43 }
44 }; 44 };
45 45
46 TEST_F(CrashLoggingTest, SetClearSingle) { 46 TEST_F(CrashLoggingTest, SetClearSingle) {
47 const char* kTestKey = "test-key"; 47 const char* kTestKey = "test-key";
48 base::debug::CrashKey keys[] = { { kTestKey, 1 } }; 48 base::debug::CrashKey keys[] = { { kTestKey, 255 } };
49 base::debug::InitCrashKeys(keys, arraysize(keys), 255); 49 base::debug::InitCrashKeys(keys, arraysize(keys), 255);
50 50
51 base::debug::SetCrashKeyValue(kTestKey, "value"); 51 base::debug::SetCrashKeyValue(kTestKey, "value");
52 EXPECT_EQ("value", (*key_values_)[kTestKey]); 52 EXPECT_EQ("value", (*key_values_)[kTestKey]);
53 53
54 base::debug::ClearCrashKey(kTestKey); 54 base::debug::ClearCrashKey(kTestKey);
55 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey)); 55 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey));
56 } 56 }
57 57
58 TEST_F(CrashLoggingTest, SetChunked) { 58 TEST_F(CrashLoggingTest, SetChunked) {
59 const char* kTestKey = "chunky"; 59 const char* kTestKey = "chunky";
60 const char* kChunk1 = "chunky-1"; 60 const char* kChunk1 = "chunky-1";
61 const char* kChunk2 = "chunky-2"; 61 const char* kChunk2 = "chunky-2";
62 const char* kChunk3 = "chunky-3"; 62 const char* kChunk3 = "chunky-3";
63 base::debug::CrashKey keys[] = { { kTestKey, 3 } }; 63 base::debug::CrashKey keys[] = { { kTestKey, 15 } };
64 base::debug::InitCrashKeys(keys, arraysize(keys), 5); 64 base::debug::InitCrashKeys(keys, arraysize(keys), 5);
65 65
66 std::map<std::string, std::string>& values = *key_values_; 66 std::map<std::string, std::string>& values = *key_values_;
67 67
68 // Fill only the first chunk. 68 // Fill only the first chunk.
69 base::debug::SetCrashKeyValue(kTestKey, "foo"); 69 base::debug::SetCrashKeyValue(kTestKey, "foo");
70 EXPECT_EQ(1u, values.size()); 70 EXPECT_EQ(1u, values.size());
71 EXPECT_EQ("foo", values[kChunk1]); 71 EXPECT_EQ("foo", values[kChunk1]);
72 EXPECT_TRUE(values.end() == values.find(kChunk2)); 72 EXPECT_TRUE(values.end() == values.find(kChunk2));
73 EXPECT_TRUE(values.end() == values.find(kChunk3)); 73 EXPECT_TRUE(values.end() == values.find(kChunk3));
74 74
75 // Fill all three chunks with truncation. 75 // Fill three chunks with truncation (max length is 15, this string is 20).
76 base::debug::SetCrashKeyValue(kTestKey, "five four three two"); 76 base::debug::SetCrashKeyValue(kTestKey, "five four three two");
77 EXPECT_EQ(3u, values.size()); 77 EXPECT_EQ(3u, values.size());
78 EXPECT_EQ("five ", values[kChunk1]); 78 EXPECT_EQ("five ", values[kChunk1]);
79 EXPECT_EQ("four ", values[kChunk2]); 79 EXPECT_EQ("four ", values[kChunk2]);
80 EXPECT_EQ("three", values[kChunk3]); 80 EXPECT_EQ("three", values[kChunk3]);
81 81
82 // Clear everything. 82 // Clear everything.
83 base::debug::ClearCrashKey(kTestKey); 83 base::debug::ClearCrashKey(kTestKey);
84 EXPECT_EQ(0u, values.size()); 84 EXPECT_EQ(0u, values.size());
85 EXPECT_TRUE(values.end() == values.find(kChunk1)); 85 EXPECT_TRUE(values.end() == values.find(kChunk1));
(...skipping 12 matching lines...) Expand all
98 // Clear everything. 98 // Clear everything.
99 base::debug::ClearCrashKey(kTestKey); 99 base::debug::ClearCrashKey(kTestKey);
100 EXPECT_EQ(0u, values.size()); 100 EXPECT_EQ(0u, values.size());
101 EXPECT_TRUE(values.end() == values.find(kChunk1)); 101 EXPECT_TRUE(values.end() == values.find(kChunk1));
102 EXPECT_TRUE(values.end() == values.find(kChunk2)); 102 EXPECT_TRUE(values.end() == values.find(kChunk2));
103 EXPECT_TRUE(values.end() == values.find(kChunk3)); 103 EXPECT_TRUE(values.end() == values.find(kChunk3));
104 } 104 }
105 105
106 TEST_F(CrashLoggingTest, ScopedCrashKey) { 106 TEST_F(CrashLoggingTest, ScopedCrashKey) {
107 const char* kTestKey = "test-key"; 107 const char* kTestKey = "test-key";
108 base::debug::CrashKey keys[] = { { kTestKey, 1 } }; 108 base::debug::CrashKey keys[] = { { kTestKey, 255 } };
109 base::debug::InitCrashKeys(keys, arraysize(keys), 255); 109 base::debug::InitCrashKeys(keys, arraysize(keys), 255);
110 110
111 EXPECT_EQ(0u, key_values_->size()); 111 EXPECT_EQ(0u, key_values_->size());
112 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey)); 112 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey));
113 { 113 {
114 base::debug::ScopedCrashKey scoped_crash_key(kTestKey, "value"); 114 base::debug::ScopedCrashKey scoped_crash_key(kTestKey, "value");
115 EXPECT_EQ("value", (*key_values_)[kTestKey]); 115 EXPECT_EQ("value", (*key_values_)[kTestKey]);
116 EXPECT_EQ(1u, key_values_->size()); 116 EXPECT_EQ(1u, key_values_->size());
117 } 117 }
118 EXPECT_EQ(0u, key_values_->size()); 118 EXPECT_EQ(0u, key_values_->size());
119 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey)); 119 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey));
120 } 120 }
121 121
122 TEST_F(CrashLoggingTest, InitSize) { 122 TEST_F(CrashLoggingTest, InitSize) {
123 base::debug::CrashKey keys[] = { 123 base::debug::CrashKey keys[] = {
124 { "chunked-3", 3 }, 124 { "chunked-3", 15 },
125 { "single", 1 }, 125 { "single", 5 },
126 { "chunked-6", 6 }, 126 { "chunked-6", 30 },
127 }; 127 };
128 128
129 size_t num_keys = base::debug::InitCrashKeys(keys, arraysize(keys), 255); 129 size_t num_keys = base::debug::InitCrashKeys(keys, arraysize(keys), 5);
130 130
131 EXPECT_EQ(10u, num_keys); 131 EXPECT_EQ(10u, num_keys);
132 132
133 EXPECT_TRUE(base::debug::LookupCrashKey("chunked-3")); 133 EXPECT_TRUE(base::debug::LookupCrashKey("chunked-3"));
134 EXPECT_TRUE(base::debug::LookupCrashKey("single")); 134 EXPECT_TRUE(base::debug::LookupCrashKey("single"));
135 EXPECT_TRUE(base::debug::LookupCrashKey("chunked-6")); 135 EXPECT_TRUE(base::debug::LookupCrashKey("chunked-6"));
136 EXPECT_FALSE(base::debug::LookupCrashKey("chunked-6-4")); 136 EXPECT_FALSE(base::debug::LookupCrashKey("chunked-6-4"));
137 } 137 }
138 138
139 TEST_F(CrashLoggingTest, ChunkValue) { 139 TEST_F(CrashLoggingTest, ChunkValue) {
140 using base::debug::ChunkCrashKeyValue; 140 using base::debug::ChunkCrashKeyValue;
141 141
142 // Test truncation. 142 // Test truncation.
143 base::debug::CrashKey key = { "chunky", 1 }; 143 base::debug::CrashKey key = { "chunky", 10 };
144 std::vector<std::string> results = 144 std::vector<std::string> results =
145 ChunkCrashKeyValue(key, "hello world", 10); 145 ChunkCrashKeyValue(key, "hello world", 64);
146 ASSERT_EQ(1u, results.size()); 146 ASSERT_EQ(1u, results.size());
147 EXPECT_EQ("hello worl", results[0]); 147 EXPECT_EQ("hello worl", results[0]);
148 148
149 // Test short string. 149 // Test short string.
150 results = ChunkCrashKeyValue(key, "hi", 10); 150 results = ChunkCrashKeyValue(key, "hi", 10);
151 ASSERT_EQ(1u, results.size()); 151 ASSERT_EQ(1u, results.size());
152 EXPECT_EQ("hi", results[0]); 152 EXPECT_EQ("hi", results[0]);
153 153
154 // Test chunk pair. 154 // Test chunk pair.
155 key.num_chunks = 2; 155 key.max_length = 6;
156 results = ChunkCrashKeyValue(key, "foobar", 3); 156 results = ChunkCrashKeyValue(key, "foobar", 3);
157 ASSERT_EQ(2u, results.size()); 157 ASSERT_EQ(2u, results.size());
158 EXPECT_EQ("foo", results[0]); 158 EXPECT_EQ("foo", results[0]);
159 EXPECT_EQ("bar", results[1]); 159 EXPECT_EQ("bar", results[1]);
160 160
161 // Test chunk pair truncation. 161 // Test chunk pair truncation.
162 results = ChunkCrashKeyValue(key, "foobared", 3); 162 results = ChunkCrashKeyValue(key, "foobared", 3);
163 ASSERT_EQ(2u, results.size()); 163 ASSERT_EQ(2u, results.size());
164 EXPECT_EQ("foo", results[0]); 164 EXPECT_EQ("foo", results[0]);
165 EXPECT_EQ("bar", results[1]); 165 EXPECT_EQ("bar", results[1]);
166 166
167 // Test extra chunks. 167 // Test extra chunks.
168 key.num_chunks = 100; 168 key.max_length = 100;
169 results = ChunkCrashKeyValue(key, "hello world", 3); 169 results = ChunkCrashKeyValue(key, "hello world", 3);
170 ASSERT_EQ(4u, results.size()); 170 ASSERT_EQ(4u, results.size());
171 EXPECT_EQ("hel", results[0]); 171 EXPECT_EQ("hel", results[0]);
172 EXPECT_EQ("lo ", results[1]); 172 EXPECT_EQ("lo ", results[1]);
173 EXPECT_EQ("wor", results[2]); 173 EXPECT_EQ("wor", results[2]);
174 EXPECT_EQ("ld", results[3]); 174 EXPECT_EQ("ld", results[3]);
175 } 175 }
176
177 TEST_F(CrashLoggingTest, ChunkRounding) {
178 // If max_length=12 and max_chunk_length=5, there should be 3 chunks,
179 // not 2.
180 base::debug::CrashKey key = { "round", 12 };
181 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5));
182 }
OLDNEW
« no previous file with comments | « base/debug/crash_logging.cc ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698