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 import time | 11 import time |
12 | 12 |
13 from pylib import android_commands | 13 from pylib import android_commands |
14 from pylib import python_test_base | 14 from pylib import python_test_base |
15 from pylib import python_test_sharder | 15 from pylib import python_test_sharder |
16 from pylib import test_options_parser | 16 from pylib import test_options_parser |
17 from pylib import test_result | 17 from pylib import test_result |
18 | 18 |
19 | 19 |
20 class MonkeyTest(python_test_base.PythonTestBase): | 20 class MonkeyTest(python_test_base.PythonTestBase): |
21 def testMonkey(self): | 21 def testMonkey(self): |
22 start_ms = int(time.time()) * 1000 | 22 start_ms = int(time.time()) * 1000 |
23 | 23 |
24 # Launch and wait for Chrome to launch. | 24 # Launch and wait for Chrome to launch. |
25 self.adb.StartActivity(self.options.package_name, | 25 self.adb.StartActivity(self.options.package_name, |
26 self.options.activity_name, | 26 self.options.activity_name, |
27 wait_for_completion=True, | 27 wait_for_completion=True, |
28 action='android.intent.action.MAIN') | 28 action='android.intent.action.MAIN', |
| 29 force_stop=True) |
29 | 30 |
30 # Chrome crashes are not always caught by Monkey test runner. | 31 # Chrome crashes are not always caught by Monkey test runner. |
31 # Verify Chrome has the same PID before and after the test. | 32 # Verify Chrome has the same PID before and after the test. |
32 before_pids = self.adb.ExtractPid(self.options.package_name) | 33 before_pids = self.adb.ExtractPid(self.options.package_name) |
33 | 34 |
34 # Run the test. | 35 # Run the test. |
35 output = '' | 36 output = '' |
36 duration_ms = 0 | 37 duration_ms = 0 |
37 if before_pids: | 38 if before_pids: |
38 output = '\n'.join(self._LaunchMonkeyTest()) | 39 output = '\n'.join(self._LaunchMonkeyTest()) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 '--throttle %d' % throttle, | 84 '--throttle %d' % throttle, |
84 '-s %d' % seed, | 85 '-s %d' % seed, |
85 '-v ' * verbosity, | 86 '-v ' * verbosity, |
86 '--monitor-native-crashes', | 87 '--monitor-native-crashes', |
87 '--kill-process-after-error', | 88 '--kill-process-after-error', |
88 extra_args, | 89 extra_args, |
89 '%d' % event_count] | 90 '%d' % event_count] |
90 return self.adb.RunShellCommand(' '.join(cmd), timeout_time=timeout_ms) | 91 return self.adb.RunShellCommand(' '.join(cmd), timeout_time=timeout_ms) |
91 | 92 |
92 | 93 |
93 | |
94 def DispatchPythonTests(options): | 94 def DispatchPythonTests(options): |
95 """Dispatches the Monkey tests, sharding it if there multiple devices.""" | 95 """Dispatches the Monkey tests, sharding it if there multiple devices.""" |
96 logger = logging.getLogger() | 96 logger = logging.getLogger() |
97 logger.setLevel(logging.DEBUG) | 97 logger.setLevel(logging.DEBUG) |
98 | 98 |
99 available_tests = [MonkeyTest('testMonkey')] | 99 available_tests = [MonkeyTest('testMonkey')] |
100 attached_devices = android_commands.GetAttachedDevices() | 100 attached_devices = android_commands.GetAttachedDevices() |
101 if not attached_devices: | 101 if not attached_devices: |
102 raise Exception('You have no devices attached or visible!') | 102 raise Exception('You have no devices attached or visible!') |
103 | 103 |
104 # Actually run the tests. | 104 # Actually run the tests. |
105 logging.debug('Running monkey tests.') | 105 logging.debug('Running monkey tests.') |
106 available_tests *= len(attached_devices) | 106 available_tests *= len(attached_devices) |
107 options.ensure_value('shard_retries',1) | 107 options.ensure_value('shard_retries', 1) |
108 sharder = python_test_sharder.PythonTestSharder( | 108 sharder = python_test_sharder.PythonTestSharder( |
109 attached_devices, available_tests, options) | 109 attached_devices, available_tests, options) |
110 result = sharder.RunShardedTests() | 110 result = sharder.RunShardedTests() |
111 result.LogFull('Monkey', 'Monkey', options.build_type) | 111 result.LogFull('Monkey', 'Monkey', options.build_type) |
112 result.PrintAnnotation() | 112 result.PrintAnnotation() |
113 | 113 |
| 114 |
114 def main(): | 115 def main(): |
115 desc = 'Run the Monkey tests on 1 or more devices.' | 116 desc = 'Run the Monkey tests on 1 or more devices.' |
116 parser = optparse.OptionParser(description=desc) | 117 parser = optparse.OptionParser(description=desc) |
117 test_options_parser.AddBuildTypeOption(parser) | 118 test_options_parser.AddBuildTypeOption(parser) |
118 parser.add_option('--package-name', help='Allowed package.') | 119 parser.add_option('--package-name', help='Allowed package.') |
119 parser.add_option('--activity-name', | 120 parser.add_option('--activity-name', |
120 default='com.google.android.apps.chrome.Main', | 121 default='com.google.android.apps.chrome.Main', |
121 help='Name of the activity to start [default: %default].') | 122 help='Name of the activity to start [default: %default].') |
122 parser.add_option('--category', | 123 parser.add_option('--category', |
123 help='A list of allowed categories [default: ""].') | 124 help='A list of allowed categories [default: ""].') |
(...skipping 21 matching lines...) Expand all Loading... |
145 parser.error('Missing package name') | 146 parser.error('Missing package name') |
146 | 147 |
147 if options.category: | 148 if options.category: |
148 options.category = options.category.split(',') | 149 options.category = options.category.split(',') |
149 | 150 |
150 DispatchPythonTests(options) | 151 DispatchPythonTests(options) |
151 | 152 |
152 | 153 |
153 if __name__ == '__main__': | 154 if __name__ == '__main__': |
154 main() | 155 main() |
OLD | NEW |