Index: build/android/run_monkey_test.py |
diff --git a/build/android/run_monkey_test.py b/build/android/run_monkey_test.py |
index ab759156d1b190adf4479ccaa53a1389797073f7..faa6c33dfb468b008a06d6206a3ce4bebd1cc806 100755 |
--- a/build/android/run_monkey_test.py |
+++ b/build/android/run_monkey_test.py |
@@ -7,6 +7,7 @@ |
import logging |
import optparse |
import time |
+import random |
frankf
2012/09/11 17:36:51
not alphabetical. Please run gpylint.
|
from pylib import android_commands |
from pylib import python_test_base |
@@ -25,22 +26,22 @@ class MonkeyTest(python_test_base.PythonTestBase): |
start_ms = int(time.time()) * 1000 |
# Launch and wait for Chrome to launch. |
- self.adb.StartActivity(self.options['package_name'], |
- self.options.pop('activity_name'), |
+ self.adb.StartActivity(self.options.package_name, |
+ self.options.activity_name, |
wait_for_completion=True, |
action='android.intent.action.MAIN') |
# Chrome crashes are not always caught by Monkey test runner. |
# Verify Chrome has the same PID before and after the test. |
- before_pids = self.adb.ExtractPid(self.options['package_name']) |
+ before_pids = self.adb.ExtractPid(self.options.package_name) |
# Run the test. |
output = '' |
duration_ms = 0 |
if before_pids: |
- output = '\n'.join(self.adb.RunMonkey(**self.options)) |
+ output = '\n'.join(RunMonkey(self.adb, self.options)) |
duration_ms = int(time.time()) * 1000 - start_ms |
- after_pids = self.adb.ExtractPid(self.options['package_name']) |
+ after_pids = self.adb.ExtractPid(self.options.package_name) |
crashed = (not before_pids or not after_pids |
or after_pids[0] != before_pids[0]) |
@@ -61,7 +62,6 @@ def DispatchPythonTests(options): |
logger = logging.getLogger() |
logger.setLevel(logging.DEBUG) |
- build_type = options.pop('build_type') |
available_tests = [MonkeyTest('testMonkey', options)] |
attached_devices = android_commands.GetAttachedDevices() |
if not attached_devices: |
@@ -73,16 +73,52 @@ def DispatchPythonTests(options): |
sharder = python_test_sharder.PythonTestSharder( |
attached_devices, 1, available_tests) |
result = sharder.RunShardedTests() |
- result.LogFull('Monkey', 'Monkey', build_type) |
+ result.LogFull('Monkey', 'Monkey', options.build_type) |
result.PrintAnnotation() |
+def RunMonkey(adb, options): |
bulach
2012/09/11 11:08:49
nit: if nothing else will use this, please make it
frankf
2012/09/11 17:36:51
I prefer to have explicit parameters with default
Isaac (away)
2012/09/13 03:06:18
This style of defaults is consistent with the rest
Isaac (away)
2012/09/13 03:06:18
Done.
|
+ """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. |
+ verbosity: Verbosity level [0-3]. |
+ extra_args: A string of other args to pass to the command verbatim. |
bulach
2012/09/11 11:08:49
if this is becomes a method, please remove this Ar
Isaac (away)
2012/09/13 03:06:18
Done.
|
+ |
+ Returns: |
+ Output of the test run. |
+ """ |
+ category = options.category or [] |
+ seed = options.seed or random.randint(1, 100) |
+ throttle = options.throttle or 100 |
+ event_count = options.event_count or 10000 |
+ verbosity = options.verbosity or 1 |
+ extra_args = options.extra_args or '' |
+ |
+ cmd = ['monkey', |
+ '-p %s' % options.package_name, |
+ ' '.join(['-c %s' % c for c in category]), |
+ '--throttle %d' % throttle, |
+ '-s %d' % seed, |
+ '-v ' * verbosity, |
+ '--monitor-native-crashes', |
+ '--kill-process-after-error', |
+ extra_args, |
+ '%d' % event_count] |
+ return adb.RunShellCommand(' '.join(cmd), |
+ timeout_time=event_count*throttle*1.5) |
+ |
def main(): |
desc = 'Run the Monkey tests on 1 or more devices.' |
parser = optparse.OptionParser(description=desc) |
test_options_parser.AddBuildTypeOption(parser) |
- parser.add_option('--package-name', |
- help='Allowed package.') |
+ parser.add_option('--package-name', help='Allowed package.') |
parser.add_option('--activity-name', |
default='com.google.android.apps.chrome.Main', |
help='Name of the activity to start [default: %default].') |
@@ -112,7 +148,7 @@ def main(): |
if options.category: |
options.category = options.category.split(',') |
- DispatchPythonTests(vars(options)) |
+ DispatchPythonTests(options) |
if __name__ == '__main__': |