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

Side by Side Diff: build/android/pylib/android_commands.py

Issue 10829289: Add monkey command to android_commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some renaming Created 8 years, 4 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium 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 """Provides an interface to communicate with the device via the adb command. 5 """Provides an interface to communicate with the device via the adb command.
6 6
7 Assumes adb binary is currently on system path. 7 Assumes adb binary is currently on system path.
8 """ 8 """
9 9
10 import collections 10 import collections
11 import datetime 11 import datetime
12 import logging 12 import logging
13 import os 13 import os
14 import random
14 import re 15 import re
15 import shlex 16 import shlex
16 import subprocess 17 import subprocess
17 import sys 18 import sys
18 import tempfile 19 import tempfile
19 import time 20 import time
20 21
21 import pexpect 22 import pexpect
22 import io_stats_parser 23 import io_stats_parser
23 24
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 uninstall_command = 'uninstall %s' % package 306 uninstall_command = 'uninstall %s' % package
306 307
307 logging.info('>>> $' + uninstall_command) 308 logging.info('>>> $' + uninstall_command)
308 return self._adb.SendCommand(uninstall_command, timeout_time=60) 309 return self._adb.SendCommand(uninstall_command, timeout_time=60)
309 310
310 def Install(self, package_file_path, reinstall=False): 311 def Install(self, package_file_path, reinstall=False):
311 """Installs the specified package to the device. 312 """Installs the specified package to the device.
312 313
313 Args: 314 Args:
314 package_file_path: Path to .apk file to install. 315 package_file_path: Path to .apk file to install.
315 reinstall: Whether to reinstall over existing package 316 reinstall: Reinstall an existing apk.
316 317
317 Returns: 318 Returns:
318 A status string returned by adb install 319 A status string returned by adb install
319 """ 320 """
320 assert os.path.isfile(package_file_path) 321 assert os.path.isfile(package_file_path)
321 322
322 if reinstall: 323 if reinstall:
323 install_cmd = 'install -r %s' 324 install_cmd = 'install -r %s'
324 else: 325 else:
325 install_cmd = 'install %s' 326 install_cmd = 'install %s'
326 327
327 return self._adb.SendCommand(install_cmd % package_file_path, 328 return self._adb.SendCommand(install_cmd % package_file_path,
328 timeout_time=2*60, retry_count=0) 329 timeout_time=2*60, retry_count=0)
329 330
330 def ManagedInstall(self, apk_path, keep_data, package_name=None, 331 def ManagedInstall(self, apk_path, package_name=None, reinstall=False,
331 reboots_on_failure=2): 332 reboots_on_failure=2):
332 """Installs specified package and reboots device on timeouts. 333 """Installs specified package and reboots device on timeouts.
333 334
334 Args: 335 Args:
335 apk_path: Path to .apk file to install. 336 apk_path: Path to .apk file to install.
336 keep_data: Whether to keep data if package already exists 337 package_name: Package name (only needed if reinstall=False)
337 package_name: Package name (only needed if keep_data=False) 338 reinstall: Whether to reinstall instead of uninstalling first.
Isaac (away) 2012/08/22 02:03:28 I know I said it was OK earlier but I think reinst
frankf 2012/08/22 21:46:55 Done.
338 reboots_on_failure: number of time to reboot if package manager is frozen. 339 reboots_on_failure: number of time to reboot if package manager is frozen.
339 340
340 Returns: 341 Returns:
341 A status string returned by adb install 342 A status string returned by adb install
342 """ 343 """
343 reboots_left = reboots_on_failure 344 reboots_left = reboots_on_failure
344 while True: 345 while True:
345 try: 346 try:
346 if not keep_data: 347 if not reinstall:
348 assert package_name
347 self.Uninstall(package_name) 349 self.Uninstall(package_name)
348 install_status = self.Install(apk_path, keep_data) 350 install_status = self.Install(apk_path, reinstall=reinstall)
349 if 'Success' in install_status: 351 if 'Success' in install_status:
350 return install_status 352 return install_status
351 except errors.WaitForResponseTimedOutError: 353 except errors.WaitForResponseTimedOutError:
352 print '@@@STEP_WARNINGS@@@' 354 print '@@@STEP_WARNINGS@@@'
353 logging.info('Timeout on installing %s' % apk_path) 355 logging.info('Timeout on installing %s' % apk_path)
354 356
355 if reboots_left <= 0: 357 if reboots_left <= 0:
356 raise Exception('Install failure') 358 raise Exception('Install failure')
357 359
358 # Force a hard reboot on last attempt 360 # Force a hard reboot on last attempt
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 if len(process_results) <= 8: 982 if len(process_results) <= 8:
981 continue 983 continue
982 # Column 0 is the executable name 984 # Column 0 is the executable name
983 # Column 1 is the pid 985 # Column 1 is the pid
984 # Column 8 is the Inode in use 986 # Column 8 is the Inode in use
985 if process_results[8] == socket_name: 987 if process_results[8] == socket_name:
986 pids.append((int(process_results[1]), process_results[0])) 988 pids.append((int(process_results[1]), process_results[0]))
987 break 989 break
988 logging.info('PidsUsingDevicePort: %s', pids) 990 logging.info('PidsUsingDevicePort: %s', pids)
989 return pids 991 return pids
992
993 def RunMonkey(self, package_name, category=None, throttle=100, seed=None,
994 event_count=10000, verbose=1, extra_args=''):
995 """Runs monkey test for a given package.
996
997 Args:
998 package_name: Allowed package.
999 category: A list of allowed categories.
1000 throttle: Delay between events (ms).
1001 seed: Seed value for pseduo-random generator. Same seed value
1002 generates the same sequence of events. Seed is randomized by
1003 default.
1004 event_count: Number of events to generate.
1005 verbose: Verbosity level [0-3].
1006 extra_args: A string of other args to pass to the command verbatim.
1007
1008 Returns:
1009 Output of the test run.
1010 """
1011 if category is None:
Isaac (away) 2012/08/22 02:03:28 the preferred way of doing this is: category = ca
frankf 2012/08/22 21:46:55 Done.
1012 category = []
1013
1014 if not seed:
1015 seed = random.randint(1, 100)
Isaac (away) 2012/08/22 02:03:28 seed = seed or random.randint(1, 100)
frankf 2012/08/22 21:46:55 Done.
1016
1017 cmd = ['monkey',
1018 '-p %s' % package_name,
1019 ' '.join(['-c %s' % c for c in category]),
1020 '--throttle %d' % throttle,
1021 '-s %d' % seed,
1022 ' '.join(['-v'] * verbose),
Isaac (away) 2012/08/22 02:03:28 don't like this syntax -- can you figure out an al
frankf 2012/08/22 21:46:55 The only other way is restrict verbose to a bool (
Isaac (away) 2012/08/22 21:53:19 Oh, I didn't realize you wanted to pass multiple -
1023 extra_args,
1024 '%s' % event_count]
1025 return self.RunShellCommand(' '.join(cmd),
1026 timeout_time=event_count*throttle*1.5)
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