Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import logging | |
| 6 | |
| 7 from devil.android import device_errors | |
| 8 from devil.android.sdk import intent | |
| 9 from pylib import constants | |
| 10 from pylib.base import base_test_result | |
| 11 from pylib.local.device import local_device_test_run | |
| 12 | |
| 13 | |
| 14 _CHROME_PACKAGE = constants.PACKAGE_INFO['chrome'].package | |
| 15 | |
| 16 class LocalDeviceMonkeyTestRun(local_device_test_run.LocalDeviceTestRun): | |
| 17 def __init__(self, env, test_instance): | |
| 18 super(LocalDeviceMonkeyTestRun, self).__init__(env, test_instance) | |
| 19 | |
| 20 def TestPackage(self): | |
| 21 return 'monkey' | |
| 22 | |
| 23 #override | |
| 24 def SetUp(self): | |
| 25 pass | |
| 26 | |
| 27 #override | |
| 28 def _RunTest(self, device, test): | |
| 29 device.ClearApplicationState(self._test_instance.package) | |
| 30 | |
| 31 # Chrome crashes are not always caught by Monkey test runner. | |
| 32 # Launch Chrome and verify Chrome has the same PID before and after | |
| 33 # the test. | |
| 34 device.StartActivity( | |
| 35 intent.Intent(package=self._test_instance.package, | |
| 36 activity=self._test_instance.activity, | |
| 37 action='android.intent.action.MAIN'), | |
| 38 blocking=True, force_stop=True) | |
| 39 before_pids = device.GetPids(self._test_instance.package) | |
| 40 | |
| 41 output = '' | |
| 42 if before_pids: | |
| 43 if len(before_pids.get(self._test_instance.package, [])) > 1: | |
| 44 raise Exception( | |
| 45 'At most one instance of process %s expected but found pids: ' | |
| 46 '%s' % (self._test_instance.package, before_pids)) | |
| 47 output = '\n'.join(self._LaunchMonkeyTest(device)) | |
| 48 after_pids = device.GetPids(self._test_instance.package) | |
| 49 | |
| 50 crashed = True | |
| 51 if not self._test_instance.package in before_pids: | |
| 52 logging.error('Failed to start the process.') | |
| 53 elif not self._test_instance.package in after_pids: | |
| 54 logging.error('Process %s has died.', | |
| 55 before_pids[self._test_instance.package]) | |
| 56 elif (before_pids[self._test_instance.package] != | |
| 57 after_pids[self._test_instance.package]): | |
| 58 logging.error('Detected process restart %s -> %s', | |
| 59 before_pids[self._test_instance.package], | |
| 60 after_pids[self._test_instance.package]) | |
| 61 else: | |
| 62 crashed = False | |
| 63 | |
| 64 success_pattern = 'Events injected: %d' % self._test_instance.event_count | |
| 65 if success_pattern in output and not crashed: | |
| 66 result = base_test_result.BaseTestResult( | |
| 67 test, base_test_result.ResultType.PASS, log=output) | |
| 68 else: | |
| 69 result = base_test_result.BaseTestResult( | |
| 70 test, base_test_result.ResultType.FAIL, log=output) | |
| 71 if 'chrome' in self._test_instance.package: | |
| 72 logging.warning('Starting MinidumpUploadService...') | |
| 73 # TODO(jbudorick): Update this after upstreaming. | |
|
jbudorick
2016/11/16 00:14:02
Well, this is awkward.
mikecase (-- gone --)
2016/11/16 22:48:57
lol
| |
| 74 minidump_intent = intent.Intent( | |
| 75 action='%s.crash.ACTION_FIND_ALL' % _CHROME_PACKAGE, | |
| 76 package=self._test_instance.package, | |
| 77 activity='%s.crash.MinidumpUploadService' % _CHROME_PACKAGE) | |
| 78 try: | |
| 79 device.RunShellCommand( | |
| 80 ['am', 'startservice'] + minidump_intent.am_args, | |
| 81 as_root=True, check_return=True) | |
| 82 except device_errors.CommandFailedError: | |
| 83 logging.exception('Failed to start MinidumpUploadService') | |
| 84 | |
| 85 return result | |
| 86 | |
| 87 #override | |
| 88 def TearDown(self): | |
| 89 pass | |
| 90 | |
| 91 #override | |
| 92 def _CreateShards(self, tests): | |
| 93 return tests | |
| 94 | |
| 95 #override | |
| 96 def _ShouldShard(self): | |
| 97 # TODO(mikecase): Run Monkey test concurrently on each attached device. | |
| 98 return False | |
| 99 | |
| 100 #override | |
| 101 def _GetTests(self): | |
| 102 return ['MonkeyTest'] | |
| 103 | |
| 104 def _LaunchMonkeyTest(self, device): | |
| 105 try: | |
| 106 cmd = ['monkey', | |
| 107 '-p', self._test_instance.package, | |
| 108 '--throttle', str(self._test_instance.throttle), | |
| 109 '-s', str(self._test_instance.seed), | |
| 110 '--monitor-native-crashes', | |
| 111 '--kill-process-after-error'] | |
| 112 for category in self._test_instance.categories: | |
| 113 cmd.extend(['-c', category]) | |
| 114 for _ in range(self._test_instance.verbose_count): | |
| 115 cmd.append('-v') | |
| 116 cmd.append(str(self._test_instance.event_count)) | |
| 117 return device.RunShellCommand( | |
| 118 cmd, timeout=self._test_instance.timeout) | |
|
jbudorick
2016/11/16 00:14:03
This should be using check_return=True, though I'm
mikecase (-- gone --)
2016/11/16 22:48:57
ack
| |
| 119 finally: | |
| 120 try: | |
| 121 # Kill the monkey test process on the device. If you manually | |
| 122 # interupt the test run, this will prevent the monkey test from | |
| 123 # continuing to run. | |
| 124 device.KillAll('com.android.commands.monkey') | |
| 125 except device_errors.CommandFailedError: | |
| 126 pass | |
| OLD | NEW |