| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Runs a monkey test on a single device.""" | 5 """Runs a monkey test on a single device.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import random | 8 import random |
| 9 | 9 |
| 10 from pylib import constants | 10 from pylib import constants |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 Returns: | 51 Returns: |
| 52 A tuple of (TestRunResults, retry). | 52 A tuple of (TestRunResults, retry). |
| 53 """ | 53 """ |
| 54 self.device.StartActivity( | 54 self.device.StartActivity( |
| 55 intent.Intent(package=self._package, activity=self._activity, | 55 intent.Intent(package=self._package, activity=self._activity, |
| 56 action='android.intent.action.MAIN'), | 56 action='android.intent.action.MAIN'), |
| 57 blocking=True, force_stop=True) | 57 blocking=True, force_stop=True) |
| 58 | 58 |
| 59 # Chrome crashes are not always caught by Monkey test runner. | 59 # Chrome crashes are not always caught by Monkey test runner. |
| 60 # Verify Chrome has the same PID before and after the test. | 60 # Verify Chrome has the same PID before and after the test. |
| 61 before_pids = self.device.old_interface.ExtractPid(self._package) | 61 before_pids = self.device.GetPids(self._package) |
| 62 | 62 |
| 63 # Run the test. | 63 # Run the test. |
| 64 output = '' | 64 output = '' |
| 65 if before_pids: | 65 if before_pids: |
| 66 output = '\n'.join(self._LaunchMonkeyTest()) | 66 output = '\n'.join(self._LaunchMonkeyTest()) |
| 67 after_pids = self.device.old_interface.ExtractPid(self._package) | 67 after_pids = self.device.GetPids(self._package) |
| 68 | 68 |
| 69 crashed = True | 69 crashed = True |
| 70 if not before_pids: | 70 if not self._package in before_pids: |
| 71 logging.error('Failed to start the process.') | 71 logging.error('Failed to start the process.') |
| 72 elif not after_pids: | 72 elif not self._package in after_pids: |
| 73 logging.error('Process %s has died.', before_pids[0]) | 73 logging.error('Process %s has died.', before_pids[self._package]) |
| 74 elif before_pids[0] != after_pids[0]: | 74 elif before_pids[self._package] != after_pids[self._package]: |
| 75 logging.error('Detected process restart %s -> %s', | 75 logging.error('Detected process restart %s -> %s', |
| 76 before_pids[0], after_pids[0]) | 76 before_pids[self._package], after_pids[self._package]) |
| 77 else: | 77 else: |
| 78 crashed = False | 78 crashed = False |
| 79 | 79 |
| 80 results = base_test_result.TestRunResults() | 80 results = base_test_result.TestRunResults() |
| 81 success_pattern = 'Events injected: %d' % self._options.event_count | 81 success_pattern = 'Events injected: %d' % self._options.event_count |
| 82 if success_pattern in output and not crashed: | 82 if success_pattern in output and not crashed: |
| 83 result = base_test_result.BaseTestResult( | 83 result = base_test_result.BaseTestResult( |
| 84 test_name, base_test_result.ResultType.PASS, log=output) | 84 test_name, base_test_result.ResultType.PASS, log=output) |
| 85 else: | 85 else: |
| 86 result = base_test_result.BaseTestResult( | 86 result = base_test_result.BaseTestResult( |
| 87 test_name, base_test_result.ResultType.FAIL, log=output) | 87 test_name, base_test_result.ResultType.FAIL, log=output) |
| 88 if 'chrome' in self._options.package: | 88 if 'chrome' in self._options.package: |
| 89 logging.warning('Starting MinidumpUploadService...') | 89 logging.warning('Starting MinidumpUploadService...') |
| 90 try: | 90 try: |
| 91 self.device.old_interface.StartCrashUploadService(self._package) | 91 self.device.old_interface.StartCrashUploadService(self._package) |
| 92 except AssertionError as e: | 92 except AssertionError as e: |
| 93 logging.error('Failed to start MinidumpUploadService: %s', e) | 93 logging.error('Failed to start MinidumpUploadService: %s', e) |
| 94 results.AddResult(result) | 94 results.AddResult(result) |
| 95 return results, False | 95 return results, False |
| OLD | NEW |