OLD | NEW |
(Empty) | |
| 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 import logging, os, re |
| 6 from autotest_lib.client.bin import site_crash_test, site_log_reader, \ |
| 7 site_utils, test |
| 8 from autotest_lib.client.common_lib import error, utils |
| 9 |
| 10 |
| 11 _KCRASH_FILE = '/sys/kernel/debug/preserved/kcrash' |
| 12 |
| 13 |
| 14 class logging_KernelCrash(site_crash_test.CrashTest): |
| 15 version = 1 |
| 16 |
| 17 |
| 18 def _test_reporter_startup(self): |
| 19 """Test that the crash_reporter is handling kernel crashes.""" |
| 20 if not self._log_reader.can_find('Enabling kernel crash handling'): |
| 21 if self._log_reader.can_find( |
| 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( |
| 27 'Could not find kernel crash found message') |
| 28 |
| 29 |
| 30 def _get_kcrash_name(self): |
| 31 filename_match = re.search( |
| 32 r'Collected kernel crash diagnostics into (\S+)', |
| 33 self._log_reader.get_logs()) |
| 34 if not filename_match: |
| 35 raise error.TestFail('Could not message with kcrash filename') |
| 36 return filename_match.group(1) |
| 37 |
| 38 |
| 39 def _test_reporter_kcrash_storage(self): |
| 40 """Test that crash_reporter has properly stored the kcrash report.""" |
| 41 if not self._log_reader.can_find('Cleared kernel crash diagnostics'): |
| 42 raise error.TestFail('Could not find clearing message') |
| 43 |
| 44 kcrash_report = self._get_kcrash_name() |
| 45 if not os.path.exists(kcrash_report): |
| 46 raise error.TestFail('Crash report gone') |
| 47 report_contents = utils.read_file(kcrash_report) |
| 48 if not 'kernel BUG at fs/proc/breakme.c' in report_contents: |
| 49 raise error.TestFail('Crash report has unexpected contents') |
| 50 |
| 51 if not os.path.exists(_KCRASH_FILE): |
| 52 raise error.TestFail('Could not find %s' % _KCRASH_FILE) |
| 53 kcrash_file_contents = utils.read_file(_KCRASH_FILE) |
| 54 if kcrash_file_contents != '': |
| 55 raise error.TestFail('%s was not properly cleared' % _KCRASH_FILE) |
| 56 |
| 57 |
| 58 def _test_sender_send_kcrash(self): |
| 59 """Test that crash_sender properly sends the crash report.""" |
| 60 kcrash_report = self._get_kcrash_name() |
| 61 if not os.path.exists(kcrash_report): |
| 62 raise error.TestFail('Crash report gone') |
| 63 self._set_sending(True) |
| 64 result = self._call_sender_one_crash( |
| 65 report=os.path.basename(kcrash_report)) |
| 66 if (not result['send_attempt'] or not result['send_success'] or |
| 67 result['report_exists']): |
| 68 raise error.TestFail('kcrash not sent properly') |
| 69 if result['exec_name'] != 'kernel' or result['report_kind'] != 'kcrash': |
| 70 raise error.TestFail('kcrash exec name or report kind wrong') |
| 71 if result['report_name'] != kcrash_report: |
| 72 raise error.TestFail('Sent the wrong kcrash report') |
| 73 |
| 74 |
| 75 def run_once(self, is_before): |
| 76 self._log_reader.set_start_by_reboot(-1) |
| 77 if is_before: |
| 78 self.run_crash_tests(['reporter_startup'], must_run_all=False) |
| 79 # Leave crash sending paused for the kernel crash. |
| 80 self._leave_crash_sending = False |
| 81 else: |
| 82 self.run_crash_tests(['reporter_startup', |
| 83 'reporter_kcrash_storage', |
| 84 'sender_send_kcrash'], |
| 85 clear_spool_first=False) |
OLD | NEW |