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

Side by Side Diff: client/site_tests/power_LoadTest/power_LoadTest.py

Issue 2872027: External Extension for power_LoadTest (Closed) Base URL: ssh://gitrw.chromium.org/autotest.git
Patch Set: Added README with pack instructions. Cleaned up test loop, check_network. Created 10 years, 5 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
« no previous file with comments | « client/site_tests/power_LoadTest/external_extensions.json ('k') | 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
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging, os, re, shutil, time 5 import logging, os, re, shutil, time
6 from autotest_lib.client.bin import site_ui_test 6 from autotest_lib.client.bin import site_ui_test, site_login
7 from autotest_lib.client.common_lib import error, site_httpd, \ 7 from autotest_lib.client.common_lib import error, site_httpd, \
8 site_power_status, site_ui, utils 8 site_power_status, site_ui, utils
9 9
10 params_dict = { 10 params_dict = {
11 'test_time_ms': '_mseconds', 11 'test_time_ms': '_mseconds',
12 'should_scroll': '_should_scroll', 12 'should_scroll': '_should_scroll',
13 'should_scroll_up': '_should_scroll_up', 13 'should_scroll_up': '_should_scroll_up',
14 'scroll_loop': '_scroll_loop', 14 'scroll_loop': '_scroll_loop',
15 'scroll_interval_ms': '_scroll_interval_ms', 15 'scroll_interval_ms': '_scroll_interval_ms',
16 'scroll_by_pixels': '_scroll_by_pixels', 16 'scroll_by_pixels': '_scroll_by_pixels',
17 } 17 }
18 18
19 19
20 class power_LoadTest(site_ui_test.UITest): 20 class power_LoadTest(site_ui_test.UITest):
21 version = 1 21 version = 2
22 22
23 def setup(self): 23 def ensure_login_complete(self):
24 # TODO(snanda): Remove once power manager is in 24 """
25 shutil.copy(os.path.join(os.environ['SYSROOT'], 'usr/bin/xset'), 25 Override site_ui_test.UITest's ensure_login_complete.
26 self.bindir) 26 Do not use auth server and local dns for our test. We need to be
27 if not os.path.exists(self.srcdir): 27 able to reach the web.
28 os.mkdir(self.srcdir) 28 """
29 pass
29 30
30 31 def initialize(self, creds='$default', percent_initial_charge_min=None,
31 def run_once(self, percent_initial_charge_min=None,
32 check_network=True, loop_time=3600, loop_count=1, 32 check_network=True, loop_time=3600, loop_count=1,
33 should_scroll='true', should_scroll_up='true', 33 should_scroll='true', should_scroll_up='true',
34 scroll_loop='false', scroll_interval_ms='10000', 34 scroll_loop='false', scroll_interval_ms='10000',
35 scroll_by_pixels='600', low_battery_threshold=3, 35 scroll_by_pixels='600', low_battery_threshold=3,
36 verbose=True): 36 verbose=True):
37
37 """ 38 """
38 percent_initial_charge_min: min battery charge at start of test 39 percent_initial_charge_min: min battery charge at start of test
39 check_network: check that Ethernet interface is not running 40 check_network: check that Ethernet interface is not running
40 loop_count: number of times to loop the test for 41 loop_count: number of times to loop the test for
41 loop_time: length of time to run the test for in each loop 42 loop_time: length of time to run the test for in each loop
42 should_scroll: should the extension scroll pages 43 should_scroll: should the extension scroll pages
43 should_scroll_up: should scroll in up direction 44 should_scroll_up: should scroll in up direction
44 scroll_loop: continue scrolling indefinitely 45 scroll_loop: continue scrolling indefinitely
45 scroll_interval_ms: how often to scoll 46 scroll_interval_ms: how often to scoll
46 scroll_by_pixels: number of pixels to scroll each time 47 scroll_by_pixels: number of pixels to scroll each time
47 """ 48 """
48
49 self._loop_time = loop_time 49 self._loop_time = loop_time
50 self._loop_count = loop_count 50 self._loop_count = loop_count
51 self._mseconds = self._loop_time * 1000 51 self._mseconds = self._loop_time * 1000
52 self._verbose = verbose 52 self._verbose = verbose
53 self._low_battery_threshold = low_battery_threshold 53 self._low_battery_threshold = low_battery_threshold
54 self._should_scroll = should_scroll 54 self._should_scroll = should_scroll
55 self._should_scroll_up = should_scroll_up 55 self._should_scroll_up = should_scroll_up
56 self._scroll_loop = scroll_loop 56 self._scroll_loop = scroll_loop
57 self._scroll_interval_ms = scroll_interval_ms 57 self._scroll_interval_ms = scroll_interval_ms
58 self._scroll_by_pixels = scroll_by_pixels 58 self._scroll_by_pixels = scroll_by_pixels
59 self._tmp_keyvals = {} 59 self._tmp_keyvals = {}
60
61 self._power_status = site_power_status.get_status() 60 self._power_status = site_power_status.get_status()
62 61
63 # verify that initial conditions are met: 62 # verify that initial conditions are met:
64 if self._power_status.linepower[0].online: 63 if self._power_status.linepower[0].online:
65 raise error.TestError( 64 raise error.TestError(
66 'Running on AC power. Please remove AC power cable') 65 'Running on AC power. Please remove AC power cable')
67 66
68 percent_initial_charge = self._percent_current_charge() 67 percent_initial_charge = self._percent_current_charge()
69 if percent_initial_charge_min and percent_initial_charge < \ 68 if percent_initial_charge_min and percent_initial_charge < \
70 percent_initial_charge_min: 69 percent_initial_charge_min:
(...skipping 14 matching lines...) Expand all
85 utils.system_output(cmd).rstrip()) 84 utils.system_output(cmd).rstrip())
86 85
87 cmd = 'backlight-tool --get_brightness' 86 cmd = 'backlight-tool --get_brightness'
88 self._tmp_keyvals['level_backlight_current'] = int( 87 self._tmp_keyvals['level_backlight_current'] = int(
89 utils.system_output(cmd).rstrip()) 88 utils.system_output(cmd).rstrip())
90 89
91 # disable screen locker and powerd 90 # disable screen locker and powerd
92 os.system('stop screen-locker') 91 os.system('stop screen-locker')
93 os.system('stop powerd') 92 os.system('stop powerd')
94 93
95 # disable screen blanking. Stopping screen-locker isn't
96 # synchronous :(. Add a sleep for now, till powerd comes around
97 # and fixes all this for us.
98 time.sleep(5)
99 site_ui.xsystem(os.path.join(self.bindir, 'xset') + ' s off')
100 site_ui.xsystem(os.path.join(self.bindir, 'xset') + ' dpms 0 0 0')
101 site_ui.xsystem(os.path.join(self.bindir, 'xset') + ' -dpms')
102
103 # fix up file perms for the power test extension so that chrome 94 # fix up file perms for the power test extension so that chrome
104 # can access it 95 # can access it
105 os.system('chmod -R 755 %s' % self.bindir) 96 os.system('chmod -R 755 %s' % self.bindir)
106 97
98
99 # TODO (bleung) :
100 # The new external extension packed crx means we can't pass params by
101 # modifying params.js
102 # Possible solution :
103 # - modify extension to not start until we poke it from the browser.
104 # then pass through URL.
105
107 # write test parameters to the power extension's params.js file 106 # write test parameters to the power extension's params.js file
108 self._ext_path = os.path.join(self.bindir, 'extension') 107 # self._ext_path = os.path.join(self.bindir, 'extension')
109 self._write_ext_params() 108 # self._write_ext_params()
109
110 # copy external_extensions.json to known location
111 self._json_path = os.path.join(self.bindir, '..')
112 shutil.copy(os.path.join(self.bindir, 'external_extensions.json'),
113 self._json_path)
110 114
111 # setup a HTTP Server to listen for status updates from the power 115 # setup a HTTP Server to listen for status updates from the power
112 # test extension 116 # test extension
113 self._testServer = site_httpd.HTTPListener(8001, docroot=self.bindir) 117 self._testServer = site_httpd.HTTPListener(8001, docroot=self.bindir)
114 self._testServer.run() 118 self._testServer.run()
115 119
116 # initialize various interesting power related stats 120 # initialize various interesting power related stats
117 self._usb_stats = site_power_status.USBSuspendStats() 121 self._usb_stats = site_power_status.USBSuspendStats()
118 self._cpufreq_stats = site_power_status.CPUFreqStats() 122 self._cpufreq_stats = site_power_status.CPUFreqStats()
119 self._cpuidle_stats = site_power_status.CPUIdleStats() 123 self._cpuidle_stats = site_power_status.CPUIdleStats()
120 124
121 125
122 self._usb_stats.refresh() 126 self._usb_stats.refresh()
123 self._cpufreq_stats.refresh() 127 self._cpufreq_stats.refresh()
124 self._cpuidle_stats.refresh() 128 self._cpuidle_stats.refresh()
125 self._power_status.refresh() 129 self._power_status.refresh()
126 130
127 self._ah_charge_start = self._power_status.battery[0].charge_now 131 self._ah_charge_start = self._power_status.battery[0].charge_now
128 self._wh_energy_start = self._power_status.battery[0].energy 132 self._wh_energy_start = self._power_status.battery[0].energy
129 133
134 # from site_ui_test.UITest.initialize, sans authserver & local dns.
135 (self.username, self.password) = self._UITest__resolve_creds(creds)
136
137
138 def run_once(self):
139
130 t0 = time.time() 140 t0 = time.time()
131 141
132 for i in range(self._loop_count): 142 for i in range(self._loop_count):
133 # the power test extension will report its status here 143 # the power test extension will report its status here
134 latch = self._testServer.add_wait_url('/status') 144 latch = self._testServer.add_wait_url('/status')
135 145
136 # launch chrome with power test extension 146 if site_login.logged_in():
137 args = '--load-extension=%s' % self._ext_path 147 site_login.attempt_logout()
138 session = site_ui.ChromeSession(args, clean_state=False) 148 # the act of logging in will launch chrome with external extension.
149 self.login(self.username, self.password)
139 150
140 low_battery = self._do_wait(self._verbose, self._loop_time, 151 low_battery = self._do_wait(self._verbose, self._loop_time,
141 latch, session) 152 latch)
142 session.close()
143 153
144 if self._verbose: 154 if self._verbose:
145 logging.debug('loop %d completed' % i) 155 logging.debug('loop %d completed' % i)
146 logging.debug(utils.system_output('xset q')) 156 logging.debug(utils.system_output('xset q'))
147 157
148 if low_battery: 158 if low_battery:
149 logging.info('Exiting due to low battery') 159 logging.info('Exiting due to low battery')
150 break 160 break
151 161
152 t1 = time.time() 162 t1 = time.time()
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 203
194 keyvals['a_current_rate'] = keyvals['ah_charge_used'] * 60 / \ 204 keyvals['a_current_rate'] = keyvals['ah_charge_used'] * 60 / \
195 keyvals['minutes_battery_life'] 205 keyvals['minutes_battery_life']
196 keyvals['w_energy_rate'] = keyvals['wh_energy_used'] * 60 / \ 206 keyvals['w_energy_rate'] = keyvals['wh_energy_used'] * 60 / \
197 keyvals['minutes_battery_life'] 207 keyvals['minutes_battery_life']
198 208
199 self.write_perf_keyval(keyvals) 209 self.write_perf_keyval(keyvals)
200 210
201 211
202 def cleanup(self): 212 def cleanup(self):
213 # remove json file after test to stop external extension launch.
214 os.system('rm -f %s' %
215 os.path.join(self._json_path, 'external_extensions.json'))
203 # re-enable screen locker and powerd. This also re-enables dpms. 216 # re-enable screen locker and powerd. This also re-enables dpms.
204 os.system('start powerd') 217 os.system('start powerd')
205 os.system('start screen-locker') 218 os.system('start screen-locker')
206 219 if site_login.logged_in():
220 site_login.attempt_logout()
207 221
208 def _is_network_iface_running(self, name): 222 def _is_network_iface_running(self, name):
209 try: 223 try:
210 out = utils.system_output('ifconfig %s' % name) 224 out = utils.system_output('ifconfig %s' % name)
211 except error.CmdError, e: 225 except error.CmdError, e:
212 logging.info(e) 226 logging.info(e)
213 return False 227 return False
214 228
215 match = re.search('RUNNING', out, re.S) 229 match = re.search('RUNNING', out, re.S)
216 return match 230 return match
(...skipping 10 matching lines...) Expand all
227 for k in params_dict: 241 for k in params_dict:
228 data += template % (k, getattr(self, params_dict[k])) 242 data += template % (k, getattr(self, params_dict[k]))
229 243
230 filename = os.path.join(self._ext_path, 'params.js') 244 filename = os.path.join(self._ext_path, 'params.js')
231 utils.open_write_close(filename, data) 245 utils.open_write_close(filename, data)
232 246
233 logging.debug('filename ' + filename) 247 logging.debug('filename ' + filename)
234 logging.debug(data) 248 logging.debug(data)
235 249
236 250
237 def _do_wait(self, verbose, seconds, latch, session): 251 def _do_wait(self, verbose, seconds, latch):
238 latched = False 252 latched = False
239 low_battery = False 253 low_battery = False
240 total_time = seconds + 60 254 total_time = seconds + 60
241 elapsed_time = 0 255 elapsed_time = 0
242 wait_time = 60 256 wait_time = 60
243 257
244 while elapsed_time < total_time: 258 while elapsed_time < total_time:
245 time.sleep(wait_time) 259 time.sleep(wait_time)
246 elapsed_time += wait_time 260 elapsed_time += wait_time
247 261
(...skipping 19 matching lines...) Expand all
267 for e in form_data: 281 for e in form_data:
268 key = 'ext_' + e 282 key = 'ext_' + e
269 if key in self._tmp_keyvals: 283 if key in self._tmp_keyvals:
270 self._tmp_keyvals[key] += form_data[e] 284 self._tmp_keyvals[key] += form_data[e]
271 else: 285 else:
272 self._tmp_keyvals[key] = form_data[e] 286 self._tmp_keyvals[key] = form_data[e]
273 else: 287 else:
274 logging.debug("Didn't get status back from power extension") 288 logging.debug("Didn't get status back from power extension")
275 289
276 return low_battery 290 return low_battery
OLDNEW
« no previous file with comments | « client/site_tests/power_LoadTest/external_extensions.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698