Moved RunMonkeyTests out of android_commands.py
(it did not fit) - simplified calling structure. R=frankf@chromium.org,bulach@chromium.org,klundberg@chromium.org BUG= Review URL: https://chromiumcodereview.appspot.com/10908188 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156511 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
build/android
@@ -11,7 +11,6 @@ import collections
|
|||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -1003,37 +1002,3 @@ class AndroidCommands(object):
|
|||||||
status = self._adb.SendShellCommand(
|
status = self._adb.SendShellCommand(
|
||||||
'\'ls "%s" >/dev/null 2>&1; echo $?\'' % (file_name))
|
'\'ls "%s" >/dev/null 2>&1; echo $?\'' % (file_name))
|
||||||
return int(status) == 0
|
return int(status) == 0
|
||||||
|
|
||||||
def RunMonkey(self, package_name, category=None, throttle=100, seed=None,
|
|
||||||
event_count=10000, verbosity=1, extra_args=''):
|
|
||||||
"""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.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Output of the test run.
|
|
||||||
"""
|
|
||||||
category = category or []
|
|
||||||
seed = seed or random.randint(1, 100)
|
|
||||||
|
|
||||||
cmd = ['monkey',
|
|
||||||
'-p %s' % 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 self.RunShellCommand(' '.join(cmd),
|
|
||||||
timeout_time=event_count*throttle*1.5)
|
|
||||||
|
@@ -6,11 +6,11 @@
|
|||||||
"""Runs the Monkey tests on one or more devices."""
|
"""Runs the Monkey tests on one or more devices."""
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
import optparse
|
||||||
|
import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from pylib import android_commands
|
from pylib import android_commands
|
||||||
from pylib import python_test_base
|
from pylib import python_test_base
|
||||||
from pylib import python_test_caller
|
|
||||||
from pylib import python_test_sharder
|
from pylib import python_test_sharder
|
||||||
from pylib import test_options_parser
|
from pylib import test_options_parser
|
||||||
from pylib import test_result
|
from pylib import test_result
|
||||||
@@ -25,22 +25,22 @@ class MonkeyTest(python_test_base.PythonTestBase):
|
|||||||
start_ms = int(time.time()) * 1000
|
start_ms = int(time.time()) * 1000
|
||||||
|
|
||||||
# Launch and wait for Chrome to launch.
|
# Launch and wait for Chrome to launch.
|
||||||
self.adb.StartActivity(self.options['package_name'],
|
self.adb.StartActivity(self.options.package_name,
|
||||||
self.options.pop('activity_name'),
|
self.options.activity_name,
|
||||||
wait_for_completion=True,
|
wait_for_completion=True,
|
||||||
action='android.intent.action.MAIN')
|
action='android.intent.action.MAIN')
|
||||||
|
|
||||||
# Chrome crashes are not always caught by Monkey test runner.
|
# Chrome crashes are not always caught by Monkey test runner.
|
||||||
# Verify Chrome has the same PID before and after the test.
|
# 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.
|
# Run the test.
|
||||||
output = ''
|
output = ''
|
||||||
duration_ms = 0
|
duration_ms = 0
|
||||||
if before_pids:
|
if before_pids:
|
||||||
output = '\n'.join(self.adb.RunMonkey(**self.options))
|
output = '\n'.join(self._LaunchMonkeyTest())
|
||||||
duration_ms = int(time.time()) * 1000 - start_ms
|
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
|
crashed = (not before_pids or not after_pids
|
||||||
or after_pids[0] != before_pids[0])
|
or after_pids[0] != before_pids[0])
|
||||||
@@ -55,13 +55,50 @@ class MonkeyTest(python_test_base.PythonTestBase):
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def _LaunchMonkeyTest(self):
|
||||||
|
"""Runs monkey test for a given package.
|
||||||
|
|
||||||
|
Looks at the following parameters in the options object provided
|
||||||
|
in class initializer:
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
category = self.options.category or []
|
||||||
|
seed = self.options.seed or random.randint(1, 100)
|
||||||
|
throttle = self.options.throttle or 100
|
||||||
|
event_count = self.options.event_count or 10000
|
||||||
|
verbosity = self.options.verbosity or 1
|
||||||
|
extra_args = self.options.extra_args or ''
|
||||||
|
|
||||||
|
timeout_ms = event_count * throttle * 1.5
|
||||||
|
|
||||||
|
cmd = ['monkey',
|
||||||
|
'-p %s' % self.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 self.adb.RunShellCommand(' '.join(cmd), timeout_time=timeout_ms)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def DispatchPythonTests(options):
|
def DispatchPythonTests(options):
|
||||||
"""Dispatches the Monkey tests, sharding it if there multiple devices."""
|
"""Dispatches the Monkey tests, sharding it if there multiple devices."""
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
build_type = options.pop('build_type')
|
|
||||||
available_tests = [MonkeyTest('testMonkey', options)]
|
available_tests = [MonkeyTest('testMonkey', options)]
|
||||||
attached_devices = android_commands.GetAttachedDevices()
|
attached_devices = android_commands.GetAttachedDevices()
|
||||||
if not attached_devices:
|
if not attached_devices:
|
||||||
@@ -73,16 +110,14 @@ def DispatchPythonTests(options):
|
|||||||
sharder = python_test_sharder.PythonTestSharder(
|
sharder = python_test_sharder.PythonTestSharder(
|
||||||
attached_devices, 1, available_tests)
|
attached_devices, 1, available_tests)
|
||||||
result = sharder.RunShardedTests()
|
result = sharder.RunShardedTests()
|
||||||
result.LogFull('Monkey', 'Monkey', build_type)
|
result.LogFull('Monkey', 'Monkey', options.build_type)
|
||||||
result.PrintAnnotation()
|
result.PrintAnnotation()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
desc = 'Run the Monkey tests on 1 or more devices.'
|
desc = 'Run the Monkey tests on 1 or more devices.'
|
||||||
parser = optparse.OptionParser(description=desc)
|
parser = optparse.OptionParser(description=desc)
|
||||||
test_options_parser.AddBuildTypeOption(parser)
|
test_options_parser.AddBuildTypeOption(parser)
|
||||||
parser.add_option('--package-name',
|
parser.add_option('--package-name', help='Allowed package.')
|
||||||
help='Allowed package.')
|
|
||||||
parser.add_option('--activity-name',
|
parser.add_option('--activity-name',
|
||||||
default='com.google.android.apps.chrome.Main',
|
default='com.google.android.apps.chrome.Main',
|
||||||
help='Name of the activity to start [default: %default].')
|
help='Name of the activity to start [default: %default].')
|
||||||
@@ -91,16 +126,16 @@ def main():
|
|||||||
parser.add_option('--throttle', default=100, type='int',
|
parser.add_option('--throttle', default=100, type='int',
|
||||||
help='Delay between events (ms) [default: %default]. ')
|
help='Delay between events (ms) [default: %default]. ')
|
||||||
parser.add_option('--seed', type='int',
|
parser.add_option('--seed', type='int',
|
||||||
help='Seed value for pseduo-random generator. Same seed'
|
help=('Seed value for pseduo-random generator. Same seed '
|
||||||
' value generates the same sequence of events. Seed is'
|
'value generates the same sequence of events. Seed '
|
||||||
' randomized by default.')
|
'is randomized by default.'))
|
||||||
parser.add_option('--event-count', default=10000, type='int',
|
parser.add_option('--event-count', default=10000, type='int',
|
||||||
help='Number of events to generate [default: %default].')
|
help='Number of events to generate [default: %default].')
|
||||||
parser.add_option('--verbosity', default=1, type='int',
|
parser.add_option('--verbosity', default=1, type='int',
|
||||||
help='Verbosity level [0-3] [default: %default].')
|
help='Verbosity level [0-3] [default: %default].')
|
||||||
parser.add_option('--extra-args', default='',
|
parser.add_option('--extra-args', default='',
|
||||||
help='String of other args to pass to the command verbatim'
|
help=('String of other args to pass to the command verbatim'
|
||||||
' [default: "%default"].')
|
' [default: "%default"].'))
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if args:
|
if args:
|
||||||
@@ -112,7 +147,7 @@ def main():
|
|||||||
if options.category:
|
if options.category:
|
||||||
options.category = options.category.split(',')
|
options.category = options.category.split(',')
|
||||||
|
|
||||||
DispatchPythonTests(vars(options))
|
DispatchPythonTests(options)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user