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 sys |
11 | 11 |
12 from pylib import android_commands | 12 from pylib import android_commands |
| 13 from pylib import dispatch |
13 from pylib.base import base_test_result | 14 from pylib.base import base_test_result |
14 from pylib.host_driven import python_test_base | 15 from pylib.host_driven import python_test_base |
15 from pylib.host_driven import python_test_sharder | 16 from pylib.host_driven import python_test_sharder |
16 from pylib.utils import report_results | 17 from pylib.utils import report_results |
17 from pylib.utils import test_options_parser | 18 from pylib.utils import test_options_parser |
18 | 19 |
19 | 20 |
20 class MonkeyTest(python_test_base.PythonTestBase): | 21 class MonkeyTest(python_test_base.PythonTestBase): |
21 def testMonkey(self): | 22 def testMonkey(self): |
22 # Launch and wait for Chrome to launch. | 23 # Launch and wait for Chrome to launch. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 '--throttle %d' % throttle, | 81 '--throttle %d' % throttle, |
81 '-s %d' % seed, | 82 '-s %d' % seed, |
82 '-v ' * verbosity, | 83 '-v ' * verbosity, |
83 '--monitor-native-crashes', | 84 '--monitor-native-crashes', |
84 '--kill-process-after-error', | 85 '--kill-process-after-error', |
85 extra_args, | 86 extra_args, |
86 '%d' % event_count] | 87 '%d' % event_count] |
87 return self.adb.RunShellCommand(' '.join(cmd), timeout_time=timeout_ms) | 88 return self.adb.RunShellCommand(' '.join(cmd), timeout_time=timeout_ms) |
88 | 89 |
89 | 90 |
90 def DispatchPythonTests(options): | 91 def RunMonkeyTests(options): |
91 """Dispatches the Monkey tests, sharding it if there multiple devices.""" | 92 """Runs the Monkey tests, replicating it if there multiple devices.""" |
92 logger = logging.getLogger() | 93 logger = logging.getLogger() |
93 logger.setLevel(logging.DEBUG) | 94 logger.setLevel(logging.DEBUG) |
94 attached_devices = android_commands.GetAttachedDevices() | |
95 if not attached_devices: | |
96 raise Exception('You have no devices attached or visible!') | |
97 | 95 |
98 # Actually run the tests. | 96 # Actually run the tests. |
99 logging.debug('Running monkey tests.') | 97 logging.debug('Running monkey tests.') |
100 # TODO(frankf): This is a stop-gap solution. Come up with a | 98 available_tests = [MonkeyTest('testMonkey')] |
101 # general way for running tests on every devices. | 99 |
102 available_tests = [] | 100 def TestRunnerFactory(device, shard_index): |
103 for k in range(len(attached_devices)): | 101 return python_test_sharder.PythonTestRunner(options, device, shard_index) |
104 new_method = 'testMonkey%d' % k | 102 |
105 setattr(MonkeyTest, new_method, MonkeyTest.testMonkey) | 103 results, exit_code = dispatch.Dispatch( |
106 available_tests.append(MonkeyTest(new_method)) | 104 options, available_tests, TestRunnerFactory, distribution='replicate') |
107 options.ensure_value('shard_retries', 1) | |
108 sharder = python_test_sharder.PythonTestSharder( | |
109 attached_devices, available_tests, options) | |
110 results = sharder.RunShardedTests() | |
111 report_results.LogFull( | 105 report_results.LogFull( |
112 results=results, | 106 results=results, |
113 test_type='Monkey', | 107 test_type='Monkey', |
114 test_package='Monkey', | 108 test_package='Monkey', |
115 build_type=options.build_type) | 109 build_type=options.build_type) |
116 # TODO(gkanwar): After the host-driven tests have been refactored, they sould | 110 |
117 # use the comment exit code system (part of pylib/base/shard.py) | 111 return exit_code |
118 if not results.DidRunPass(): | |
119 return 1 | |
120 return 0 | |
121 | 112 |
122 | 113 |
123 def main(): | 114 def main(): |
124 desc = 'Run the Monkey tests on 1 or more devices.' | 115 desc = 'Run the Monkey tests on 1 or more devices.' |
125 parser = optparse.OptionParser(description=desc) | 116 parser = optparse.OptionParser(description=desc) |
126 test_options_parser.AddBuildTypeOption(parser) | 117 test_options_parser.AddBuildTypeOption(parser) |
127 parser.add_option('--package-name', help='Allowed package.') | 118 parser.add_option('--package-name', help='Allowed package.') |
128 parser.add_option('--activity-name', | 119 parser.add_option('--activity-name', |
129 default='com.google.android.apps.chrome.Main', | 120 default='com.google.android.apps.chrome.Main', |
130 help='Name of the activity to start [default: %default].') | 121 help='Name of the activity to start [default: %default].') |
(...skipping 18 matching lines...) Expand all Loading... |
149 parser.print_help(sys.stderr) | 140 parser.print_help(sys.stderr) |
150 parser.error('Unknown arguments: %s' % args) | 141 parser.error('Unknown arguments: %s' % args) |
151 | 142 |
152 if not options.package_name: | 143 if not options.package_name: |
153 parser.print_help(sys.stderr) | 144 parser.print_help(sys.stderr) |
154 parser.error('Missing package name') | 145 parser.error('Missing package name') |
155 | 146 |
156 if options.category: | 147 if options.category: |
157 options.category = options.category.split(',') | 148 options.category = options.category.split(',') |
158 | 149 |
159 DispatchPythonTests(options) | 150 RunMonkeyTests(options) |
160 | 151 |
161 | 152 |
162 if __name__ == '__main__': | 153 if __name__ == '__main__': |
163 main() | 154 main() |
OLD | NEW |