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

Side by Side Diff: build/android/pylib/monkey/test_runner.py

Issue 2101243005: Add a snapshot of flutter/engine/src/build to our sdk (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add README.dart Created 4 years, 5 months 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
« no previous file with comments | « build/android/pylib/monkey/test_options.py ('k') | build/android/pylib/perf/__init__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 """Runs a monkey test on a single device."""
6
7 import logging
8 import random
9
10 from pylib import constants
11 from pylib.base import base_test_result
12 from pylib.base import base_test_runner
13 from pylib.device import device_errors
14 from pylib.device import intent
15
16 _CHROME_PACKAGE = constants.PACKAGE_INFO['chrome'].package
17
18 class TestRunner(base_test_runner.BaseTestRunner):
19 """A TestRunner instance runs a monkey test on a single device."""
20
21 def __init__(self, test_options, device, _):
22 super(TestRunner, self).__init__(device, None)
23 self._options = test_options
24 self._package = constants.PACKAGE_INFO[self._options.package].package
25 self._activity = constants.PACKAGE_INFO[self._options.package].activity
26
27 def _LaunchMonkeyTest(self):
28 """Runs monkey test for a given package.
29
30 Returns:
31 Output from the monkey command on the device.
32 """
33
34 timeout_ms = self._options.event_count * self._options.throttle * 1.5
35
36 cmd = ['monkey',
37 '-p %s' % self._package,
38 ' '.join(['-c %s' % c for c in self._options.category]),
39 '--throttle %d' % self._options.throttle,
40 '-s %d' % (self._options.seed or random.randint(1, 100)),
41 '-v ' * self._options.verbose_count,
42 '--monitor-native-crashes',
43 '--kill-process-after-error',
44 self._options.extra_args,
45 '%d' % self._options.event_count]
46 return self.device.RunShellCommand(' '.join(cmd), timeout=timeout_ms)
47
48 def RunTest(self, test_name):
49 """Run a Monkey test on the device.
50
51 Args:
52 test_name: String to use for logging the test result.
53
54 Returns:
55 A tuple of (TestRunResults, retry).
56 """
57 self.device.StartActivity(
58 intent.Intent(package=self._package, activity=self._activity,
59 action='android.intent.action.MAIN'),
60 blocking=True, force_stop=True)
61
62 # Chrome crashes are not always caught by Monkey test runner.
63 # Verify Chrome has the same PID before and after the test.
64 before_pids = self.device.GetPids(self._package)
65
66 # Run the test.
67 output = ''
68 if before_pids:
69 output = '\n'.join(self._LaunchMonkeyTest())
70 after_pids = self.device.GetPids(self._package)
71
72 crashed = True
73 if not self._package in before_pids:
74 logging.error('Failed to start the process.')
75 elif not self._package in after_pids:
76 logging.error('Process %s has died.', before_pids[self._package])
77 elif before_pids[self._package] != after_pids[self._package]:
78 logging.error('Detected process restart %s -> %s',
79 before_pids[self._package], after_pids[self._package])
80 else:
81 crashed = False
82
83 results = base_test_result.TestRunResults()
84 success_pattern = 'Events injected: %d' % self._options.event_count
85 if success_pattern in output and not crashed:
86 result = base_test_result.BaseTestResult(
87 test_name, base_test_result.ResultType.PASS, log=output)
88 else:
89 result = base_test_result.BaseTestResult(
90 test_name, base_test_result.ResultType.FAIL, log=output)
91 if 'chrome' in self._options.package:
92 logging.warning('Starting MinidumpUploadService...')
93 # TODO(jbudorick): Update this after upstreaming.
94 minidump_intent = intent.Intent(
95 action='%s.crash.ACTION_FIND_ALL' % _CHROME_PACKAGE,
96 package=self._package,
97 activity='%s.crash.MinidumpUploadService' % _CHROME_PACKAGE)
98 try:
99 self.device.RunShellCommand(
100 ['am', 'startservice'] + minidump_intent.am_args,
101 as_root=True, check_return=True)
102 except device_errors.CommandFailedError:
103 logging.exception('Failed to start MinidumpUploadService')
104
105 results.AddResult(result)
106 return results, False
OLDNEW
« no previous file with comments | « build/android/pylib/monkey/test_options.py ('k') | build/android/pylib/perf/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698