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 7import time 8 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.common_lib.cros import chrome 11from autotest_lib.client.cros.bluetooth import bluetooth_device_xmlrpc_server 12from autotest_lib.client.cros.input_playback import keyboard 13from autotest_lib.client.cros.power import power_test 14from autotest_lib.client.cros.power import power_utils 15 16 17class power_Idle(power_test.power_Test): 18 """class for power_Idle test. 19 20 Collects power stats when machine is idle 21 22 Current tests, 23 24 | test# | seconds | display | bluetooth | 25 ------------------------------------------- 26 | 1 | 120 | off | off | 27 | 2 | 120 | default | off | 28 | 3 | 120 | default | on - idle | 29 | 4 | 120 | off | on - idle | 30 31 """ 32 version = 1 33 first_test_warmup_secs = 60 34 35 def initialize(self, pdash_note='', seconds_period=10., 36 force_discharge=False, run_arc=True): 37 super(power_Idle, self).initialize(seconds_period=seconds_period, 38 pdash_note=pdash_note, 39 force_discharge=force_discharge, 40 run_arc=run_arc) 41 42 def run_once(self, warmup_secs=20, idle_secs=120, default_only=False): 43 """Collect power stats for idle tests.""" 44 45 def measure_it(warmup_secs, idle_secs, tagname): 46 """Helper function to wrap testing loop for each sub test.""" 47 if self.is_first_test: 48 warmup_secs += self.first_test_warmup_secs 49 self.is_first_test = False 50 if warmup_secs > 0: 51 tstart = time.time() 52 time.sleep(warmup_secs) 53 self.checkpoint_measurements("warmup", tstart) 54 tstart = time.time() 55 time.sleep(idle_secs) 56 self.checkpoint_measurements(tagname, tstart) 57 58 bt_device = bluetooth_device_xmlrpc_server \ 59 .BluetoothDeviceXmlRpcDelegate() 60 61 # --disable-sync disables test account info sync, eg. Wi-Fi credentials, 62 # so that each test run does not remember info from last test run. 63 extra_browser_args = ['--disable-sync'] 64 # b/228256145 to avoid powerd restart 65 extra_browser_args.append('--disable-features=FirmwareUpdaterApp') 66 with chrome.Chrome(extra_browser_args=extra_browser_args, 67 arc_mode=self._arc_mode) as self.cr: 68 self.is_first_test = True 69 70 # Measure power in full-screen blank tab 71 tab = self.cr.browser.tabs.New() 72 tab.Activate() 73 fullscreen = tab.EvaluateJavaScript('document.webkitIsFullScreen') 74 if not fullscreen: 75 with keyboard.Keyboard() as keys: 76 keys.press_key('f4') 77 78 # Stop services again as Chrome might have restarted them. 79 self._services.stop_services() 80 81 if default_only: 82 self.start_measurements() 83 measure_it(warmup_secs, idle_secs, 'all-default') 84 return 85 86 # test1 : display off, BT off 87 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_OFF) 88 if not bt_device.set_powered(False): 89 raise error.TestFail('Cannot turn off bluetooth adapter.') 90 self.start_measurements() 91 measure_it(warmup_secs, idle_secs, 'display-off_bluetooth-off') 92 93 # test2 : display default, BT off 94 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_ON) 95 measure_it(warmup_secs, idle_secs, 96 'display-default_bluetooth-off') 97 98 # test3 : display default, BT on 99 if not bt_device.set_powered(True): 100 logging.warning('Cannot turn on bluetooth adapter.') 101 return 102 measure_it(warmup_secs, idle_secs, 'display-default_bluetooth-on') 103 104 # test4 : display off, BT on 105 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_OFF) 106 measure_it(warmup_secs, idle_secs, 'display-off_bluetooth-on') 107 108 def cleanup(self): 109 """Reset to previous state.""" 110 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_ON) 111 super(power_Idle, self).cleanup() 112