• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5import time
6import common
7from autotest_lib.client.common_lib import error
8from autotest_lib.server import test
9
10# Process to kill for log-generation purposes.
11TARGET_PROCESS = 'weaved'
12# Number of seconds to wait for host.run commands to timeout.
13COMMAND_TIMEOUT_SECONDS = 10
14# Number of times to retry the command the ls command to find logs.
15LOG_LIST_RETRIES = 5
16
17class brillo_CrashLogging(test.test):
18    """Confirm that crash logs are generated for native crashes."""
19    version = 1
20
21
22    def run_once(self, host=None):
23        """Confirm that crash logs are generated for native crashes.
24
25        @param host: host object representing the device under test.
26        """
27        if host is None:
28            raise error.TestFail('brillo_Crashlogging test executed without '
29                                 'a host')
30        self.host = host
31
32        # Remove any existing crash logs.
33        self.host.run('rm /data/misc/crash_reporter/crash/*',
34                      timeout=COMMAND_TIMEOUT_SECONDS, ignore_status=True)
35
36        # Find and kill a process.
37        result = self.host.run('pgrep %s' % TARGET_PROCESS,
38                               timeout=COMMAND_TIMEOUT_SECONDS)
39        pid = result.stdout.strip()
40        if not len(pid):
41            raise error.TestFail('No %s process found to kill' % TARGET_PROCESS)
42        self.host.run('kill -SIGSEGV %s' % pid, timeout=COMMAND_TIMEOUT_SECONDS)
43        # If the process links against bionic, then the first kill will be
44        # caught by bionic, so issue the command twice.
45        self.host.run('kill -SIGSEGV %s' % pid, timeout=COMMAND_TIMEOUT_SECONDS,
46                      ignore_status=True)
47        logs = None
48        for _ in xrange(LOG_LIST_RETRIES):
49            try:
50                logs = self.host.run_output(
51                        'ls /data/misc/crash_reporter/crash',
52                        timeout=COMMAND_TIMEOUT_SECONDS).split()
53            except (error.GenericHostRunError, error.AutoservSSHTimeout,
54                    error.CmdTimeoutError):
55                raise error.TestFail('No crash logs were created because of a '
56                                     'host error or because the directory '
57                                     'where crash logs are written to does not '
58                                     'exist on the DUT.')
59            if logs:
60                break
61            time.sleep(1)
62
63        if not logs:
64            raise error.TestFail('No crash logs were created.')
65