1# copyright (c) 2015 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, threading, time 6 7from autotest_lib.server import autotest, test 8from autotest_lib.client.common_lib import error 9 10_LONG_TIMEOUT = 120 11_WAIT_DELAY = 5 12_CHROME_PATH = '/opt/google/chrome/chrome' 13 14class platform_FullyChargedPowerStatus(test.test): 15 version = 1 16 17 def cleanup(self): 18 """ Power on RPM on cleanup. 19 20 """ 21 self.host.power_on() 22 23 24 def get_power_supply_parameters(self): 25 """ Retrieve power supply info 26 27 @returns a list of power supply info paramenters 28 29 """ 30 power_supply_info = self.host.get_power_supply_info() 31 online = power_supply_info['Line Power']['online'] 32 state = power_supply_info['Battery']['state'] 33 percentage = power_supply_info['Battery']['display percentage'] 34 current = power_supply_info['Battery']['current (A)'] 35 return (online, state, int(float(percentage)), float(current)) 36 37 38 def check_power_charge_status(self, status): 39 """ Check any power status strings are not returned as expected 40 41 @param status: record power status set when fail 42 43 """ 44 errors = list() 45 online, state, percentage, current = self.get_power_supply_parameters() 46 47 if state != 'Fully charged' and state != 'Charging' and current != 0.0: 48 errors.append('Bad state %s at %s' % (state, status)) 49 50 if percentage < 95 : 51 errors.append('Bad percentage %d at %s' % (percentage, status)) 52 53 if online != 'yes': 54 errors.append('Bad online %s at %s' % (online, status)) 55 56 if errors: 57 raise error.TestFail('; '.join(errors)) 58 59 60 def action_login(self): 61 """Login i.e. runs running client test""" 62 self.autotest_client.run_test('desktopui_SimpleLogin', 63 exit_without_logout=True) 64 65 66 def is_chrome_available(self): 67 """check if _CHROME_PATH exists 68 69 @returns true if _CHROME_PATH no exists 70 71 """ 72 return self.host.run('ls %s' % _CHROME_PATH, 73 ignore_status=True).exit_status == 0 74 75 76 def action_suspend(self): 77 """Suspend i.e. powerd_dbus_suspend and wait 78 79 @returns boot_id for the following resume 80 81 """ 82 boot_id = self.host.get_boot_id() 83 thread = threading.Thread(target = self.host.suspend) 84 thread.start() 85 self.host.test_wait_for_sleep(_LONG_TIMEOUT) 86 logging.debug('--- Suspended') 87 return boot_id 88 89 90 def run_once(self, host, power_status_sets): 91 self.host = host 92 self.autotest_client = autotest.Autotest(self.host) 93 94 if not self.is_chrome_available(): 95 raise error.TestNAError('Chrome does not reside on DUT. Test Skipped') 96 97 if not self.host.get_board_type() == 'CHROMEBOOK': 98 raise error.TestNAError('DUT is not Chromebook. Test Skipped') 99 100 if self.host.has_power(): 101 self.host.power_on() 102 else: 103 raise error.TestError('No RPM is setup to device') 104 105 online, state, percentage, current = self.get_power_supply_parameters() 106 if not ( online == 'yes' and percentage > 95 ): 107 raise error.TestError('The DUT is not on AC or Battery charge is low ') 108 109 self.action_login() 110 111 for power_status_set in power_status_sets: 112 before_suspend, after_suspend, before_resume = power_status_set 113 logging.info('Power status set: %s', str(power_status_set)) 114 115 # Set power before suspend 116 if not before_suspend: 117 self.host.power_off() 118 time.sleep(_WAIT_DELAY) 119 120 # Suspend DUT(powerd_dbus_suspend) 121 boot_id = self.action_suspend() 122 logging.info('DUT suspended') 123 124 # Set power after suspend 125 if after_suspend: 126 self.host.power_on() 127 else: 128 self.host.power_off() 129 time.sleep(_WAIT_DELAY) 130 time.sleep(_WAIT_DELAY) 131 132 # Set power before resume 133 if before_resume: 134 self.host.power_on() 135 else: 136 self.host.power_off() 137 time.sleep(_WAIT_DELAY) 138 time.sleep(_WAIT_DELAY) 139 140 # Wait to resume DUT 141 self.host.test_wait_for_resume(boot_id, _LONG_TIMEOUT) 142 logging.info('DUT resumed') 143 144 # Set power to on after resume if needed 145 if not before_resume: 146 self.host.power_on() 147 time.sleep(_WAIT_DELAY) 148 149 self.check_power_charge_status(str(power_status_set)) 150