OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Runs the Monkey tests on one or more devices.""" | 6 """Runs the Monkey tests on one or more devices.""" |
7 import logging | 7 import logging |
8 import optparse | 8 import optparse |
9 import random | 9 import random |
| 10 import sys |
10 import time | 11 import time |
11 | 12 |
12 from pylib import android_commands | 13 from pylib import android_commands |
13 from pylib import python_test_base | 14 from pylib import python_test_base |
14 from pylib import python_test_sharder | 15 from pylib import python_test_sharder |
15 from pylib import test_options_parser | 16 from pylib import test_options_parser |
16 from pylib import test_result | 17 from pylib import test_result |
17 | 18 |
18 | 19 |
19 class MonkeyTest(python_test_base.PythonTestBase): | 20 class MonkeyTest(python_test_base.PythonTestBase): |
20 def __init__(self, test_name, options): | |
21 self.options = options | |
22 super(MonkeyTest, self).__init__(test_name) | |
23 | |
24 def testMonkey(self): | 21 def testMonkey(self): |
25 start_ms = int(time.time()) * 1000 | 22 start_ms = int(time.time()) * 1000 |
26 | 23 |
27 # Launch and wait for Chrome to launch. | 24 # Launch and wait for Chrome to launch. |
28 self.adb.StartActivity(self.options.package_name, | 25 self.adb.StartActivity(self.options.package_name, |
29 self.options.activity_name, | 26 self.options.activity_name, |
30 wait_for_completion=True, | 27 wait_for_completion=True, |
31 action='android.intent.action.MAIN') | 28 action='android.intent.action.MAIN') |
32 | 29 |
33 # Chrome crashes are not always caught by Monkey test runner. | 30 # Chrome crashes are not always caught by Monkey test runner. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 logger.setLevel(logging.DEBUG) | 97 logger.setLevel(logging.DEBUG) |
101 | 98 |
102 available_tests = [MonkeyTest('testMonkey', options)] | 99 available_tests = [MonkeyTest('testMonkey', options)] |
103 attached_devices = android_commands.GetAttachedDevices() | 100 attached_devices = android_commands.GetAttachedDevices() |
104 if not attached_devices: | 101 if not attached_devices: |
105 raise Exception('You have no devices attached or visible!') | 102 raise Exception('You have no devices attached or visible!') |
106 | 103 |
107 # Actually run the tests. | 104 # Actually run the tests. |
108 logging.debug('Running monkey tests.') | 105 logging.debug('Running monkey tests.') |
109 available_tests *= len(attached_devices) | 106 available_tests *= len(attached_devices) |
| 107 options.ensure_value('shard_retries',1) |
110 sharder = python_test_sharder.PythonTestSharder( | 108 sharder = python_test_sharder.PythonTestSharder( |
111 attached_devices, 1, available_tests) | 109 attached_devices, available_tests, options) |
112 result = sharder.RunShardedTests() | 110 result = sharder.RunShardedTests() |
113 result.LogFull('Monkey', 'Monkey', options.build_type) | 111 result.LogFull('Monkey', 'Monkey', options.build_type) |
114 result.PrintAnnotation() | 112 result.PrintAnnotation() |
115 | 113 |
116 def main(): | 114 def main(): |
117 desc = 'Run the Monkey tests on 1 or more devices.' | 115 desc = 'Run the Monkey tests on 1 or more devices.' |
118 parser = optparse.OptionParser(description=desc) | 116 parser = optparse.OptionParser(description=desc) |
119 test_options_parser.AddBuildTypeOption(parser) | 117 test_options_parser.AddBuildTypeOption(parser) |
120 parser.add_option('--package-name', help='Allowed package.') | 118 parser.add_option('--package-name', help='Allowed package.') |
121 parser.add_option('--activity-name', | 119 parser.add_option('--activity-name', |
(...skipping 10 matching lines...) Expand all Loading... |
132 parser.add_option('--event-count', default=10000, type='int', | 130 parser.add_option('--event-count', default=10000, type='int', |
133 help='Number of events to generate [default: %default].') | 131 help='Number of events to generate [default: %default].') |
134 parser.add_option('--verbosity', default=1, type='int', | 132 parser.add_option('--verbosity', default=1, type='int', |
135 help='Verbosity level [0-3] [default: %default].') | 133 help='Verbosity level [0-3] [default: %default].') |
136 parser.add_option('--extra-args', default='', | 134 parser.add_option('--extra-args', default='', |
137 help=('String of other args to pass to the command verbatim' | 135 help=('String of other args to pass to the command verbatim' |
138 ' [default: "%default"].')) | 136 ' [default: "%default"].')) |
139 (options, args) = parser.parse_args() | 137 (options, args) = parser.parse_args() |
140 | 138 |
141 if args: | 139 if args: |
| 140 parser.print_help(sys.stderr) |
142 parser.error('Unknown arguments: %s' % args) | 141 parser.error('Unknown arguments: %s' % args) |
143 | 142 |
144 if not options.package_name: | 143 if not options.package_name: |
| 144 parser.print_help(sys.stderr) |
145 parser.error('Missing package name') | 145 parser.error('Missing package name') |
146 | 146 |
147 if options.category: | 147 if options.category: |
148 options.category = options.category.split(',') | 148 options.category = options.category.split(',') |
149 | 149 |
150 DispatchPythonTests(options) | 150 DispatchPythonTests(options) |
151 | 151 |
152 | 152 |
153 if __name__ == '__main__': | 153 if __name__ == '__main__': |
154 main() | 154 main() |
OLD | NEW |