OLD | NEW |
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 import logging, os, re | 5 import logging, os, re |
6 from autotest_lib.client.bin import site_crash_test, site_log_reader, \ | 6 from autotest_lib.client.bin import site_crash_test, site_log_reader, \ |
7 site_utils, test | 7 site_utils, test |
8 from autotest_lib.client.common_lib import error, utils | 8 from autotest_lib.client.common_lib import error, utils |
9 | 9 |
10 | 10 |
11 _KCRASH_FILE = '/sys/kernel/debug/preserved/kcrash' | 11 _KCRASH_FILE = '/sys/kernel/debug/preserved/kcrash' |
12 | 12 |
13 | 13 |
14 class logging_KernelCrash(site_crash_test.CrashTest): | 14 class logging_KernelCrash(site_crash_test.CrashTest): |
15 version = 1 | 15 version = 1 |
16 | 16 |
17 | 17 |
18 def _test_reporter_startup(self): | 18 def _test_reporter_startup(self): |
19 """Test that the crash_reporter is handling kernel crashes.""" | 19 """Test that the crash_reporter is handling kernel crashes.""" |
20 if not self._log_reader.can_find('Enabling kernel crash handling'): | 20 if not self._log_reader.can_find('Enabling kernel crash handling'): |
21 if not self._log_reader.can_find( | 21 if not self._log_reader.can_find( |
22 'Kernel does not support crash dumping'): | 22 'Kernel does not support crash dumping'): |
23 raise error.TestFail( | 23 raise error.TestFail( |
24 'Could not find kernel crash found message') | 24 'Could not find kernel crash enabling message') |
25 | 25 |
26 | 26 |
27 def _get_kcrash_name(self): | 27 def _get_kcrash_name(self): |
28 filename_match = re.search( | 28 filename_match = re.search(r'Stored kcrash to (\S+)', |
29 r'Collected kernel crash diagnostics into (\S+)', | |
30 self._log_reader.get_logs()) | 29 self._log_reader.get_logs()) |
31 if not filename_match: | 30 if not filename_match: |
32 return None | 31 return None |
33 return filename_match.group(1) | 32 return filename_match.group(1) |
34 | 33 |
35 | 34 |
| 35 def _is_signature_match(self, signature): |
| 36 return (re.match(r'kernel-write_breakme-[0-9A-F]{8}$', signature) is |
| 37 not None) |
| 38 |
| 39 |
36 def _test_reporter_kcrash_storage(self): | 40 def _test_reporter_kcrash_storage(self): |
37 """Test that crash_reporter has properly stored the kcrash report.""" | 41 """Test that crash_reporter has properly stored the kcrash report.""" |
38 if not self._log_reader.can_find('Cleared kernel crash diagnostics'): | 42 if not self._log_reader.can_find('Cleared kernel crash diagnostics'): |
39 raise error.TestFail('Could not find clearing message') | 43 raise error.TestFail('Could not find clearing message') |
40 | 44 |
| 45 announce_match = re.search( |
| 46 r'Received .* from kernel \(signature ([^\)]+)\) \(([^\)]+)\)', |
| 47 self._log_reader.get_logs()) |
| 48 |
| 49 if not announce_match: |
| 50 raise error.TestFail('Could not find kernel crash announcement') |
| 51 |
| 52 if not self._is_signature_match(announce_match.group(1)): |
| 53 raise error.TestFail( |
| 54 'Kernel crash signature (%s) did not match expected pattern' % |
| 55 announce_match.group(1)) |
| 56 |
41 kcrash_report = self._get_kcrash_name() | 57 kcrash_report = self._get_kcrash_name() |
42 | 58 |
43 if self._consent: | 59 if self._consent: |
44 if kcrash_report is None: | 60 if kcrash_report is None: |
45 raise error.TestFail( | 61 raise error.TestFail( |
46 'Could not find message with kcrash filename') | 62 'Could not find message with kcrash filename') |
| 63 if announce_match.group(2) != 'handling': |
| 64 raise error.TestFail('Did not announce handling of kcrash') |
47 else: | 65 else: |
48 if kcrash_report is not None: | 66 if kcrash_report is not None: |
49 raise error.TestFail('Should not have found kcrash filename') | 67 raise error.TestFail('Should not have found kcrash filename') |
| 68 if announce_match.group(2) != 'ignoring': |
| 69 raise error.TestFail('Did not announce ignoring of kcrash') |
50 return | 70 return |
51 | 71 |
52 if not os.path.exists(kcrash_report): | 72 if not os.path.exists(kcrash_report): |
53 raise error.TestFail('Crash report gone') | 73 raise error.TestFail('Crash report gone') |
54 report_contents = utils.read_file(kcrash_report) | 74 report_contents = utils.read_file(kcrash_report) |
55 if not 'kernel BUG at fs/proc/breakme.c' in report_contents: | 75 if not 'kernel BUG at fs/proc/breakme.c' in report_contents: |
56 raise error.TestFail('Crash report has unexpected contents') | 76 raise error.TestFail('Crash report has unexpected contents') |
57 | 77 |
58 if not os.path.exists(_KCRASH_FILE): | 78 if not os.path.exists(_KCRASH_FILE): |
59 raise error.TestFail('Could not find %s' % _KCRASH_FILE) | 79 raise error.TestFail('Could not find %s' % _KCRASH_FILE) |
(...skipping 11 matching lines...) Expand all Loading... |
71 raise error.TestFail('Crash report gone') | 91 raise error.TestFail('Crash report gone') |
72 result = self._call_sender_one_crash( | 92 result = self._call_sender_one_crash( |
73 report=os.path.basename(kcrash_report)) | 93 report=os.path.basename(kcrash_report)) |
74 if (not result['send_attempt'] or not result['send_success'] or | 94 if (not result['send_attempt'] or not result['send_success'] or |
75 result['report_exists']): | 95 result['report_exists']): |
76 raise error.TestFail('kcrash not sent properly') | 96 raise error.TestFail('kcrash not sent properly') |
77 if result['exec_name'] != 'kernel' or result['report_kind'] != 'kcrash': | 97 if result['exec_name'] != 'kernel' or result['report_kind'] != 'kcrash': |
78 raise error.TestFail('kcrash exec name or report kind wrong') | 98 raise error.TestFail('kcrash exec name or report kind wrong') |
79 if result['report_payload'] != kcrash_report: | 99 if result['report_payload'] != kcrash_report: |
80 raise error.TestFail('Sent the wrong kcrash report') | 100 raise error.TestFail('Sent the wrong kcrash report') |
| 101 if not self._is_signature_match(result['sig']): |
| 102 raise error.TestFail('Sent the wrong kcrash signature') |
81 | 103 |
82 | 104 |
83 def run_once(self, is_before, consent): | 105 def run_once(self, is_before, consent): |
84 self._log_reader.set_start_by_reboot(-1) | 106 self._log_reader.set_start_by_reboot(-1) |
85 # We manage consent saving across tests. | 107 # We manage consent saving across tests. |
86 self._automatic_consent_saving = False | 108 self._automatic_consent_saving = False |
87 self._consent = consent | 109 self._consent = consent |
88 if is_before: | 110 if is_before: |
89 self.run_crash_tests(['reporter_startup'], must_run_all=False) | 111 self.run_crash_tests(['reporter_startup'], must_run_all=False) |
90 # Leave crash sending paused for the kernel crash. | 112 # Leave crash sending paused for the kernel crash. |
91 self._leave_crash_sending = False | 113 self._leave_crash_sending = False |
92 else: | 114 else: |
93 self.run_crash_tests(['reporter_startup', | 115 self.run_crash_tests(['reporter_startup', |
94 'reporter_kcrash_storage', | 116 'reporter_kcrash_storage', |
95 'sender_send_kcrash'], | 117 'sender_send_kcrash'], |
96 clear_spool_first=False) | 118 clear_spool_first=False) |
OLD | NEW |