Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: build/android/run_monkey_test.py

Issue 11273099: Restart app before running monkey test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 os
9 import random 10 import random
10 import sys 11 import sys
11 import time 12 import time
12 13
14 # Don't need these deps.
bulach 2012/10/30 10:52:50 hmm, which bit needs this? would it be possible to
frankf 2012/10/30 19:05:22 Good point. I fixed the root cause by moving class
15 os.environ['ANDROID_SDK_ROOT'] = ''
16 os.environ['ANDROID_BUILD_TOP'] = ''
17
13 from pylib import android_commands 18 from pylib import android_commands
14 from pylib import python_test_base 19 from pylib import python_test_base
15 from pylib import python_test_sharder 20 from pylib import python_test_sharder
16 from pylib import test_options_parser 21 from pylib import test_options_parser
17 from pylib import test_result 22 from pylib import test_result
18 23
19 24
20 class MonkeyTest(python_test_base.PythonTestBase): 25 class MonkeyTest(python_test_base.PythonTestBase):
21 def testMonkey(self): 26 def testMonkey(self):
22 start_ms = int(time.time()) * 1000 27 start_ms = int(time.time()) * 1000
23 28
24 # Launch and wait for Chrome to launch. 29 # Launch and wait for Chrome to launch.
25 self.adb.StartActivity(self.options.package_name, 30 self.adb.StartActivity(self.options.package_name,
26 self.options.activity_name, 31 self.options.activity_name,
32 force_stop=True,
27 wait_for_completion=True, 33 wait_for_completion=True,
28 action='android.intent.action.MAIN') 34 action='android.intent.action.MAIN')
29 35
30 # Chrome crashes are not always caught by Monkey test runner. 36 # Chrome crashes are not always caught by Monkey test runner.
31 # Verify Chrome has the same PID before and after the test. 37 # Verify Chrome has the same PID before and after the test.
32 before_pids = self.adb.ExtractPid(self.options.package_name) 38 before_pids = self.adb.ExtractPid(self.options.package_name)
33 39
34 # Run the test. 40 # Run the test.
35 output = '' 41 output = ''
36 duration_ms = 0 42 duration_ms = 0
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 '--throttle %d' % throttle, 89 '--throttle %d' % throttle,
84 '-s %d' % seed, 90 '-s %d' % seed,
85 '-v ' * verbosity, 91 '-v ' * verbosity,
86 '--monitor-native-crashes', 92 '--monitor-native-crashes',
87 '--kill-process-after-error', 93 '--kill-process-after-error',
88 extra_args, 94 extra_args,
89 '%d' % event_count] 95 '%d' % event_count]
90 return self.adb.RunShellCommand(' '.join(cmd), timeout_time=timeout_ms) 96 return self.adb.RunShellCommand(' '.join(cmd), timeout_time=timeout_ms)
91 97
92 98
93
94 def DispatchPythonTests(options): 99 def DispatchPythonTests(options):
95 """Dispatches the Monkey tests, sharding it if there multiple devices.""" 100 """Dispatches the Monkey tests, sharding it if there multiple devices."""
96 logger = logging.getLogger() 101 logger = logging.getLogger()
97 logger.setLevel(logging.DEBUG) 102 logger.setLevel(logging.DEBUG)
98 103
99 available_tests = [MonkeyTest('testMonkey')] 104 available_tests = [MonkeyTest('testMonkey')]
100 attached_devices = android_commands.GetAttachedDevices() 105 attached_devices = android_commands.GetAttachedDevices()
101 if not attached_devices: 106 if not attached_devices:
102 raise Exception('You have no devices attached or visible!') 107 raise Exception('You have no devices attached or visible!')
103 108
104 # Actually run the tests. 109 # Actually run the tests.
105 logging.debug('Running monkey tests.') 110 logging.debug('Running monkey tests.')
106 available_tests *= len(attached_devices) 111 available_tests *= len(attached_devices)
107 options.ensure_value('shard_retries',1) 112 options.ensure_value('shard_retries', 1)
108 sharder = python_test_sharder.PythonTestSharder( 113 sharder = python_test_sharder.PythonTestSharder(
109 attached_devices, available_tests, options) 114 attached_devices, available_tests, options)
110 result = sharder.RunShardedTests() 115 result = sharder.RunShardedTests()
111 result.LogFull('Monkey', 'Monkey', options.build_type) 116 result.LogFull('Monkey', 'Monkey', options.build_type)
112 result.PrintAnnotation() 117 result.PrintAnnotation()
113 118
119
114 def main(): 120 def main():
115 desc = 'Run the Monkey tests on 1 or more devices.' 121 desc = 'Run the Monkey tests on 1 or more devices.'
116 parser = optparse.OptionParser(description=desc) 122 parser = optparse.OptionParser(description=desc)
117 test_options_parser.AddBuildTypeOption(parser) 123 test_options_parser.AddBuildTypeOption(parser)
118 parser.add_option('--package-name', help='Allowed package.') 124 parser.add_option('--package-name', help='Allowed package.')
119 parser.add_option('--activity-name', 125 parser.add_option('--activity-name',
120 default='com.google.android.apps.chrome.Main', 126 default='com.google.android.apps.chrome.Main',
121 help='Name of the activity to start [default: %default].') 127 help='Name of the activity to start [default: %default].')
122 parser.add_option('--category', 128 parser.add_option('--category',
123 help='A list of allowed categories [default: ""].') 129 help='A list of allowed categories [default: ""].')
(...skipping 21 matching lines...) Expand all
145 parser.error('Missing package name') 151 parser.error('Missing package name')
146 152
147 if options.category: 153 if options.category:
148 options.category = options.category.split(',') 154 options.category = options.category.split(',')
149 155
150 DispatchPythonTests(options) 156 DispatchPythonTests(options)
151 157
152 158
153 if __name__ == '__main__': 159 if __name__ == '__main__':
154 main() 160 main()
OLDNEW
« build/android/pylib/android_commands.py ('K') | « build/android/pylib/android_commands.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698