Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #include "base/file_util.h" |
| 8 | #include "base/string_util.h" |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 9 | #include "chromeos/syslog_logging.h" |
| 10 | #include "chromeos/test_helpers.h" |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 11 | #include "crash-reporter/kernel_collector.h" |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 12 | #include "gflags/gflags.h" |
| 13 | #include "gtest/gtest.h" |
| 14 | |
| 15 | static int s_crashes = 0; |
| 16 | static bool s_metrics = false; |
| 17 | |
| 18 | static const char kTestKCrash[] = "test/kcrash"; |
| 19 | static const char kTestCrashDirectory[] = "test/crash_directory"; |
| 20 | |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 21 | using chromeos::FindLog; |
| 22 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 23 | void CountCrash() { |
| 24 | ++s_crashes; |
| 25 | } |
| 26 | |
| 27 | bool IsMetrics() { |
| 28 | return s_metrics; |
| 29 | } |
| 30 | |
| 31 | class KernelCollectorTest : public ::testing::Test { |
| 32 | void SetUp() { |
| 33 | s_crashes = 0; |
| 34 | s_metrics = true; |
| 35 | collector_.Initialize(CountCrash, |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 36 | IsMetrics); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 37 | mkdir("test", 0777); |
| 38 | test_kcrash_ = FilePath(kTestKCrash); |
| 39 | collector_.OverridePreservedDumpPath(test_kcrash_); |
| 40 | unlink(kTestKCrash); |
| 41 | mkdir(kTestCrashDirectory, 0777); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 42 | chromeos::ClearLog(); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 43 | } |
| 44 | protected: |
| 45 | void WriteStringToFile(const FilePath &file_path, |
| 46 | const char *data) { |
| 47 | ASSERT_EQ(strlen(data), |
| 48 | file_util::WriteFile(file_path, data, strlen(data))); |
| 49 | } |
| 50 | |
| 51 | void SetUpSuccessfulCollect(); |
| 52 | void CheckPreservedDumpClear(); |
Simon Glass | d74cc09 | 2011-04-06 10:47:01 -0700 | [diff] [blame] | 53 | void ComputeKernelStackSignatureCommon(); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 54 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 55 | KernelCollector collector_; |
| 56 | FilePath test_kcrash_; |
| 57 | }; |
| 58 | |
Simon Glass | d74cc09 | 2011-04-06 10:47:01 -0700 | [diff] [blame] | 59 | TEST_F(KernelCollectorTest, ComputeKernelStackSignatureBase) { |
| 60 | // Make sure the normal build architecture is detected |
| 61 | EXPECT_TRUE(collector_.GetArch() != KernelCollector::archUnknown); |
| 62 | } |
| 63 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 64 | TEST_F(KernelCollectorTest, LoadPreservedDump) { |
| 65 | ASSERT_FALSE(file_util::PathExists(test_kcrash_)); |
| 66 | std::string dump; |
| 67 | ASSERT_FALSE(collector_.LoadPreservedDump(&dump)); |
| 68 | WriteStringToFile(test_kcrash_, ""); |
| 69 | ASSERT_TRUE(collector_.LoadPreservedDump(&dump)); |
| 70 | ASSERT_EQ("", dump); |
| 71 | WriteStringToFile(test_kcrash_, "something"); |
| 72 | ASSERT_TRUE(collector_.LoadPreservedDump(&dump)); |
| 73 | ASSERT_EQ("something", dump); |
| 74 | } |
| 75 | |
| 76 | TEST_F(KernelCollectorTest, EnableMissingKernel) { |
| 77 | ASSERT_FALSE(collector_.Enable()); |
| 78 | ASSERT_FALSE(collector_.IsEnabled()); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 79 | ASSERT_TRUE(FindLog( |
| 80 | "Kernel does not support crash dumping")); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 81 | ASSERT_EQ(s_crashes, 0); |
| 82 | } |
| 83 | |
| 84 | TEST_F(KernelCollectorTest, EnableOK) { |
| 85 | WriteStringToFile(test_kcrash_, ""); |
| 86 | ASSERT_TRUE(collector_.Enable()); |
| 87 | ASSERT_TRUE(collector_.IsEnabled()); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 88 | ASSERT_TRUE(FindLog("Enabling kernel crash handling")); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 89 | ASSERT_EQ(s_crashes, 0); |
| 90 | } |
| 91 | |
| 92 | TEST_F(KernelCollectorTest, ClearPreservedDump) { |
| 93 | std::string dump; |
| 94 | ASSERT_FALSE(file_util::PathExists(test_kcrash_)); |
| 95 | WriteStringToFile(test_kcrash_, "something"); |
| 96 | ASSERT_TRUE(collector_.LoadPreservedDump(&dump)); |
| 97 | ASSERT_EQ("something", dump); |
| 98 | ASSERT_TRUE(collector_.ClearPreservedDump()); |
| 99 | ASSERT_TRUE(collector_.LoadPreservedDump(&dump)); |
| 100 | ASSERT_EQ(KernelCollector::kClearingSequence, dump); |
| 101 | } |
| 102 | |
Doug Anderson | 1e6b8bd | 2011-04-07 09:40:05 -0700 | [diff] [blame^] | 103 | TEST_F(KernelCollectorTest, StripSensitiveDataBasic) { |
| 104 | // Basic tests of StripSensitiveData... |
| 105 | |
| 106 | // Make sure we work OK with a string w/ no MAC addresses. |
| 107 | const std::string kCrashWithNoMacsOrig = |
| 108 | "<7>[111566.131728] PM: Entering mem sleep\n"; |
| 109 | std::string crash_with_no_macs(kCrashWithNoMacsOrig); |
| 110 | collector_.StripSensitiveData(&crash_with_no_macs); |
| 111 | EXPECT_EQ(kCrashWithNoMacsOrig, crash_with_no_macs); |
| 112 | |
| 113 | // Make sure that we handle the case where there's nothing before/after the |
| 114 | // MAC address. |
| 115 | const std::string kJustAMacOrig = |
| 116 | "11:22:33:44:55:66"; |
| 117 | const std::string kJustAMacStripped = |
| 118 | "00:00:00:00:00:01"; |
| 119 | std::string just_a_mac(kJustAMacOrig); |
| 120 | collector_.StripSensitiveData(&just_a_mac); |
| 121 | EXPECT_EQ(kJustAMacStripped, just_a_mac); |
| 122 | |
| 123 | // Test MAC addresses crammed together to make sure it gets both of them. |
| 124 | // |
| 125 | // I'm not sure that the code does ideal on these two test cases (they don't |
| 126 | // look like two MAC addresses to me), but since we don't see them I think |
| 127 | // it's OK to behave as shown here. |
| 128 | const std::string kCrammedMacs1Orig = |
| 129 | "11:22:33:44:55:66:11:22:33:44:55:66"; |
| 130 | const std::string kCrammedMacs1Stripped = |
| 131 | "00:00:00:00:00:01:00:00:00:00:00:01"; |
| 132 | std::string crammed_macs_1(kCrammedMacs1Orig); |
| 133 | collector_.StripSensitiveData(&crammed_macs_1); |
| 134 | EXPECT_EQ(kCrammedMacs1Stripped, crammed_macs_1); |
| 135 | |
| 136 | const std::string kCrammedMacs2Orig = |
| 137 | "11:22:33:44:55:6611:22:33:44:55:66"; |
| 138 | const std::string kCrammedMacs2Stripped = |
| 139 | "00:00:00:00:00:0100:00:00:00:00:01"; |
| 140 | std::string crammed_macs_2(kCrammedMacs2Orig); |
| 141 | collector_.StripSensitiveData(&crammed_macs_2); |
| 142 | EXPECT_EQ(kCrammedMacs2Stripped, crammed_macs_2); |
| 143 | |
| 144 | // Test case-sensitiveness (we shouldn't be case-senstive). |
| 145 | const std::string kCapsMacOrig = |
| 146 | "AA:BB:CC:DD:EE:FF"; |
| 147 | const std::string kCapsMacStripped = |
| 148 | "00:00:00:00:00:01"; |
| 149 | std::string caps_mac(kCapsMacOrig); |
| 150 | collector_.StripSensitiveData(&caps_mac); |
| 151 | EXPECT_EQ(kCapsMacStripped, caps_mac); |
| 152 | |
| 153 | const std::string kLowerMacOrig = |
| 154 | "aa:bb:cc:dd:ee:ff"; |
| 155 | const std::string kLowerMacStripped = |
| 156 | "00:00:00:00:00:01"; |
| 157 | std::string lower_mac(kLowerMacOrig); |
| 158 | collector_.StripSensitiveData(&lower_mac); |
| 159 | EXPECT_EQ(kLowerMacStripped, lower_mac); |
| 160 | } |
| 161 | |
| 162 | TEST_F(KernelCollectorTest, StripSensitiveDataBulk) { |
| 163 | // Test calling StripSensitiveData w/ lots of MAC addresses in the "log". |
| 164 | |
| 165 | // Test that stripping code handles more than 256 unique MAC addresses, since |
| 166 | // that overflows past the last byte... |
| 167 | // We'll write up some code that generates 258 unique MAC addresses. Sorta |
| 168 | // cheating since the code is very similar to the current code in |
| 169 | // StripSensitiveData(), but would catch if someone changed that later. |
| 170 | std::string lotsa_macs_orig; |
| 171 | std::string lotsa_macs_stripped; |
| 172 | int i; |
| 173 | for (i = 0; i < 258; i++) { |
| 174 | lotsa_macs_orig += StringPrintf(" 11:11:11:11:%02X:%02x", |
| 175 | (i & 0xff00) >> 8, i & 0x00ff); |
| 176 | lotsa_macs_stripped += StringPrintf(" 00:00:00:00:%02X:%02x", |
| 177 | ((i+1) & 0xff00) >> 8, (i+1) & 0x00ff); |
| 178 | } |
| 179 | std::string lotsa_macs(lotsa_macs_orig); |
| 180 | collector_.StripSensitiveData(&lotsa_macs); |
| 181 | EXPECT_EQ(lotsa_macs_stripped, lotsa_macs); |
| 182 | } |
| 183 | |
| 184 | TEST_F(KernelCollectorTest, StripSensitiveDataSample) { |
| 185 | // Test calling StripSensitiveData w/ some actual lines from a real crash; |
| 186 | // included two MAC addresses (though replaced them with some bogusness). |
| 187 | const std::string kCrashWithMacsOrig = |
| 188 | "<6>[111567.195339] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES)" |
| 189 | " filtered out\n" |
| 190 | "<7>[108539.540144] wlan0: authenticate with 11:22:33:44:55:66 (try 1)\n" |
| 191 | "<7>[108539.554973] wlan0: associate with 11:22:33:44:55:66 (try 1)\n" |
| 192 | "<6>[110136.587583] usb0: register 'QCUSBNet2k' at usb-0000:00:1d.7-2," |
| 193 | " QCUSBNet Ethernet Device, 99:88:77:66:55:44\n" |
| 194 | "<7>[110964.314648] wlan0: deauthenticated from 11:22:33:44:55:66" |
| 195 | " (Reason: 6)\n" |
| 196 | "<7>[110964.325057] phy0: Removed STA 11:22:33:44:55:66\n" |
| 197 | "<7>[110964.325115] phy0: Destroyed STA 11:22:33:44:55:66\n" |
| 198 | "<6>[110969.219172] usb0: register 'QCUSBNet2k' at usb-0000:00:1d.7-2," |
| 199 | " QCUSBNet Ethernet Device, 99:88:77:66:55:44\n" |
| 200 | "<7>[111566.131728] PM: Entering mem sleep\n"; |
| 201 | const std::string kCrashWithMacsStripped = |
| 202 | "<6>[111567.195339] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES)" |
| 203 | " filtered out\n" |
| 204 | "<7>[108539.540144] wlan0: authenticate with 00:00:00:00:00:01 (try 1)\n" |
| 205 | "<7>[108539.554973] wlan0: associate with 00:00:00:00:00:01 (try 1)\n" |
| 206 | "<6>[110136.587583] usb0: register 'QCUSBNet2k' at usb-0000:00:1d.7-2," |
| 207 | " QCUSBNet Ethernet Device, 00:00:00:00:00:02\n" |
| 208 | "<7>[110964.314648] wlan0: deauthenticated from 00:00:00:00:00:01" |
| 209 | " (Reason: 6)\n" |
| 210 | "<7>[110964.325057] phy0: Removed STA 00:00:00:00:00:01\n" |
| 211 | "<7>[110964.325115] phy0: Destroyed STA 00:00:00:00:00:01\n" |
| 212 | "<6>[110969.219172] usb0: register 'QCUSBNet2k' at usb-0000:00:1d.7-2," |
| 213 | " QCUSBNet Ethernet Device, 00:00:00:00:00:02\n" |
| 214 | "<7>[111566.131728] PM: Entering mem sleep\n"; |
| 215 | std::string crash_with_macs(kCrashWithMacsOrig); |
| 216 | collector_.StripSensitiveData(&crash_with_macs); |
| 217 | EXPECT_EQ(kCrashWithMacsStripped, crash_with_macs); |
| 218 | } |
| 219 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 220 | TEST_F(KernelCollectorTest, CollectPreservedFileMissing) { |
| 221 | ASSERT_FALSE(collector_.Collect()); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 222 | ASSERT_TRUE(FindLog("Unable to read test/kcrash")); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 223 | ASSERT_EQ(0, s_crashes); |
| 224 | } |
| 225 | |
| 226 | TEST_F(KernelCollectorTest, CollectNoCrash) { |
| 227 | WriteStringToFile(test_kcrash_, ""); |
| 228 | ASSERT_FALSE(collector_.Collect()); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 229 | ASSERT_FALSE(FindLog("Collected kernel crash")); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 230 | ASSERT_EQ(0, s_crashes); |
| 231 | } |
| 232 | |
| 233 | TEST_F(KernelCollectorTest, CollectBadDirectory) { |
| 234 | WriteStringToFile(test_kcrash_, "something"); |
| 235 | ASSERT_TRUE(collector_.Collect()); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 236 | ASSERT_TRUE(FindLog( |
| 237 | "Unable to create appropriate crash directory")); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 238 | ASSERT_EQ(1, s_crashes); |
| 239 | } |
| 240 | |
| 241 | void KernelCollectorTest::SetUpSuccessfulCollect() { |
| 242 | collector_.ForceCrashDirectory(kTestCrashDirectory); |
| 243 | WriteStringToFile(test_kcrash_, "something"); |
| 244 | ASSERT_EQ(0, s_crashes); |
| 245 | } |
| 246 | |
| 247 | void KernelCollectorTest::CheckPreservedDumpClear() { |
| 248 | // Make sure the preserved dump is now clear. |
| 249 | std::string dump; |
| 250 | ASSERT_TRUE(collector_.LoadPreservedDump(&dump)); |
| 251 | ASSERT_EQ(KernelCollector::kClearingSequence, dump); |
| 252 | } |
| 253 | |
| 254 | TEST_F(KernelCollectorTest, CollectOptedOut) { |
| 255 | SetUpSuccessfulCollect(); |
| 256 | s_metrics = false; |
| 257 | ASSERT_TRUE(collector_.Collect()); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 258 | ASSERT_TRUE(FindLog("(ignoring - no consent)")); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 259 | ASSERT_EQ(0, s_crashes); |
| 260 | |
| 261 | CheckPreservedDumpClear(); |
| 262 | } |
| 263 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 264 | TEST_F(KernelCollectorTest, CollectOK) { |
| 265 | SetUpSuccessfulCollect(); |
| 266 | ASSERT_TRUE(collector_.Collect()); |
| 267 | ASSERT_EQ(1, s_crashes); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 268 | ASSERT_TRUE(FindLog("(handling)")); |
Ken Mixter | afcf808 | 2010-10-26 14:45:01 -0700 | [diff] [blame] | 269 | static const char kNamePrefix[] = "Stored kcrash to "; |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 270 | std::string log = chromeos::GetLog(); |
| 271 | size_t pos = log.find(kNamePrefix); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 272 | ASSERT_NE(std::string::npos, pos); |
| 273 | pos += strlen(kNamePrefix); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 274 | std::string filename = log.substr(pos, std::string::npos); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 275 | // Take the name up until \n |
| 276 | size_t end_pos = filename.find_first_of("\n"); |
| 277 | ASSERT_NE(std::string::npos, end_pos); |
| 278 | filename = filename.substr(0, end_pos); |
| 279 | ASSERT_EQ(0, filename.find(kTestCrashDirectory)); |
| 280 | ASSERT_TRUE(file_util::PathExists(FilePath(filename))); |
| 281 | std::string contents; |
| 282 | ASSERT_TRUE(file_util::ReadFileToString(FilePath(filename), &contents)); |
| 283 | ASSERT_EQ("something", contents); |
| 284 | |
| 285 | CheckPreservedDumpClear(); |
| 286 | } |
| 287 | |
Simon Glass | d74cc09 | 2011-04-06 10:47:01 -0700 | [diff] [blame] | 288 | // Perform tests which are common across architectures |
| 289 | void KernelCollectorTest::ComputeKernelStackSignatureCommon() { |
| 290 | std::string signature; |
| 291 | |
| 292 | const char kStackButNoPC[] = |
| 293 | "<4>[ 6066.829029] [<790340af>] __do_softirq+0xa6/0x143\n"; |
| 294 | EXPECT_TRUE( |
| 295 | collector_.ComputeKernelStackSignature(kStackButNoPC, &signature, false)); |
| 296 | EXPECT_EQ("kernel--83615F0A", signature); |
| 297 | |
| 298 | const char kMissingEverything[] = |
| 299 | "<4>[ 6066.829029] [<790340af>] ? __do_softirq+0xa6/0x143\n"; |
| 300 | EXPECT_FALSE( |
| 301 | collector_.ComputeKernelStackSignature(kMissingEverything, |
| 302 | &signature, |
| 303 | false)); |
| 304 | |
| 305 | // Long message. |
| 306 | const char kTruncatedMessage[] = |
| 307 | "<0>[ 87.485611] Kernel panic - not syncing: 01234567890123456789" |
| 308 | "01234567890123456789X\n"; |
| 309 | EXPECT_TRUE( |
| 310 | collector_.ComputeKernelStackSignature(kTruncatedMessage, |
| 311 | &signature, |
| 312 | false)); |
| 313 | EXPECT_EQ("kernel-0123456789012345678901234567890123456789-00000000", |
| 314 | signature); |
| 315 | } |
| 316 | |
| 317 | TEST_F(KernelCollectorTest, ComputeKernelStackSignatureARM) { |
| 318 | const char kBugToPanic[] = |
| 319 | "<5>[ 123.412524] Modules linked in:\n" |
| 320 | "<5>[ 123.412534] CPU: 0 Tainted: G W " |
| 321 | "(2.6.37-01030-g51cee64 #153)\n" |
| 322 | "<5>[ 123.412552] PC is at write_breakme+0xd0/0x1b4\n" |
| 323 | "<5>[ 123.412560] LR is at write_breakme+0xc8/0x1b4\n" |
| 324 | "<5>[ 123.412569] pc : [<c0058220>] lr : [<c005821c>] " |
| 325 | "psr: 60000013\n" |
| 326 | "<5>[ 123.412574] sp : f4e0ded8 ip : c04d104c fp : 000e45e0\n" |
| 327 | "<5>[ 123.412581] r10: 400ff000 r9 : f4e0c000 r8 : 00000004\n" |
| 328 | "<5>[ 123.412589] r7 : f4e0df80 r6 : f4820c80 r5 : 00000004 " |
| 329 | "r4 : f4e0dee8\n" |
| 330 | "<5>[ 123.412598] r3 : 00000000 r2 : f4e0decc r1 : c05f88a9 " |
| 331 | "r0 : 00000039\n" |
| 332 | "<5>[ 123.412608] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA " |
| 333 | "ARM Segment user\n" |
| 334 | "<5>[ 123.412617] Control: 10c53c7d Table: 34dcc04a DAC: 00000015\n" |
| 335 | "<0>[ 123.412626] Process bash (pid: 1014, stack limit = 0xf4e0c2f8)\n" |
| 336 | "<0>[ 123.412634] Stack: (0xf4e0ded8 to 0xf4e0e000)\n" |
| 337 | "<0>[ 123.412641] dec0: " |
| 338 | " f4e0dee8 c0183678\n" |
| 339 | "<0>[ 123.412654] dee0: 00000000 00000000 00677562 0000081f c06a6a78 " |
| 340 | "400ff000 f4e0dfb0 00000000\n" |
| 341 | "<0>[ 123.412666] df00: bec7ab44 000b1719 bec7ab0c c004f498 bec7a314 " |
| 342 | "c024acc8 00000001 c018359c\n" |
| 343 | "<0>[ 123.412679] df20: f4e0df34 c04d10fc f5803c80 271beb39 000e45e0 " |
| 344 | "f5803c80 c018359c c017bfe0\n" |
| 345 | "<0>[ 123.412691] df40: 00000004 f4820c80 400ff000 f4e0df80 00000004 " |
| 346 | "f4e0c000 00000000 c01383e4\n" |
| 347 | "<0>[ 123.412703] df60: f4820c80 400ff000 f4820c80 400ff000 00000000 " |
| 348 | "00000000 00000004 c0138578\n" |
| 349 | "<0>[ 123.412715] df80: 00000000 00000000 00000004 00000000 00000004 " |
| 350 | "402f95d0 00000004 00000004\n" |
| 351 | "<0>[ 123.412727] dfa0: c0054984 c00547c0 00000004 402f95d0 00000001 " |
| 352 | "400ff000 00000004 00000000\n" |
| 353 | "<0>[ 123.412739] dfc0: 00000004 402f95d0 00000004 00000004 400ff000 " |
| 354 | "000c194c bec7ab58 000e45e0\n" |
| 355 | "<0>[ 123.412751] dfe0: 00000000 bec7aad8 40232520 40284e9c 60000010 " |
| 356 | "00000001 00000000 00000000\n" |
| 357 | "<5>[ 39.496577] Backtrace:\n" |
| 358 | "<5>[ 123.412782] [<c0058220>] (__bug+0x20/0x2c) from [<c0183678>] " |
| 359 | "(write_breakme+0xdc/0x1bc)\n" |
| 360 | "<5>[ 123.412798] [<c0183678>] (write_breakme+0xdc/0x1bc) from " |
| 361 | "[<c017bfe0>] (proc_reg_write+0x88/0x9c)\n"; |
| 362 | std::string signature; |
| 363 | |
| 364 | collector_.SetArch(KernelCollector::archArm); |
| 365 | EXPECT_TRUE( |
| 366 | collector_.ComputeKernelStackSignature(kBugToPanic, &signature, false)); |
| 367 | EXPECT_EQ("kernel-write_breakme-97D3E92F", signature); |
| 368 | |
| 369 | ComputeKernelStackSignatureCommon(); |
| 370 | } |
| 371 | |
| 372 | |
| 373 | TEST_F(KernelCollectorTest, ComputeKernelStackSignatureX86) { |
Ken Mixter | afcf808 | 2010-10-26 14:45:01 -0700 | [diff] [blame] | 374 | const char kBugToPanic[] = |
| 375 | "<4>[ 6066.829029] [<79039d16>] ? run_timer_softirq+0x165/0x1e6\n" |
| 376 | "<4>[ 6066.829029] [<790340af>] ignore_old_stack+0xa6/0x143\n" |
| 377 | "<0>[ 6066.829029] EIP: [<b82d7c15>] ieee80211_stop_tx_ba_session+" |
| 378 | "0xa3/0xb5 [mac80211] SS:ESP 0068:7951febc\n" |
| 379 | "<0>[ 6066.829029] CR2: 00000000323038a7\n" |
| 380 | "<4>[ 6066.845422] ---[ end trace 12b058bb46c43500 ]---\n" |
| 381 | "<0>[ 6066.845747] Kernel panic - not syncing: Fatal exception " |
| 382 | "in interrupt\n" |
| 383 | "<0>[ 6066.846902] Call Trace:\n" |
| 384 | "<4>[ 6066.846902] [<7937a07b>] ? printk+0x14/0x19\n" |
| 385 | "<4>[ 6066.949779] [<79379fc1>] panic+0x3e/0xe4\n" |
| 386 | "<4>[ 6066.949971] [<7937c5c5>] oops_end+0x73/0x81\n" |
| 387 | "<4>[ 6066.950208] [<7901b260>] no_context+0x10d/0x117\n"; |
| 388 | std::string signature; |
Simon Glass | d74cc09 | 2011-04-06 10:47:01 -0700 | [diff] [blame] | 389 | |
| 390 | collector_.SetArch(KernelCollector::archX86); |
Ken Mixter | afcf808 | 2010-10-26 14:45:01 -0700 | [diff] [blame] | 391 | EXPECT_TRUE( |
| 392 | collector_.ComputeKernelStackSignature(kBugToPanic, &signature, false)); |
| 393 | EXPECT_EQ("kernel-ieee80211_stop_tx_ba_session-DE253569", signature); |
| 394 | |
| 395 | const char kPCButNoStack[] = |
| 396 | "<0>[ 6066.829029] EIP: [<b82d7c15>] ieee80211_stop_tx_ba_session+"; |
| 397 | EXPECT_TRUE( |
| 398 | collector_.ComputeKernelStackSignature(kPCButNoStack, &signature, false)); |
| 399 | EXPECT_EQ("kernel-ieee80211_stop_tx_ba_session-00000000", signature); |
| 400 | |
Ken Mixter | afcf808 | 2010-10-26 14:45:01 -0700 | [diff] [blame] | 401 | const char kBreakmeBug[] = |
| 402 | "<4>[ 180.492137] [<790970c6>] ? handle_mm_fault+0x67f/0x96d\n" |
| 403 | "<4>[ 180.492137] [<790dcdfe>] ? proc_reg_write+0x5f/0x73\n" |
| 404 | "<4>[ 180.492137] [<790e2224>] ? write_breakme+0x0/0x108\n" |
| 405 | "<4>[ 180.492137] [<790dcd9f>] ? proc_reg_write+0x0/0x73\n" |
| 406 | "<4>[ 180.492137] [<790ac0aa>] vfs_write+0x85/0xe4\n" |
| 407 | "<0>[ 180.492137] Code: c6 44 05 b2 00 89 d8 e8 0c ef 09 00 85 c0 75 " |
| 408 | "0b c7 00 00 00 00 00 e9 8e 00 00 00 ba e6 75 4b 79 89 d8 e8 f1 ee 09 " |
| 409 | "00 85 c0 75 04 <0f> 0b eb fe ba 58 47 49 79 89 d8 e8 dd ee 09 00 85 " |
| 410 | "c0 75 0a 68\n" |
| 411 | "<0>[ 180.492137] EIP: [<790e22a4>] write_breakme+0x80/0x108 SS:ESP " |
| 412 | "0068:aa3e9efc\n" |
| 413 | "<4>[ 180.501800] ---[ end trace 2a6b72965e1b1523 ]---\n" |
| 414 | "<0>[ 180.502026] Kernel panic - not syncing: Fatal exception\n" |
| 415 | "<4>[ 180.502026] Call Trace:\n" |
| 416 | "<4>[ 180.502806] [<79379aba>] ? printk+0x14/0x1a\n" |
| 417 | "<4>[ 180.503033] [<79379a00>] panic+0x3e/0xe4\n" |
| 418 | "<4>[ 180.503287] [<7937c005>] oops_end+0x73/0x81\n" |
| 419 | "<4>[ 180.503520] [<790055dd>] die+0x58/0x5e\n" |
| 420 | "<4>[ 180.503538] [<7937b96c>] do_trap+0x8e/0xa7\n" |
| 421 | "<4>[ 180.503555] [<79003d70>] ? do_invalid_op+0x0/0x80\n"; |
| 422 | |
| 423 | EXPECT_TRUE( |
| 424 | collector_.ComputeKernelStackSignature(kBreakmeBug, &signature, false)); |
| 425 | EXPECT_EQ("kernel-write_breakme-122AB3CD", signature); |
| 426 | |
| 427 | const char kPCLineTooOld[] = |
| 428 | "<4>[ 174.492137] [<790970c6>] ignored_function+0x67f/0x96d\n" |
| 429 | "<4>[ 175.492137] [<790970c6>] ignored_function2+0x67f/0x96d\n" |
| 430 | "<0>[ 174.492137] EIP: [<790e22a4>] write_breakme+0x80/0x108 SS:ESP " |
| 431 | "0068:aa3e9efc\n" |
| 432 | "<4>[ 180.501800] ---[ end trace 2a6b72965e1b1523 ]---\n" |
| 433 | "<4>[ 180.502026] Call Trace:\n" |
| 434 | "<0>[ 180.502026] Kernel panic - not syncing: Fatal exception\n" |
| 435 | "<4>[ 180.502806] [<79379aba>] printk+0x14/0x1a\n"; |
| 436 | |
| 437 | EXPECT_TRUE( |
| 438 | collector_.ComputeKernelStackSignature(kPCLineTooOld, &signature, false)); |
| 439 | EXPECT_EQ("kernel-Fatal exception-ED4C84FE", signature); |
| 440 | |
| 441 | // Panic without EIP line. |
| 442 | const char kExamplePanicOnly[] = |
| 443 | "<0>[ 87.485611] Kernel panic - not syncing: Testing panic\n" |
| 444 | "<4>[ 87.485630] Pid: 2825, comm: bash Tainted: G " |
| 445 | "C 2.6.32.23+drm33.10 #1\n" |
| 446 | "<4>[ 87.485639] Call Trace:\n" |
| 447 | "<4>[ 87.485660] [<8133f71d>] ? printk+0x14/0x17\n" |
| 448 | "<4>[ 87.485674] [<8133f663>] panic+0x3e/0xe4\n" |
| 449 | "<4>[ 87.485689] [<810d062e>] write_breakme+0xaa/0x124\n"; |
| 450 | EXPECT_TRUE( |
| 451 | collector_.ComputeKernelStackSignature(kExamplePanicOnly, |
| 452 | &signature, |
| 453 | false)); |
| 454 | EXPECT_EQ("kernel-Testing panic-E0FC3552", signature); |
Simon Glass | d74cc09 | 2011-04-06 10:47:01 -0700 | [diff] [blame] | 455 | ComputeKernelStackSignatureCommon(); |
Ken Mixter | afcf808 | 2010-10-26 14:45:01 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 458 | int main(int argc, char **argv) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 459 | SetUpTests(&argc, argv, false); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 460 | return RUN_ALL_TESTS(); |
| 461 | } |