• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 logging
6
7from autotest_lib.client.bin import utils
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib.cros import arc, chrome
10from autotest_lib.client.cros import upstart
11
12
13class power_UiResume(arc.ArcTest):
14    """
15    Suspend the system while simulating user behavior.
16
17    If ARC is present, open ARC before suspending. If ARC is not present, log
18    into Chrome before suspending. To suspend, call autotest power_Resume. This
19    reduces duplicate code, while cover all 3 cases: with ARC, with Chrome but
20    without ARC, and without Chrome.
21
22    """
23    version = 3
24
25    def initialize(self, no_arc=False):
26        """
27        Entry point. Initialize ARC if it is enabled on the DUT, otherwise log
28        in Chrome browser.
29
30        """
31        self._enable_arc = utils.is_arc_available() and not no_arc
32        if self._enable_arc:
33            super(power_UiResume, self).initialize()
34        else:
35            self._chrome = chrome.Chrome()
36
37
38    def run_once(self, max_devs_returned=10, seconds=0,
39                 ignore_kernel_warns=False):
40        """
41        Run client side autotest power_Resume, to reduce duplicate code.
42
43        """
44        service = 'powerd'
45        err = 0
46        pid_start = upstart.get_pid(service)
47        if not pid_start:
48            upstart.restart_job(service)
49        pid_start = upstart.get_pid(service)
50        if not pid_start:
51            logging.error('%s is not running at start of test', service)
52            err += 1
53
54        self.job.run_test(
55                'power_Resume',
56                max_devs_returned=max_devs_returned,
57                seconds=seconds,
58                ignore_kernel_warns=ignore_kernel_warns,
59                measure_arc=self._enable_arc)
60
61        pid_end = upstart.get_pid('powerd')
62        if not pid_end:
63            logging.error('%s is not running at end of test', service)
64            err += 1
65
66        if pid_start and pid_end and pid_start != pid_end:
67            logging.error('%s respawned during test', service)
68            err += 1
69
70        if err:
71            raise error.TestFail('Test failed.  See errors for details.')
72
73    def cleanup(self):
74        """
75        Clean up ARC if it is enabled on the DUT, otherwise close the Chrome
76        browser.
77        """
78        if self._enable_arc:
79            super(power_UiResume, self).cleanup()
80        else:
81            self._chrome.close()
82