• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2009 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 logging, os, time
6from autotest_lib.client.bin import test, utils
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.cros import cros_ui
9
10class desktopui_KillRestart(test.test):
11    """Validate that the given binary can crash and get restarted."""
12    version = 1
13
14    def initialize(self):
15        """Clear out respawn timestamp files."""
16        cros_ui.clear_respawn_state()
17
18    def run_once(self, binary = 'chrome'):
19        # Ensure the binary is running.
20        utils.poll_for_condition(
21            lambda: os.system('pgrep %s >/dev/null' % binary) == 0,
22            error.TestFail('%s is not running at start of test' % binary),
23            timeout=60)
24
25        # Try to kill all running instances of the binary.
26        try:
27            utils.system('pkill -KILL %s' % binary)
28        except error.CmdError, e:
29            logging.debug(e)
30            raise error.TestFail('%s is not running before kill' % binary)
31
32        # Check if the binary is running again (using os.system(), since it
33        # doesn't raise an exception if the command fails).
34        utils.poll_for_condition(
35            lambda: os.system('pgrep %s >/dev/null' % binary) == 0,
36            error.TestFail('%s is not running after kill' % binary),
37            timeout=60)
38
39
40    def cleanup(self):
41        """Ensure that state from testing is cleared out."""
42        cros_ui.clear_respawn_state()
43