1# Lint as: python2, python3 2# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import logging 7 8from autotest_lib.client.bin import utils 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.common_lib.cros import arc, chrome 11from autotest_lib.client.cros import upstart 12 13 14class power_UiResume(arc.ArcTest): 15 """ 16 Suspend the system while simulating user behavior. 17 18 If ARC is present, open ARC before suspending. If ARC is not present, log 19 into Chrome before suspending. To suspend, call autotest power_Resume. This 20 reduces duplicate code, while cover all 3 cases: with ARC, with Chrome but 21 without ARC, and without Chrome. 22 23 """ 24 version = 3 25 26 def initialize(self, no_arc=False): 27 """ 28 Entry point. Initialize ARC if it is enabled on the DUT, otherwise log 29 in Chrome browser. 30 31 """ 32 # --disable-sync disables test account info sync, eg. Wi-Fi credentials, 33 # so that each test run does not remember info from last test run. 34 extra_browser_args = ['--disable-sync'] 35 36 # TODO(b/191251229): Only enable ARC if ARC is available and it is not 37 # running ARCVM. 38 self._enable_arc = (utils.is_arc_available() and not utils.is_arcvm() 39 and not no_arc) 40 if self._enable_arc: 41 super(power_UiResume, 42 self).initialize(extra_browser_args=extra_browser_args) 43 else: 44 self._chrome = chrome.Chrome(extra_browser_args=extra_browser_args) 45 46 47 def run_once(self, max_devs_returned=10, seconds=0, 48 ignore_kernel_warns=False): 49 """ 50 Run client side autotest power_Resume, to reduce duplicate code. 51 52 """ 53 service = 'powerd' 54 err = 0 55 pid_start = upstart.get_pid(service) 56 if not pid_start: 57 upstart.restart_job(service) 58 pid_start = upstart.get_pid(service) 59 if not pid_start: 60 logging.error('%s is not running at start of test', service) 61 err += 1 62 63 self.job.run_test( 64 'power_Resume', 65 max_devs_returned=max_devs_returned, 66 seconds=seconds, 67 ignore_kernel_warns=ignore_kernel_warns, 68 measure_arc=self._enable_arc) 69 70 pid_end = upstart.get_pid('powerd') 71 if not pid_end: 72 logging.error('%s is not running at end of test', service) 73 err += 1 74 75 if pid_start and pid_end and pid_start != pid_end: 76 logging.error('%s respawned during test', service) 77 err += 1 78 79 if err: 80 raise error.TestFail('Test failed. See errors for details.') 81 82 def cleanup(self): 83 """ 84 Clean up ARC if it is enabled on the DUT, otherwise close the Chrome 85 browser. 86 """ 87 if self._enable_arc: 88 super(power_UiResume, self).cleanup() 89 else: 90 self._chrome.close() 91