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 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 # TODO(kmixter): Remove this exception once I know it has | |
24 logging.info('Hasnt the kcrash kernel change landed?') | |
25 else: | |
26 raise error.TestFail( | 23 raise error.TestFail( |
27 'Could not find kernel crash found message') | 24 'Could not find kernel crash found message') |
28 | 25 |
29 | 26 |
30 def _get_kcrash_name(self): | 27 def _get_kcrash_name(self): |
31 filename_match = re.search( | 28 filename_match = re.search( |
32 r'Collected kernel crash diagnostics into (\S+)', | 29 r'Collected kernel crash diagnostics into (\S+)', |
33 self._log_reader.get_logs()) | 30 self._log_reader.get_logs()) |
34 if not filename_match: | 31 if not filename_match: |
35 raise error.TestFail('Could not message with kcrash filename') | 32 return None |
36 return filename_match.group(1) | 33 return filename_match.group(1) |
37 | 34 |
38 | 35 |
39 def _test_reporter_kcrash_storage(self): | 36 def _test_reporter_kcrash_storage(self): |
40 """Test that crash_reporter has properly stored the kcrash report.""" | 37 """Test that crash_reporter has properly stored the kcrash report.""" |
41 if not self._log_reader.can_find('Cleared kernel crash diagnostics'): | 38 if not self._log_reader.can_find('Cleared kernel crash diagnostics'): |
42 raise error.TestFail('Could not find clearing message') | 39 raise error.TestFail('Could not find clearing message') |
43 | 40 |
44 kcrash_report = self._get_kcrash_name() | 41 kcrash_report = self._get_kcrash_name() |
| 42 |
| 43 if self._consent: |
| 44 if kcrash_report is None: |
| 45 raise error.TestFail( |
| 46 'Could not find message with kcrash filename') |
| 47 else: |
| 48 if kcrash_report is not None: |
| 49 raise error.TestFail('Should not have found kcrash filename') |
| 50 return |
| 51 |
45 if not os.path.exists(kcrash_report): | 52 if not os.path.exists(kcrash_report): |
46 raise error.TestFail('Crash report gone') | 53 raise error.TestFail('Crash report gone') |
47 report_contents = utils.read_file(kcrash_report) | 54 report_contents = utils.read_file(kcrash_report) |
48 if not 'kernel BUG at fs/proc/breakme.c' in report_contents: | 55 if not 'kernel BUG at fs/proc/breakme.c' in report_contents: |
49 raise error.TestFail('Crash report has unexpected contents') | 56 raise error.TestFail('Crash report has unexpected contents') |
50 | 57 |
51 if not os.path.exists(_KCRASH_FILE): | 58 if not os.path.exists(_KCRASH_FILE): |
52 raise error.TestFail('Could not find %s' % _KCRASH_FILE) | 59 raise error.TestFail('Could not find %s' % _KCRASH_FILE) |
53 kcrash_file_contents = utils.read_file(_KCRASH_FILE) | 60 kcrash_file_contents = utils.read_file(_KCRASH_FILE) |
54 if kcrash_file_contents != '': | 61 if kcrash_file_contents != '': |
55 raise error.TestFail('%s was not properly cleared' % _KCRASH_FILE) | 62 raise error.TestFail('%s was not properly cleared' % _KCRASH_FILE) |
56 | 63 |
57 | 64 |
58 def _test_sender_send_kcrash(self): | 65 def _test_sender_send_kcrash(self): |
59 """Test that crash_sender properly sends the crash report.""" | 66 """Test that crash_sender properly sends the crash report.""" |
| 67 if not self._consent: |
| 68 return |
60 kcrash_report = self._get_kcrash_name() | 69 kcrash_report = self._get_kcrash_name() |
61 if not os.path.exists(kcrash_report): | 70 if not os.path.exists(kcrash_report): |
62 raise error.TestFail('Crash report gone') | 71 raise error.TestFail('Crash report gone') |
63 self._set_sending(True) | 72 self._set_sending(True) |
64 result = self._call_sender_one_crash( | 73 result = self._call_sender_one_crash( |
65 report=os.path.basename(kcrash_report)) | 74 report=os.path.basename(kcrash_report)) |
66 if (not result['send_attempt'] or not result['send_success'] or | 75 if (not result['send_attempt'] or not result['send_success'] or |
67 result['report_exists']): | 76 result['report_exists']): |
68 raise error.TestFail('kcrash not sent properly') | 77 raise error.TestFail('kcrash not sent properly') |
69 if result['exec_name'] != 'kernel' or result['report_kind'] != 'kcrash': | 78 if result['exec_name'] != 'kernel' or result['report_kind'] != 'kcrash': |
70 raise error.TestFail('kcrash exec name or report kind wrong') | 79 raise error.TestFail('kcrash exec name or report kind wrong') |
71 if result['report_name'] != kcrash_report: | 80 if result['report_payload'] != kcrash_report: |
72 raise error.TestFail('Sent the wrong kcrash report') | 81 raise error.TestFail('Sent the wrong kcrash report') |
73 | 82 |
74 | 83 |
75 def run_once(self, is_before): | 84 def run_once(self, is_before, consent): |
76 self._log_reader.set_start_by_reboot(-1) | 85 self._log_reader.set_start_by_reboot(-1) |
| 86 # We manage consent saving across tests. |
| 87 self._automatic_consent_saving = False |
| 88 self._consent = consent |
77 if is_before: | 89 if is_before: |
78 self.run_crash_tests(['reporter_startup'], must_run_all=False) | 90 self.run_crash_tests(['reporter_startup'], must_run_all=False) |
79 # Leave crash sending paused for the kernel crash. | 91 # Leave crash sending paused for the kernel crash. |
80 self._leave_crash_sending = False | 92 self._leave_crash_sending = False |
81 else: | 93 else: |
82 self.run_crash_tests(['reporter_startup', | 94 self.run_crash_tests(['reporter_startup', |
83 'reporter_kcrash_storage', | 95 'reporter_kcrash_storage', |
84 'sender_send_kcrash'], | 96 'sender_send_kcrash'], |
85 clear_spool_first=False) | 97 clear_spool_first=False) |
OLD | NEW |