Home | History | Annotate | Download | only in logging_CrashServices
      1 # Copyright (c) 2012 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 os, os.path, logging
      6 from autotest_lib.client.bin import test, utils
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.client.common_lib.cros import chrome
      9 from autotest_lib.client.cros.crash_test import CrashTest
     10 
     11 class logging_CrashServices(test.test):
     12     version = 3
     13 
     14     process_list = {
     15         '/sbin/agetty' : ['.core', '.dmp', '.meta'],
     16         '/usr/sbin/cryptohomed' : ['.core', '.dmp', '.meta'],
     17         '/usr/bin/metrics_daemon' : ['.core', '.dmp', '.meta'],
     18         '/usr/bin/powerd' : ['.core', '.dmp', '.meta', '.log'],
     19         '/usr/sbin/rsyslogd': ['.core', '.dmp', '.meta'],
     20         # Removing tcsd crash with reference to crbug.com/380359
     21         # '/usr/sbin/tcsd' : ['.core', '.dmp', '.meta'],
     22         '/usr/bin/tlsdated' : ['.core', '.dmp', '.meta'],
     23         '/usr/bin/shill' : ['.core', '.dmp', '.meta'],
     24         '/usr/sbin/update_engine' : ['.core', '.dmp', '.meta', '.log'],
     25         '/usr/sbin/wpa_supplicant' : ['.core', '.dmp', '.meta'],
     26         '/sbin/session_manager' : ['.core', '.dmp', '.meta']
     27     }
     28 
     29     def _kill_processes(self, name):
     30         """Kills the process passed as the parameter
     31 
     32         @param name: Name of the process to be killed.
     33 
     34         @returns: exit status of the kill command.
     35 
     36         """
     37         return utils.system("killall -w -s SEGV %s" % name, ignore_status=True)
     38 
     39 
     40     def _find_crash_files(self, process_name, extension):
     41         """Find if the crash dumps with appropriate extensions are created.
     42 
     43         @param process_name: Name of the process killed.
     44         @param extension: Extension of the dump files to be created.
     45 
     46         @returns: Returns the name of the dump file.
     47 
     48         """
     49         return self._find_file_in_path(CrashTest._SYSTEM_CRASH_DIR,
     50                                        process_name, extension)
     51 
     52 
     53     def _find_file_in_path(self, path, process_name, filetype):
     54         """Checks the creation of the the dump files with appropriate extensions.
     55            Also check for the file size of the dumps created.
     56 
     57         @param path: Dirctory path where the dump files are expected.
     58         @param process_name: Name of the process.
     59         @param filetype: Extension of the dump file.
     60 
     61         @returns: Name of the dump file.
     62 
     63         """
     64         try:
     65             entries = os.listdir(path)
     66         except OSError:
     67             return None
     68 
     69         for entry in entries:
     70             (filename, ext) = os.path.splitext(entry)
     71             if ext == filetype and filename.startswith(process_name):
     72                 logging.info('the path is %s' % os.path)
     73                 if os.path.getsize(path + '/' + entry) > 0 :
     74                     return entry
     75         return None
     76 
     77 
     78     def _test_process(self, process_path, crash_extensions):
     79         """Calls a function to kill the process and then wait
     80            for the creation of the dump files.
     81 
     82         @param process_path: Path of the process to be killed.
     83         @param crash_extensions: Extension of the dump file expected.
     84 
     85         """
     86         if self._kill_processes(process_path):
     87             raise error.TestFail("Failed to kill process %s" % process_path)
     88 
     89         process_name = os.path.basename(process_path)
     90 
     91         for crash_ext in crash_extensions:
     92             # wait for appropriate dump files in a crash directory.
     93             utils.poll_for_condition(
     94                 condition=lambda: self._find_crash_files(process_name,
     95                                                          crash_ext),
     96                 desc="Waiting for %s for %s" % (crash_ext, process_path))
     97 
     98 
     99     def run_once(self, process_path=None, crash_extensions=None):
    100         if process_path:
    101             self._test_process(process_path,crash_extensions)
    102             return
    103 
    104         with chrome.Chrome():
    105             if not utils.is_freon():
    106                 process_path = '/usr/bin/X'
    107                 crash_extensions = ['.core', '.dmp', '.meta']
    108                 self.job.run_test("logging_CrashServices",
    109                                   process_path=process_path,
    110                                   crash_extensions=crash_extensions,
    111                                   tag=os.path.basename(process_path))
    112             for process_path in self.process_list.keys():
    113                 self.job.run_test("logging_CrashServices",
    114                                   process_path=process_path,
    115                                   crash_extensions=self.process_list.get(process_path),
    116                                   tag=os.path.basename(process_path))