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