Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/test/functional/chromeos_battery.py

Issue 6990069: Adding PyAuto Battery test for ChromeOS (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 import time
dtu 2011/06/01 01:09:23 Remove extra import.
xot 2011/06/06 02:27:19 Done.
8
9 import pyauto_functional # Must be imported before pyauto
10 import pyauto
11
12 from chromeos.power_strip import PowerStrip
13
14 class ChromeosBattery(pyauto.PyUITest):
15 """Tests ChromeOS Battery Status API.
Nirnimesh 2011/06/01 00:33:00 nit: leave a blank line after this line Remove 'A
xot 2011/06/06 02:27:19 Done.
16 Preconditions:
17 1) Device under test (DUT) is connected to the corporate LAN
Nirnimesh 2011/06/01 00:33:00 remove reference to 'corporate'. Just mention that
xot 2011/06/06 02:27:19 Done.
18 LAN via Ethernet-to-USB adapter plugged into one of its
19 USB ports.
20 2) AC power cable is connected to the DUT, and plugged into
21 the IP controlled Power Switch, outlet #4, located in the
Nirnimesh 2011/06/01 00:33:00 remove name of the lab
xot 2011/06/06 02:27:19 Done.
22 Oyster Bay lab.
23 3) Battery is installed in the DUT, and battery is not fully
24 discharged.
25
26 Note about calculation time:
27 When AC power is turned off or on, the battery will take from 2
28 to 60 seconds to calculate the time left. While calculating, the
29 keys 'battery_time_to_full' and 'battery_time_to_empty' are
30 absent.
31 """
32
33 _OUTLET_WITH_BATTERY = '.a4'
dtu 2011/06/01 01:09:23 Put this in the configuration file and read it fro
xot 2011/06/06 02:27:19 Done.
34 _BATTERY_CONFIG_FILE = os.path.join(pyauto.PyUITest.DataDir(),
35 'pyauto_private', 'chromeos', 'power',
dtu 2011/06/01 01:09:23 nit: Indent these lines by one space.
xot 2011/06/06 02:27:19 Done.
36 'battery_testbed_config')
dtu 2011/06/01 01:09:23 Does this configuration file exist yet? Please sta
xot 2011/06/06 02:27:19 Yes file exists. It was sent out as issue https://
37
38 def setUp(self):
39 pyauto.PyUITest.setUp(self)
40 self.InitPowerStrip()
41
42 def tearDown(self):
43 # Leave power outlet On so battery does not discharge
44 self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY)
45 pyauto.PyUITest.tearDown(self)
46
47 def InitPowerStrip(self):
48 self.assertTrue(
Nirnimesh 2011/06/01 00:33:00 replace self.assertTrue with 'assert' Use self.as
xot 2011/06/06 02:27:19 Done.
49 lambda: os.path.exists(ChromeosBattery._BATTERY_CONFIG_FILE),
50 msg = 'Power Strip configuration file does not exist.')
51 power_config = pyauto.PyUITest.EvalDataFrom(
52 ChromeosBattery._BATTERY_CONFIG_FILE)
53 self._power_strip = PowerStrip(power_config['strip_ip'])
54
55 def WaitUntilBatteryTimeIsCalculated(self):
56 battery_status = self.GetBatteryInfo()
57 if battery_status.get('line_power_on'):
58 time_key = 'battery_time_to_full'
59 else:
60 time_key = 'battery_time_to_empty'
61 return self.WaitUntil(lambda: self.GetBatteryInfo().get(time_key) != None,
62 timeout=60,
63 retry_sleep=2)
64
65 def testBatteryChargesWhenACisOn(self):
66 """AC power ON to CrOS device with battery."""
67 self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY)
68
69 # Get info about charging battery
70 self.assertTrue(self.WaitUntilBatteryTimeIsCalculated(),
71 msg='Battery charge time was not calculated')
72 battery_status = self.GetBatteryInfo()
73 self.assertTrue(battery_status.get('battery_is_present'),
74 msg='Battery is not present.')
75 self.assertTrue(battery_status.get('line_power_on'),
76 msg='Line power is off.')
77 self.assertTrue(battery_status.get('battery_time_to_full') >= 0,
78 msg='Battery charge time is negative.')
79
80 def testBatteryDischargesWhenACisOff(self):
81 """AC power OFF to CrOS device with battery."""
82 self._power_strip.PowerOff(ChromeosBattery._OUTLET_WITH_BATTERY)
83
84 # Get info about discharging battery
85 self.assertTrue(self.WaitUntilBatteryTimeIsCalculated(),
86 msg='Battery discharge time was not calculated.')
87 battery_status = self.GetBatteryInfo()
88 self.assertTrue(battery_status.get('battery_is_present'),
89 msg='Battery is not present.')
90 self.assertFalse(battery_status.get('line_power_on'),
91 msg='Line power is off.')
92 self.assertTrue(battery_status.get('battery_time_to_empty') >= 0,
93 msg='Battery discharge time is negative.')
94
95 def testBatteryTimesAreDifferent(self):
96 """Time until full is different than Time until empty"""
97 # Turn AC Power ON
98 self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY)
99
100 # Get charging battery time to full
101 self.WaitUntilBatteryTimeIsCalculated()
102 battery_status = self.GetBatteryInfo()
103 time_to_full = battery_status.get('battery_time_to_full')
104
105 # Turn AC Power OFF
106 self._power_strip.PowerOff(ChromeosBattery._OUTLET_WITH_BATTERY)
107
108 # Get discharging battery time to empty
109 self.WaitUntilBatteryTimeIsCalculated()
110 battery_status = self.GetBatteryInfo()
111 time_to_empty = battery_status.get('battery_time_to_empty')
112
113 # Compare times
114 self.assertNotEqual(time_to_full, time_to_empty,
115 msg='Battery time to full equals time to empty. '
116 'Though very unlikely, this is not impossible. '
117 'If test failed falsely, Kris owes Scott a beer. ')
118
Nirnimesh 2011/06/01 00:33:00 nit: need another blank line here
xot 2011/06/06 02:27:19 Done.
119 if __name__ == '__main__':
120 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698