1# Copyright (c) 2010 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 glob 6import logging 7import os 8 9from autotest_lib.client.bin import test 10from autotest_lib.client.common_lib import error, utils 11from autotest_lib.client.cros.power import power_status, power_utils 12 13class power_ProbeDriver(test.test): 14 """Confirms that AC driver is loaded and functioning 15 unless device is AC only.""" 16 version = 1 17 18 def run_once(self, test_which='Mains'): 19 # This test doesn't apply to systems that run on AC only. 20 if not power_utils.has_battery(): 21 return 22 # Gather power supplies 23 status = power_status.get_status() 24 run_dict = { 'Mains': self.run_ac, 'Battery': self.run_bat } 25 run = run_dict.get(test_which) 26 if run: 27 run(status) 28 else: 29 raise error.TestNAError('Unknown test type: %s' % test_which) 30 31 def run_ac(self, status): 32 """Checks AC driver. 33 34 @param status: power_status.SysStat object 35 """ 36 if not status.linepower: 37 raise error.TestFail('No line power devices found') 38 39 if not status.on_ac(): 40 raise error.TestFail('Line power is not connected') 41 42 if not status.battery_discharging(): 43 return 44 45 if status.battery_discharge_ok_on_ac(): 46 logging.info('DUT battery discharging but deemed ok') 47 return 48 49 raise error.TestFail('Battery is discharging') 50 51 def run_bat(self, status): 52 """ Checks batteries. 53 54 @param status: power_status.SysStat object 55 """ 56 if not status.battery: 57 raise error.TestFail('No battery found') 58 59 if not status.battery[0].present: 60 raise error.TestFail('No battery present') 61 62 if not status.battery_discharging(): 63 raise error.TestFail('No battery discharging') 64 65 if status.on_ac(): 66 raise error.TestFail('One of ACs is online') 67