Chromium Code Reviews| Index: chrome/test/functional/chromeos_battery.py |
| =================================================================== |
| --- chrome/test/functional/chromeos_battery.py (revision 0) |
| +++ chrome/test/functional/chromeos_battery.py (revision 0) |
| @@ -0,0 +1,122 @@ |
| +#!/usr/bin/python |
| +# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that |
| +# can be found in the LICENSE file. |
| + |
| +import os |
| + |
| +import pyauto_functional # Must be imported before pyauto |
| +import pyauto |
| + |
| +from chromeos.power_strip import PowerStrip |
| + |
| +class ChromeosBattery(pyauto.PyUITest): |
| + """Tests ChromeOS Battery Status. |
| + |
| + Preconditions: |
| + 1) Device under test (DUT) is connected to the LAN via an |
| + Ethernet-to-USB adapter plugged into one of its USB ports. |
| + 2) AC power cable is connected to the DUT, and plugged into |
| + the IP controlled Power Switch, outlet #4, located in the lab. |
| + 3) Battery is installed in the DUT, and battery is not fully |
| + discharged. |
| + 4) Tester should have physical access to the power switch. |
| + |
| + Note about time calculation: |
| + When AC power is turned off or on, the battery will take from 2 |
| + to 60 seconds to calculate the time remaining to empty or full. |
| + While calculating, the keys 'battery_time_to_full' and |
| + 'battery_time_to_empty' are absent. |
| + """ |
| + |
| + _BATTERY_CONFIG_FILE = os.path.join(pyauto.PyUITest.DataDir(), |
| + 'pyauto_private', 'chromeos', 'power', |
| + 'battery_testbed_config') |
| + |
| + def setUp(self): |
| + pyauto.PyUITest.setUp(self) |
| + self.InitPowerStrip() |
| + |
| + def tearDown(self): |
| + # Leave AC power ON so battery does not discharge between tests |
| + self._power_strip.PowerOn(self._outlet_battery_full) |
| + pyauto.PyUITest.tearDown(self) |
| + |
| + def InitPowerStrip(self): |
| + assert os.path.exists(ChromeosBattery._BATTERY_CONFIG_FILE),\ |
|
Nirnimesh
2011/06/06 18:09:01
nit: put a space before \
Repeat elsewhere in this
xot
2011/06/10 01:36:33
Done.
|
| + 'Power Strip configuration file does not exist.' |
| + power_config = pyauto.PyUITest.EvalDataFrom( |
| + ChromeosBattery._BATTERY_CONFIG_FILE) |
| + self._power_strip = PowerStrip(power_config['strip_ip']) |
| + self._outlet_battery_full = (power_config['configs'] |
| + ['battery_full'] |
| + ['outlet_id']) |
| + |
| + def BatteryPowerAndChargeStateAgree(self, ac_power_on, time_key): |
| + battery_status = self.GetBatteryInfo() |
| + return ((battery_status.get('line_power_on') == ac_power_on) and |
|
Nirnimesh
2011/06/06 18:09:01
nit: remove extra parens. You don't need any paren
xot
2011/06/10 01:36:33
Done.
|
| + (battery_status.get(time_key) != None)) |
|
Nirnimesh
2011/06/06 18:09:01
'!= None' is redundant
dtu
2011/06/06 21:06:58
No, it should be "time_key in battery_status". 0 i
xot
2011/06/10 01:36:33
replaced with "time_key in battery_status"
xot
2011/06/10 01:36:33
replaced with "time_key in battery_status"
|
| + |
| + def testBatteryChargesWhenACisOn(self): |
| + """AC power ON to CrOS device with battery.""" |
| + self._power_strip.PowerOn(self._outlet_battery_full) |
| + |
| + # Get info about charging battery |
| + assert self.WaitUntil(lambda: self.BatteryPowerAndChargeStateAgree( |
| + True, 'battery_time_to_full'), timeout=60, retry_sleep=1),\ |
|
Nirnimesh
2011/06/06 18:09:01
Isn't the default timeout (~25 secs) not enough?
dtu
2011/06/06 21:06:58
You can pull this entire WaitUntil thing out to a
dtu
2011/06/06 21:06:58
scunningham said he's seen it take up to 40s, so 6
xot
2011/06/10 01:36:33
Okay, but only if you don't complain about me crea
xot
2011/06/10 01:36:33
Done.
xot
2011/06/10 01:36:33
Nope.
|
| + 'Battery charge time was not calculated.' |
| + battery_status = self.GetBatteryInfo() |
| + self.assertTrue(battery_status.get('battery_is_present'), |
| + msg='Battery is not present.') |
| + self.assertTrue(battery_status.get('line_power_on'), |
| + msg='Line power is off.') |
| + self.assertTrue(battery_status.get('battery_time_to_full') >= 0, |
| + msg='Battery charge time is negative.') |
| + |
| + def testBatteryDischargesWhenACisOff(self): |
| + """AC power OFF to CrOS device with battery.""" |
| + self._power_strip.PowerOff(self._outlet_battery_full) |
| + |
| + # Get info about discharging battery |
| + assert self.WaitUntil(lambda: self.BatteryPowerAndChargeStateAgree( |
| + False, 'battery_time_to_empty'), timeout=60, retry_sleep=1),\ |
| + 'Battery discharge time was not calculated.' |
| + battery_status = self.GetBatteryInfo() |
| + self.assertTrue(battery_status.get('battery_is_present'), |
| + msg='Battery is not present.') |
| + self.assertFalse(battery_status.get('line_power_on'), |
| + msg='Line power is off.') |
|
stanleyw
2011/06/06 20:54:50
Do you mean line power is on?
xot
2011/06/10 01:36:33
Good catch!
|
| + self.assertTrue(battery_status.get('battery_time_to_empty') >= 0, |
| + msg='Battery discharge time is negative.') |
| + |
| + def testBatteryTimesAreDifferent(self): |
| + """Time to full is different than Time to empty""" |
| + # Turn AC Power ON |
| + self._power_strip.PowerOn(self._outlet_battery_full) |
| + |
| + # Get charging battery time to full |
| + assert self.WaitUntil(lambda: self.BatteryPowerAndChargeStateAgree( |
| + True, 'battery_time_to_full'), timeout=60, retry_sleep=1),\ |
| + 'Battery charge time was not calculated.' |
| + battery_status = self.GetBatteryInfo() |
| + time_to_full = battery_status.get('battery_time_to_full') |
| + |
| + # Turn AC Power OFF |
| + self._power_strip.PowerOff(self._outlet_battery_full) |
| + |
| + # Get discharging battery time to empty |
| + assert self.WaitUntil(lambda: self.BatteryPowerAndChargeStateAgree( |
| + False, 'battery_time_to_empty'), timeout=60, retry_sleep=1),\ |
| + 'Battery discharge time was not calculated.' |
| + battery_status = self.GetBatteryInfo() |
| + time_to_empty = battery_status.get('battery_time_to_empty') |
| + |
| + # Compare times |
|
stanleyw
2011/06/06 20:54:50
Maybe explain why you are comparing the times.
|
| + self.assertNotEqual(time_to_full, time_to_empty, |
| + msg='Battery time to full equals time to empty. ' |
| + 'Though very unlikely, this is not impossible. ' |
| + 'If test failed falsely, Kris owes Scott a beer. ') |
|
stanleyw
2011/06/06 20:54:50
Nice!
dtu
2011/06/06 21:06:58
Extra space after the last period.
xot
2011/06/10 01:36:33
Done.
xot
2011/06/10 01:36:33
Done.
|
| + |
| + |
| +if __name__ == '__main__': |
| + pyauto_functional.Main() |