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