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 6import time 7 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.common_lib.cros import chrome 10from autotest_lib.client.cros.bluetooth import bluetooth_device_xmlrpc_server 11from autotest_lib.client.cros.power import power_test 12from autotest_lib.client.cros.power import power_utils 13 14 15class power_Idle(power_test.power_Test): 16 """class for power_Idle test. 17 18 Collects power stats when machine is idle 19 20 Current tests, 21 22 | test# | seconds | display | bluetooth | 23 ------------------------------------------- 24 | 1 | 120 | off | off | 25 | 2 | 120 | default | off | 26 | 3 | 120 | default | on - idle | 27 | 4 | 120 | off | on - idle | 28 29 """ 30 version = 1 31 32 def initialize(self, pdash_note='', seconds_period=10.): 33 super(power_Idle, self).initialize(seconds_period=seconds_period, 34 pdash_note=pdash_note) 35 36 def run_once(self, warmup_secs=20, idle_secs=120): 37 """Collect power stats for idle tests.""" 38 39 def measure_it(warmup_secs, idle_secs, tagname): 40 time.sleep(warmup_secs) 41 tstart = time.time() 42 time.sleep(idle_secs) 43 self.checkpoint_measurements(tagname, tstart) 44 45 bt_device = bluetooth_device_xmlrpc_server \ 46 .BluetoothDeviceXmlRpcDelegate() 47 48 with chrome.Chrome(): 49 # test1 : display off, BT off 50 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_OFF) 51 if not bt_device.set_powered(False): 52 raise error.TestFail('Cannot turn off bluetooth adapter.') 53 self.start_measurements() 54 measure_it(warmup_secs, idle_secs, 'display-off_bluetooth-off') 55 56 # test2 : display default, BT off 57 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_ON) 58 measure_it(warmup_secs, idle_secs, 59 'display-default_bluetooth-off') 60 61 # test3 : display default, BT on 62 if not bt_device.set_powered(True): 63 logging.warning('Cannot turn on bluetooth adapter.') 64 return 65 measure_it(warmup_secs, idle_secs, 'display-default_bluetooth-on') 66 67 # test4 : display off, BT on 68 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_OFF) 69 measure_it(warmup_secs, idle_secs, 'display-off_bluetooth-on') 70 71def cleanup(self): 72 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_ON) 73 super(power_Idle, self).cleanup() 74