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 logging | |
dtu
2011/05/27 23:33:43
Unused import. Remove.
scottc
2011/05/31 15:40:21
Done.
| |
7 import os | |
8 import time | |
9 | |
10 import pyauto_functional | |
dtu
2011/05/27 23:33:43
Please say this:
import pyauto_functional # Must
scottc
2011/05/31 15:40:21
Done.
| |
11 import pyauto | |
12 | |
13 from chromeos.power_strip import PowerStrip | |
14 | |
15 class ChromeosBattery(pyauto.PyUITest): | |
16 """Tests ChromeOS Battery Status API. | |
17 Preconditions: | |
18 1) Device under test (DUT) is connected to the corporate LAN | |
19 LAN via Ethernet-to-USB adapter plugged into one of its | |
20 USB ports. | |
21 2) AC power cable is connected to the DUT, and plugged into | |
22 the IP controlled Power Switch, outlet #4, located in the | |
23 Oyster Bay lab. | |
24 3) Battery is installed in the DUT, and battery is not fully | |
25 discharged. | |
26 | |
27 Battery Info is a dictionary with keys: | |
dtu
2011/05/27 23:33:43
You don't need to include the entire dictionary in
scottc
2011/05/31 15:40:21
Removed.
| |
28 'battery_is_present': bool | |
29 'line_power_on': bool | |
30 if 'battery_is_present': | |
31 'battery_percentage': float (0 ~ 100) | |
32 'battery_fully_charged': bool | |
33 if 'line_power_on': | |
34 'battery_time_to_full': int (seconds) | |
35 else: | |
36 'battery_time_to_empty': int (seconds) | |
37 | |
38 When AC power is turn off or on, the battery will take from 2 | |
39 to 60 seconds to calculate the time left. While calculating, the | |
40 keys 'battery_time_to_full' and 'battery_time_to_empty' are | |
41 absent. | |
42 """ | |
43 | |
44 _OUTLET_WITH_BATTERY = '.a4' | |
45 _BATTERY_CONFIG_FILE = os.path.join(pyauto.PyUITest.DataDir(), | |
46 'pyauto_private', 'chromeos', 'power', | |
47 'battery_testbed_config') | |
48 | |
49 def setUp(self): | |
50 pyauto.PyUITest.setUp(self) | |
51 self.InitPowerStrip() | |
52 | |
53 | |
dtu
2011/05/27 23:33:43
One blank line between function definitions inside
scottc
2011/05/31 15:40:21
Done.
| |
54 def tearDown(self): | |
55 # Leave power outlet On so battery does not discharge | |
56 self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY) | |
57 pyauto.PyUITest.tearDown(self) | |
58 | |
59 | |
60 def InitPowerStrip(self): | |
61 self.assertTrue( | |
62 lambda: os.path.exists(ChromeosBattery._BATTERY_CONFIG_FILE), | |
63 msg = 'Power Strip configuration file does not exist.') | |
64 power_config = / | |
65 pyauto.PyUITest.EvalDataFrom(ChromeosBattery._BATTERY_CONFIG_FILE) | |
66 self._power_strip = PowerStrip(power_config['strip_ip']) | |
67 | |
68 | |
69 def WaitUntilBatteryTimeIsCalculated(self): | |
70 battery_status = self.GetBatteryInfo() | |
71 if battery_status.get('line_power_on'): | |
72 time_key = 'battery_time_to_full' | |
73 else: | |
74 time_key = 'battery_time_to_empty' | |
75 return self.WaitUntil(lambda: self.GetBatteryInfo().get(time_key) != None, | |
76 timeout=60, | |
77 retry_sleep=2) | |
dtu
2011/05/27 23:33:43
Probably want to shorten the timeout and keep the
scottc
2011/05/31 15:40:21
During testing, I've seen it sometimes take up to
dtu
2011/06/01 01:09:23
Okay, in that case it is fine.
On 2011/05/31 15:4
| |
78 | |
79 | |
80 def testBatteryChargesWhenACisOn(self): | |
81 """AC power ON to CrOS device with battery.""" | |
82 self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY) | |
83 time.sleep(2) # Wait for swtich to settle | |
dtu
2011/05/27 23:33:43
switch*
scottc
2011/05/31 15:40:21
Removed.
| |
84 | |
85 # Get info about charging battery | |
86 self.assertTrue(self.WaitUntilBatteryTimeIsCalculated(), | |
87 msg='Battery charge time was not calculated') | |
88 battery_status = self.GetBatteryInfo() | |
89 self.assertTrue(battery_status.get('battery_is_present'), | |
90 msg='Battery is not present.') | |
91 self.assertTrue(battery_status.get('line_power_on'), | |
92 msg='Line power is off.') | |
93 self.assertTrue(battery_status.get('battery_time_to_full') >= 0, | |
94 msg='Battery charge time is negative.') | |
95 | |
96 | |
97 def testBatteryDischargesWhenACisOff(self): | |
98 """AC power OFF to CrOS device with battery.""" | |
99 self._power_strip.PowerOff(ChromeosBattery._OUTLET_WITH_BATTERY) | |
100 time.sleep(2) # Wait for switch to settle | |
dtu
2011/05/27 23:33:43
Does it take some time for it to notice that the l
scottc
2011/05/31 15:40:21
Removed.
| |
101 | |
102 # Get info about discharging battery | |
103 self.assertTrue(self.WaitUntilBatteryTimeIsCalculated(), | |
104 msg='Battery discharge time was not calculated.') | |
105 battery_status = self.GetBatteryInfo() | |
106 self.assertTrue(battery_status.get('battery_is_present'), | |
107 msg='Battery is not present.') | |
108 self.assertFalse(battery_status.get('line_power_on'), | |
109 msg='Line power is off.') | |
110 self.assertTrue(battery_status.get('battery_time_to_empty') >= 0, | |
111 msg='Battery discharge time is negative.') | |
112 | |
113 | |
114 def testBatteryTimesAreDifferent(self): | |
115 """Time until full is different than Time until empty""" | |
116 # Turn AC Power ON | |
117 self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY) | |
118 time.sleep(2) | |
119 | |
120 # Get charging battery time to full | |
121 self.WaitUntilBatteryTimeIsCalculated() | |
122 battery_status = self.GetBatteryInfo() | |
123 time_to_full = battery_status.get('battery_time_to_full') | |
124 | |
125 # Turn AC Power OFF | |
126 self._power_strip.PowerOff(ChromeosBattery._OUTLET_WITH_BATTERY) | |
127 time.sleep(2) | |
128 | |
129 # Get discharging battery time to empty | |
130 self.WaitUntilBatteryTimeIsCalculated() | |
131 battery_status = self.GetBatteryInfo() | |
132 time_to_empty = battery_status.get('battery_time_to_empty') | |
133 | |
134 # Compare times | |
135 self.assertNotEqual(time_to_full, time_to_empty, | |
136 msg='Battery time to full equals time to empty. ' | |
137 'Though very unlikely, this is not impossible. ' | |
138 'If test failed falsely, Kris ows Scott a beer. ') | |
dtu
2011/05/27 23:33:43
owes*
scottc
2011/05/31 15:40:21
Done.
| |
139 | |
140 if __name__ == '__main__': | |
141 pyauto_functional.Main() | |
OLD | NEW |