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

Side by Side Diff: kernel_collector_test.cc

Issue 4018008: crash-reporter: Generate kernel crash signatures for server-side grouping of similar crashes (Closed) Base URL: http://git.chromium.org/git/crash-reporter.git
Patch Set: Respond to petkov review Created 10 years, 1 month 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 | « kernel_collector.cc ('k') | no next file » | 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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <unistd.h> 5 #include <unistd.h>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "crash-reporter/kernel_collector.h" 9 #include "crash-reporter/kernel_collector.h"
10 #include "crash-reporter/system_logging_mock.h" 10 #include "crash-reporter/system_logging_mock.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // Make sure the preserved dump is now clear. 128 // Make sure the preserved dump is now clear.
129 std::string dump; 129 std::string dump;
130 ASSERT_TRUE(collector_.LoadPreservedDump(&dump)); 130 ASSERT_TRUE(collector_.LoadPreservedDump(&dump));
131 ASSERT_EQ(KernelCollector::kClearingSequence, dump); 131 ASSERT_EQ(KernelCollector::kClearingSequence, dump);
132 } 132 }
133 133
134 TEST_F(KernelCollectorTest, CollectOptedOut) { 134 TEST_F(KernelCollectorTest, CollectOptedOut) {
135 SetUpSuccessfulCollect(); 135 SetUpSuccessfulCollect();
136 s_metrics = false; 136 s_metrics = false;
137 ASSERT_TRUE(collector_.Collect()); 137 ASSERT_TRUE(collector_.Collect());
138 ASSERT_NE(std::string::npos, 138 ASSERT_NE(std::string::npos, logging_.log().find("(ignoring)"));
139 logging_.log().find("Crash not saved since metrics disabled"));
140 ASSERT_EQ(0, s_crashes); 139 ASSERT_EQ(0, s_crashes);
141 140
142 CheckPreservedDumpClear(); 141 CheckPreservedDumpClear();
143 } 142 }
144 143
145
146 TEST_F(KernelCollectorTest, CollectOK) { 144 TEST_F(KernelCollectorTest, CollectOK) {
147 SetUpSuccessfulCollect(); 145 SetUpSuccessfulCollect();
148 ASSERT_TRUE(collector_.Collect()); 146 ASSERT_TRUE(collector_.Collect());
149 ASSERT_EQ(1, s_crashes); 147 ASSERT_EQ(1, s_crashes);
150 static const char kNamePrefix[] = "Collected kernel crash diagnostics into "; 148 ASSERT_NE(std::string::npos, logging_.log().find("(handling)"));
149 static const char kNamePrefix[] = "Stored kcrash to ";
151 size_t pos = logging_.log().find(kNamePrefix); 150 size_t pos = logging_.log().find(kNamePrefix);
152 ASSERT_NE(std::string::npos, pos); 151 ASSERT_NE(std::string::npos, pos);
153 pos += strlen(kNamePrefix); 152 pos += strlen(kNamePrefix);
154 std::string filename = logging_.log().substr(pos, std::string::npos); 153 std::string filename = logging_.log().substr(pos, std::string::npos);
155 // Take the name up until \n 154 // Take the name up until \n
156 size_t end_pos = filename.find_first_of("\n"); 155 size_t end_pos = filename.find_first_of("\n");
157 ASSERT_NE(std::string::npos, end_pos); 156 ASSERT_NE(std::string::npos, end_pos);
158 filename = filename.substr(0, end_pos); 157 filename = filename.substr(0, end_pos);
159 ASSERT_EQ(0, filename.find(kTestCrashDirectory)); 158 ASSERT_EQ(0, filename.find(kTestCrashDirectory));
160 ASSERT_TRUE(file_util::PathExists(FilePath(filename))); 159 ASSERT_TRUE(file_util::PathExists(FilePath(filename)));
161 std::string contents; 160 std::string contents;
162 ASSERT_TRUE(file_util::ReadFileToString(FilePath(filename), &contents)); 161 ASSERT_TRUE(file_util::ReadFileToString(FilePath(filename), &contents));
163 ASSERT_EQ("something", contents); 162 ASSERT_EQ("something", contents);
164 163
165 CheckPreservedDumpClear(); 164 CheckPreservedDumpClear();
166 } 165 }
167 166
167 TEST_F(KernelCollectorTest, ComputeKernelStackSignature) {
168 const char kBugToPanic[] =
169 "<4>[ 6066.829029] [<79039d16>] ? run_timer_softirq+0x165/0x1e6\n"
170 "<4>[ 6066.829029] [<790340af>] ignore_old_stack+0xa6/0x143\n"
171 "<0>[ 6066.829029] EIP: [<b82d7c15>] ieee80211_stop_tx_ba_session+"
172 "0xa3/0xb5 [mac80211] SS:ESP 0068:7951febc\n"
173 "<0>[ 6066.829029] CR2: 00000000323038a7\n"
174 "<4>[ 6066.845422] ---[ end trace 12b058bb46c43500 ]---\n"
175 "<0>[ 6066.845747] Kernel panic - not syncing: Fatal exception "
176 "in interrupt\n"
177 "<0>[ 6066.846902] Call Trace:\n"
178 "<4>[ 6066.846902] [<7937a07b>] ? printk+0x14/0x19\n"
179 "<4>[ 6066.949779] [<79379fc1>] panic+0x3e/0xe4\n"
180 "<4>[ 6066.949971] [<7937c5c5>] oops_end+0x73/0x81\n"
181 "<4>[ 6066.950208] [<7901b260>] no_context+0x10d/0x117\n";
182 std::string signature;
183 EXPECT_TRUE(
184 collector_.ComputeKernelStackSignature(kBugToPanic, &signature, false));
185 EXPECT_EQ("kernel-ieee80211_stop_tx_ba_session-DE253569", signature);
186
187 const char kPCButNoStack[] =
188 "<0>[ 6066.829029] EIP: [<b82d7c15>] ieee80211_stop_tx_ba_session+";
189 EXPECT_TRUE(
190 collector_.ComputeKernelStackSignature(kPCButNoStack, &signature, false));
191 EXPECT_EQ("kernel-ieee80211_stop_tx_ba_session-00000000", signature);
192
193 const char kStackButNoPC[] =
194 "<4>[ 6066.829029] [<790340af>] __do_softirq+0xa6/0x143\n";
195 EXPECT_TRUE(
196 collector_.ComputeKernelStackSignature(kStackButNoPC, &signature, false));
197 EXPECT_EQ("kernel--83615F0A", signature);
198
199 const char kMissingEverything[] =
200 "<4>[ 6066.829029] [<790340af>] ? __do_softirq+0xa6/0x143\n";
201 EXPECT_FALSE(
202 collector_.ComputeKernelStackSignature(kMissingEverything,
203 &signature,
204 false));
205
206 const char kBreakmeBug[] =
207 "<4>[ 180.492137] [<790970c6>] ? handle_mm_fault+0x67f/0x96d\n"
208 "<4>[ 180.492137] [<790dcdfe>] ? proc_reg_write+0x5f/0x73\n"
209 "<4>[ 180.492137] [<790e2224>] ? write_breakme+0x0/0x108\n"
210 "<4>[ 180.492137] [<790dcd9f>] ? proc_reg_write+0x0/0x73\n"
211 "<4>[ 180.492137] [<790ac0aa>] vfs_write+0x85/0xe4\n"
212 "<0>[ 180.492137] Code: c6 44 05 b2 00 89 d8 e8 0c ef 09 00 85 c0 75 "
213 "0b c7 00 00 00 00 00 e9 8e 00 00 00 ba e6 75 4b 79 89 d8 e8 f1 ee 09 "
214 "00 85 c0 75 04 <0f> 0b eb fe ba 58 47 49 79 89 d8 e8 dd ee 09 00 85 "
215 "c0 75 0a 68\n"
216 "<0>[ 180.492137] EIP: [<790e22a4>] write_breakme+0x80/0x108 SS:ESP "
217 "0068:aa3e9efc\n"
218 "<4>[ 180.501800] ---[ end trace 2a6b72965e1b1523 ]---\n"
219 "<0>[ 180.502026] Kernel panic - not syncing: Fatal exception\n"
220 "<4>[ 180.502026] Call Trace:\n"
221 "<4>[ 180.502806] [<79379aba>] ? printk+0x14/0x1a\n"
222 "<4>[ 180.503033] [<79379a00>] panic+0x3e/0xe4\n"
223 "<4>[ 180.503287] [<7937c005>] oops_end+0x73/0x81\n"
224 "<4>[ 180.503520] [<790055dd>] die+0x58/0x5e\n"
225 "<4>[ 180.503538] [<7937b96c>] do_trap+0x8e/0xa7\n"
226 "<4>[ 180.503555] [<79003d70>] ? do_invalid_op+0x0/0x80\n";
227
228 EXPECT_TRUE(
229 collector_.ComputeKernelStackSignature(kBreakmeBug, &signature, false));
230 EXPECT_EQ("kernel-write_breakme-122AB3CD", signature);
231
232 const char kPCLineTooOld[] =
233 "<4>[ 174.492137] [<790970c6>] ignored_function+0x67f/0x96d\n"
234 "<4>[ 175.492137] [<790970c6>] ignored_function2+0x67f/0x96d\n"
235 "<0>[ 174.492137] EIP: [<790e22a4>] write_breakme+0x80/0x108 SS:ESP "
236 "0068:aa3e9efc\n"
237 "<4>[ 180.501800] ---[ end trace 2a6b72965e1b1523 ]---\n"
238 "<4>[ 180.502026] Call Trace:\n"
239 "<0>[ 180.502026] Kernel panic - not syncing: Fatal exception\n"
240 "<4>[ 180.502806] [<79379aba>] printk+0x14/0x1a\n";
241
242 EXPECT_TRUE(
243 collector_.ComputeKernelStackSignature(kPCLineTooOld, &signature, false));
244 EXPECT_EQ("kernel-Fatal exception-ED4C84FE", signature);
245
246 // Panic without EIP line.
247 const char kExamplePanicOnly[] =
248 "<0>[ 87.485611] Kernel panic - not syncing: Testing panic\n"
249 "<4>[ 87.485630] Pid: 2825, comm: bash Tainted: G "
250 "C 2.6.32.23+drm33.10 #1\n"
251 "<4>[ 87.485639] Call Trace:\n"
252 "<4>[ 87.485660] [<8133f71d>] ? printk+0x14/0x17\n"
253 "<4>[ 87.485674] [<8133f663>] panic+0x3e/0xe4\n"
254 "<4>[ 87.485689] [<810d062e>] write_breakme+0xaa/0x124\n";
255 EXPECT_TRUE(
256 collector_.ComputeKernelStackSignature(kExamplePanicOnly,
257 &signature,
258 false));
259 EXPECT_EQ("kernel-Testing panic-E0FC3552", signature);
260
261 // Long message.
262 const char kTruncatedMessage[] =
263 "<0>[ 87.485611] Kernel panic - not syncing: 01234567890123456789"
264 "01234567890123456789X\n";
265 EXPECT_TRUE(
266 collector_.ComputeKernelStackSignature(kTruncatedMessage,
267 &signature,
268 false));
269 EXPECT_EQ("kernel-0123456789012345678901234567890123456789-00000000",
270 signature);
271
272 }
273
168 int main(int argc, char **argv) { 274 int main(int argc, char **argv) {
169 ::testing::InitGoogleTest(&argc, argv); 275 ::testing::InitGoogleTest(&argc, argv);
170 return RUN_ALL_TESTS(); 276 return RUN_ALL_TESTS();
171 } 277 }
OLDNEW
« no previous file with comments | « kernel_collector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698