Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that | |
| 4 # can be found in the LICENSE file. | |
| 5 | |
| 6 import os | |
| 7 | |
| 8 import pyauto_functional # Must be imported before pyauto | |
| 9 import pyauto | |
| 10 | |
| 11 from chromeos.power_strip import PowerStrip | |
| 12 | |
| 13 class ChromeosBattery(pyauto.PyUITest): | |
| 14 """Tests ChromeOS Battery Status. | |
| 15 | |
| 16 Preconditions: | |
| 17 1) Device under test (DUT) is connected to the LAN via an | |
| 18 Ethernet-to-USB adapter plugged into one of its USB ports. | |
| 19 2) AC power cable is connected to the DUT, and plugged into | |
| 20 the IP controlled Power Switch, outlet #4, located in the lab. | |
| 21 3) Battery is installed in the DUT, and battery is not fully | |
| 22 discharged. | |
| 23 4) Tester should have physical access to the power switch. | |
| 24 | |
| 25 Note about time calculation: | |
| 26 When AC power is turned off or on, the battery will take from 2 | |
| 27 to 60 seconds to calculate the time remaining to empty or full. | |
| 28 While calculating, the keys 'battery_time_to_full' and | |
| 29 'battery_time_to_empty' are absent. | |
| 30 """ | |
| 31 | |
| 32 _BATTERY_CONFIG_FILE = os.path.join(pyauto.PyUITest.DataDir(), | |
| 33 'pyauto_private', 'chromeos', 'power', | |
| 34 'battery_testbed_config') | |
| 35 | |
| 36 def setUp(self): | |
| 37 pyauto.PyUITest.setUp(self) | |
| 38 self.InitPowerStrip() | |
| 39 | |
| 40 def tearDown(self): | |
| 41 # Leave AC power ON so battery does not discharge between tests | |
| 42 self._power_strip.PowerOn(self._outlet_battery_full) | |
| 43 pyauto.PyUITest.tearDown(self) | |
| 44 | |
| 45 def InitPowerStrip(self): | |
| 46 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.
| |
| 47 'Power Strip configuration file does not exist.' | |
| 48 power_config = pyauto.PyUITest.EvalDataFrom( | |
| 49 ChromeosBattery._BATTERY_CONFIG_FILE) | |
| 50 self._power_strip = PowerStrip(power_config['strip_ip']) | |
| 51 self._outlet_battery_full = (power_config['configs'] | |
| 52 ['battery_full'] | |
| 53 ['outlet_id']) | |
| 54 | |
| 55 def BatteryPowerAndChargeStateAgree(self, ac_power_on, time_key): | |
| 56 battery_status = self.GetBatteryInfo() | |
| 57 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.
| |
| 58 (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"
| |
| 59 | |
| 60 def testBatteryChargesWhenACisOn(self): | |
| 61 """AC power ON to CrOS device with battery.""" | |
| 62 self._power_strip.PowerOn(self._outlet_battery_full) | |
| 63 | |
| 64 # Get info about charging battery | |
| 65 assert self.WaitUntil(lambda: self.BatteryPowerAndChargeStateAgree( | |
| 66 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.
| |
| 67 'Battery charge time was not calculated.' | |
| 68 battery_status = self.GetBatteryInfo() | |
| 69 self.assertTrue(battery_status.get('battery_is_present'), | |
| 70 msg='Battery is not present.') | |
| 71 self.assertTrue(battery_status.get('line_power_on'), | |
| 72 msg='Line power is off.') | |
| 73 self.assertTrue(battery_status.get('battery_time_to_full') >= 0, | |
| 74 msg='Battery charge time is negative.') | |
| 75 | |
| 76 def testBatteryDischargesWhenACisOff(self): | |
| 77 """AC power OFF to CrOS device with battery.""" | |
| 78 self._power_strip.PowerOff(self._outlet_battery_full) | |
| 79 | |
| 80 # Get info about discharging battery | |
| 81 assert self.WaitUntil(lambda: self.BatteryPowerAndChargeStateAgree( | |
| 82 False, 'battery_time_to_empty'), timeout=60, retry_sleep=1),\ | |
| 83 'Battery discharge time was not calculated.' | |
| 84 battery_status = self.GetBatteryInfo() | |
| 85 self.assertTrue(battery_status.get('battery_is_present'), | |
| 86 msg='Battery is not present.') | |
| 87 self.assertFalse(battery_status.get('line_power_on'), | |
| 88 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!
| |
| 89 self.assertTrue(battery_status.get('battery_time_to_empty') >= 0, | |
| 90 msg='Battery discharge time is negative.') | |
| 91 | |
| 92 def testBatteryTimesAreDifferent(self): | |
| 93 """Time to full is different than Time to empty""" | |
| 94 # Turn AC Power ON | |
| 95 self._power_strip.PowerOn(self._outlet_battery_full) | |
| 96 | |
| 97 # Get charging battery time to full | |
| 98 assert self.WaitUntil(lambda: self.BatteryPowerAndChargeStateAgree( | |
| 99 True, 'battery_time_to_full'), timeout=60, retry_sleep=1),\ | |
| 100 'Battery charge time was not calculated.' | |
| 101 battery_status = self.GetBatteryInfo() | |
| 102 time_to_full = battery_status.get('battery_time_to_full') | |
| 103 | |
| 104 # Turn AC Power OFF | |
| 105 self._power_strip.PowerOff(self._outlet_battery_full) | |
| 106 | |
| 107 # Get discharging battery time to empty | |
| 108 assert self.WaitUntil(lambda: self.BatteryPowerAndChargeStateAgree( | |
| 109 False, 'battery_time_to_empty'), timeout=60, retry_sleep=1),\ | |
| 110 'Battery discharge time was not calculated.' | |
| 111 battery_status = self.GetBatteryInfo() | |
| 112 time_to_empty = battery_status.get('battery_time_to_empty') | |
| 113 | |
| 114 # Compare times | |
|
stanleyw
2011/06/06 20:54:50
Maybe explain why you are comparing the times.
| |
| 115 self.assertNotEqual(time_to_full, time_to_empty, | |
| 116 msg='Battery time to full equals time to empty. ' | |
| 117 'Though very unlikely, this is not impossible. ' | |
| 118 '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.
| |
| 119 | |
| 120 | |
| 121 if __name__ == '__main__': | |
| 122 pyauto_functional.Main() | |
| OLD | NEW |