Home | History | Annotate | Download | only in android_CrashLogging
      1 # Copyright 2016 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 time
      6 import common
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.server import test
      9 
     10 # Process to kill for log-generation purposes.
     11 TARGET_PROCESS = '/system/bin/mediaserver'
     12 # Number of seconds to wait for host.run commands to timeout.
     13 COMMAND_TIMEOUT_SECONDS = 10
     14 # Number of times to try to kill the process.
     15 KILL_RETRIES = 10
     16 # Number of times to retry the command the find command to find logs.
     17 LOG_FIND_RETRIES = 5
     18 
     19 class android_CrashLogging(test.test):
     20     """Confirm that crash logs are generated for native crashes."""
     21     version = 1
     22 
     23 
     24     def run_once(self, host=None):
     25         """Confirm that crash logs are generated for crashes.
     26 
     27         @param host: host object representing the device under test.
     28         """
     29         if host is None:
     30             raise error.TestFail('android_Crashlogging test executed without '
     31                                  'a host')
     32         self.host = host
     33 
     34         # Remove any pre-existing tombstones.
     35         self.host.run('rm /data/tombstones/tombstone_*',
     36                       timeout=COMMAND_TIMEOUT_SECONDS, ignore_status=True)
     37 
     38         # Find and kill a process.
     39         result = self.host.run('pgrep %s' % TARGET_PROCESS,
     40                                timeout=COMMAND_TIMEOUT_SECONDS,
     41                                ignore_status=True)
     42         pid = result.stdout.strip()
     43         if result.exit_status != 0 or not len(pid):
     44             raise error.TestFail('No %s process found to kill' % TARGET_PROCESS)
     45         for _ in xrange(KILL_RETRIES):
     46             status = self.host.run('kill -SIGSEGV %s' % pid,
     47                                    timeout=COMMAND_TIMEOUT_SECONDS,
     48                                    ignore_status=True).exit_status
     49             if status != 0:
     50                 break
     51 
     52         logs = None
     53         for _ in xrange(LOG_FIND_RETRIES):
     54             try:
     55                 logs = self.host.run_output(
     56                         'find /data/tombstones -maxdepth 1 -type f',
     57                         timeout=COMMAND_TIMEOUT_SECONDS).split()
     58             except (error.GenericHostRunError, error.AutoservSSHTimeout,
     59                     error.CmdTimeoutError):
     60                 raise error.TestFail('No crash logs were created because of a '
     61                                      'host error or because the directory '
     62                                      'where crash logs are written to does not '
     63                                      'exist on the DUT.')
     64             if logs:
     65                 break
     66             time.sleep(1)
     67 
     68         if not logs:
     69             raise error.TestFail('No crash logs were created.')
     70