Index: build/android/pylib/android_commands.py |
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py |
index b5559ed63c7efb4731cd42e5314a6ed6654c0c27..6ed36f28a7e40e072f6dbc58719db9fdb30a100f 100644 |
--- a/build/android/pylib/android_commands.py |
+++ b/build/android/pylib/android_commands.py |
@@ -11,6 +11,7 @@ import collections |
import datetime |
import logging |
import os |
+import random |
import re |
import shlex |
import subprocess |
@@ -312,7 +313,7 @@ class AndroidCommands(object): |
Args: |
package_file_path: Path to .apk file to install. |
- reinstall: Whether to reinstall over existing package |
+ reinstall: Reinstall an existing apk. |
Returns: |
A status string returned by adb install |
@@ -327,14 +328,14 @@ class AndroidCommands(object): |
return self._adb.SendCommand(install_cmd % package_file_path, |
timeout_time=2*60, retry_count=0) |
- def ManagedInstall(self, apk_path, keep_data, package_name=None, |
+ def ManagedInstall(self, apk_path, package_name=None, reinstall=False, |
reboots_on_failure=2): |
"""Installs specified package and reboots device on timeouts. |
Args: |
apk_path: Path to .apk file to install. |
- keep_data: Whether to keep data if package already exists |
- package_name: Package name (only needed if keep_data=False) |
+ package_name: Package name (only needed if reinstall=False) |
+ 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.
|
reboots_on_failure: number of time to reboot if package manager is frozen. |
Returns: |
@@ -343,9 +344,10 @@ class AndroidCommands(object): |
reboots_left = reboots_on_failure |
while True: |
try: |
- if not keep_data: |
+ if not reinstall: |
+ assert package_name |
self.Uninstall(package_name) |
- install_status = self.Install(apk_path, keep_data) |
+ install_status = self.Install(apk_path, reinstall=reinstall) |
if 'Success' in install_status: |
return install_status |
except errors.WaitForResponseTimedOutError: |
@@ -987,3 +989,38 @@ class AndroidCommands(object): |
break |
logging.info('PidsUsingDevicePort: %s', pids) |
return pids |
+ |
+ def RunMonkey(self, package_name, category=None, throttle=100, seed=None, |
+ event_count=10000, verbose=1, extra_args=''): |
+ """Runs monkey test for a given package. |
+ |
+ Args: |
+ package_name: Allowed package. |
+ category: A list of allowed categories. |
+ throttle: Delay between events (ms). |
+ seed: Seed value for pseduo-random generator. Same seed value |
+ generates the same sequence of events. Seed is randomized by |
+ default. |
+ event_count: Number of events to generate. |
+ verbose: Verbosity level [0-3]. |
+ extra_args: A string of other args to pass to the command verbatim. |
+ |
+ Returns: |
+ Output of the test run. |
+ """ |
+ 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.
|
+ category = [] |
+ |
+ if not seed: |
+ 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.
|
+ |
+ cmd = ['monkey', |
+ '-p %s' % package_name, |
+ ' '.join(['-c %s' % c for c in category]), |
+ '--throttle %d' % throttle, |
+ '-s %d' % seed, |
+ ' '.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 -
|
+ extra_args, |
+ '%s' % event_count] |
+ return self.RunShellCommand(' '.join(cmd), |
+ timeout_time=event_count*throttle*1.5) |