OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Class for running instrumentation tests on a single device.""" | 5 """Class for running instrumentation tests on a single device.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 import time | 10 import time |
(...skipping 26 matching lines...) Expand all Loading... |
37 test_files += [ | 37 test_files += [ |
38 'net/data/ssl/certificates/', | 38 'net/data/ssl/certificates/', |
39 ] | 39 ] |
40 return test_files | 40 return test_files |
41 | 41 |
42 | 42 |
43 class TestRunner(base_test_runner.BaseTestRunner): | 43 class TestRunner(base_test_runner.BaseTestRunner): |
44 """Responsible for running a series of tests connected to a single device.""" | 44 """Responsible for running a series of tests connected to a single device.""" |
45 | 45 |
46 _DEVICE_DATA_DIR = 'chrome/test/data' | 46 _DEVICE_DATA_DIR = 'chrome/test/data' |
| 47 _DEVICE_COVERAGE_DIR = 'chrome/test/coverage' |
47 _HOSTMACHINE_PERF_OUTPUT_FILE = '/tmp/chrome-profile' | 48 _HOSTMACHINE_PERF_OUTPUT_FILE = '/tmp/chrome-profile' |
48 _DEVICE_PERF_OUTPUT_SEARCH_PREFIX = (constants.DEVICE_PERF_OUTPUT_DIR + | 49 _DEVICE_PERF_OUTPUT_SEARCH_PREFIX = (constants.DEVICE_PERF_OUTPUT_DIR + |
49 '/chrome-profile*') | 50 '/chrome-profile*') |
50 _DEVICE_HAS_TEST_FILES = {} | 51 _DEVICE_HAS_TEST_FILES = {} |
51 | 52 |
52 def __init__(self, test_options, device, shard_index, test_pkg, | 53 def __init__(self, test_options, device, shard_index, test_pkg, |
53 ports_to_forward): | 54 ports_to_forward): |
54 """Create a new TestRunner. | 55 """Create a new TestRunner. |
55 | 56 |
56 Args: | 57 Args: |
57 test_options: An InstrumentationOptions object. | 58 test_options: An InstrumentationOptions object. |
58 device: Attached android device. | 59 device: Attached android device. |
59 shard_index: Shard index. | 60 shard_index: Shard index. |
60 test_pkg: A TestPackage object. | 61 test_pkg: A TestPackage object. |
61 ports_to_forward: A list of port numbers for which to set up forwarders. | 62 ports_to_forward: A list of port numbers for which to set up forwarders. |
62 Can be optionally requested by a test case. | 63 Can be optionally requested by a test case. |
63 """ | 64 """ |
64 super(TestRunner, self).__init__(device, test_options.tool, | 65 super(TestRunner, self).__init__(device, test_options.tool, |
65 test_options.push_deps, | 66 test_options.push_deps, |
66 test_options.cleanup_test_files) | 67 test_options.cleanup_test_files) |
67 self._lighttp_port = constants.LIGHTTPD_RANDOM_PORT_FIRST + shard_index | 68 self._lighttp_port = constants.LIGHTTPD_RANDOM_PORT_FIRST + shard_index |
68 | 69 |
69 self.options = test_options | 70 self.options = test_options |
70 self.test_pkg = test_pkg | 71 self.test_pkg = test_pkg |
71 self.ports_to_forward = ports_to_forward | 72 self.ports_to_forward = ports_to_forward |
| 73 self.coverage_dir = test_options.coverage_dir |
72 | 74 |
73 #override | 75 #override |
74 def InstallTestPackage(self): | 76 def InstallTestPackage(self): |
75 self.test_pkg.Install(self.adb) | 77 self.test_pkg.Install(self.adb) |
76 | 78 |
77 #override | 79 #override |
78 def PushDataDeps(self): | 80 def PushDataDeps(self): |
79 # TODO(frankf): Implement a general approach for copying/installing | 81 # TODO(frankf): Implement a general approach for copying/installing |
80 # once across test runners. | 82 # once across test runners. |
81 if TestRunner._DEVICE_HAS_TEST_FILES.get(self.device, False): | 83 if TestRunner._DEVICE_HAS_TEST_FILES.get(self.device, False): |
82 logging.warning('Already copied test files to device %s, skipping.', | 84 logging.warning('Already copied test files to device %s, skipping.', |
83 self.device) | 85 self.device) |
84 return | 86 return |
85 | 87 |
86 test_data = _GetDataFilesForTestSuite(self.test_pkg.GetApkName()) | 88 test_data = _GetDataFilesForTestSuite(self.test_pkg.GetApkName()) |
87 if test_data: | 89 if test_data: |
88 # Make sure SD card is ready. | 90 # Make sure SD card is ready. |
89 self.adb.WaitForSdCardReady(20) | 91 self.adb.WaitForSdCardReady(20) |
90 for p in test_data: | 92 for p in test_data: |
91 self.adb.PushIfNeeded( | 93 self.adb.PushIfNeeded( |
92 os.path.join(constants.DIR_SOURCE_ROOT, p), | 94 os.path.join(constants.DIR_SOURCE_ROOT, p), |
93 os.path.join(self.adb.GetExternalStorage(), p)) | 95 os.path.join(self.adb.GetExternalStorage(), p)) |
94 | 96 |
95 # TODO(frankf): Specify test data in this file as opposed to passing | 97 # TODO(frankf): Specify test data in this file as opposed to passing |
96 # as command-line. | 98 # as command-line. |
97 for dest_host_pair in self.options.test_data: | 99 for dest_host_pair in self.options.test_data: |
98 dst_src = dest_host_pair.split(':',1) | 100 dst_src = dest_host_pair.split(':',1) |
99 dst_layer = dst_src[0] | 101 dst_layer = dst_src[0] |
100 host_src = dst_src[1] | 102 host_src = dst_src[1] |
101 host_test_files_path = constants.DIR_SOURCE_ROOT + '/' + host_src | 103 host_test_files_path = '%s/%s' % (constants.DIR_SOURCE_ROOT, host_src) |
102 if os.path.exists(host_test_files_path): | 104 if os.path.exists(host_test_files_path): |
103 self.adb.PushIfNeeded(host_test_files_path, | 105 self.adb.PushIfNeeded(host_test_files_path, '%s/%s/%s' % ( |
104 self.adb.GetExternalStorage() + '/' + | 106 self.adb.GetExternalStorage(), TestRunner._DEVICE_DATA_DIR, |
105 TestRunner._DEVICE_DATA_DIR + '/' + dst_layer) | 107 dst_layer)) |
106 self.tool.CopyFiles() | 108 self.tool.CopyFiles() |
107 TestRunner._DEVICE_HAS_TEST_FILES[self.device] = True | 109 TestRunner._DEVICE_HAS_TEST_FILES[self.device] = True |
108 | 110 |
109 def _GetInstrumentationArgs(self): | 111 def _GetInstrumentationArgs(self): |
110 ret = {} | 112 ret = {} |
111 if self.options.wait_for_debugger: | 113 if self.options.wait_for_debugger: |
112 ret['debug'] = 'true' | 114 ret['debug'] = 'true' |
| 115 if self.coverage_dir: |
| 116 ret['coverage'] = 'true' |
| 117 ret['coverageFile'] = self.coverage_device_file |
| 118 |
113 return ret | 119 return ret |
114 | 120 |
115 def _TakeScreenshot(self, test): | 121 def _TakeScreenshot(self, test): |
116 """Takes a screenshot from the device.""" | 122 """Takes a screenshot from the device.""" |
117 screenshot_name = os.path.join(constants.SCREENSHOTS_DIR, test + '.png') | 123 screenshot_name = os.path.join(constants.SCREENSHOTS_DIR, '%s.png' % test) |
118 logging.info('Taking screenshot named %s', screenshot_name) | 124 logging.info('Taking screenshot named %s', screenshot_name) |
119 self.adb.TakeScreenshot(screenshot_name) | 125 self.adb.TakeScreenshot(screenshot_name) |
120 | 126 |
121 def SetUp(self): | 127 def SetUp(self): |
122 """Sets up the test harness and device before all tests are run.""" | 128 """Sets up the test harness and device before all tests are run.""" |
123 super(TestRunner, self).SetUp() | 129 super(TestRunner, self).SetUp() |
124 if not self.adb.IsRootEnabled(): | 130 if not self.adb.IsRootEnabled(): |
125 logging.warning('Unable to enable java asserts for %s, non rooted device', | 131 logging.warning('Unable to enable java asserts for %s, non rooted device', |
126 self.device) | 132 self.device) |
127 else: | 133 else: |
(...skipping 21 matching lines...) Expand all Loading... |
149 Args: | 155 Args: |
150 test: The name of the test that will be run. | 156 test: The name of the test that will be run. |
151 """ | 157 """ |
152 self.SetupPerfMonitoringIfNeeded(test) | 158 self.SetupPerfMonitoringIfNeeded(test) |
153 self._SetupIndividualTestTimeoutScale(test) | 159 self._SetupIndividualTestTimeoutScale(test) |
154 self.tool.SetupEnvironment() | 160 self.tool.SetupEnvironment() |
155 | 161 |
156 # Make sure the forwarder is still running. | 162 # Make sure the forwarder is still running. |
157 self._RestartHttpServerForwarderIfNecessary() | 163 self._RestartHttpServerForwarderIfNecessary() |
158 | 164 |
| 165 if self.coverage_dir: |
| 166 coverage_basename = '%s.ec' % test |
| 167 self.coverage_device_file = '%s/%s/%s' % (self.adb.GetExternalStorage(), |
| 168 TestRunner._DEVICE_COVERAGE_DIR, |
| 169 coverage_basename) |
| 170 self.coverage_host_file = os.path.join( |
| 171 self.coverage_dir, coverage_basename) |
| 172 |
159 def _IsPerfTest(self, test): | 173 def _IsPerfTest(self, test): |
160 """Determines whether a test is a performance test. | 174 """Determines whether a test is a performance test. |
161 | 175 |
162 Args: | 176 Args: |
163 test: The name of the test to be checked. | 177 test: The name of the test to be checked. |
164 | 178 |
165 Returns: | 179 Returns: |
166 Whether the test is annotated as a performance test. | 180 Whether the test is annotated as a performance test. |
167 """ | 181 """ |
168 return _PERF_TEST_ANNOTATION in self.test_pkg.GetTestAnnotations(test) | 182 return _PERF_TEST_ANNOTATION in self.test_pkg.GetTestAnnotations(test) |
(...skipping 22 matching lines...) Expand all Loading... |
191 """ | 205 """ |
192 | 206 |
193 self.tool.CleanUpEnvironment() | 207 self.tool.CleanUpEnvironment() |
194 | 208 |
195 # The logic below relies on the test passing. | 209 # The logic below relies on the test passing. |
196 if not raw_result or raw_result.GetStatusCode(): | 210 if not raw_result or raw_result.GetStatusCode(): |
197 return | 211 return |
198 | 212 |
199 self.TearDownPerfMonitoring(test) | 213 self.TearDownPerfMonitoring(test) |
200 | 214 |
| 215 if self.coverage_dir: |
| 216 self.adb.Adb().Pull(self.coverage_device_file, self.coverage_host_file) |
| 217 self.adb.RunShellCommand('rm -f %s' % self.coverage_device_file) |
| 218 |
201 def TearDownPerfMonitoring(self, test): | 219 def TearDownPerfMonitoring(self, test): |
202 """Cleans up performance monitoring if the specified test required it. | 220 """Cleans up performance monitoring if the specified test required it. |
203 | 221 |
204 Args: | 222 Args: |
205 test: The name of the test that was just run. | 223 test: The name of the test that was just run. |
206 Raises: | 224 Raises: |
207 Exception: if there's anything wrong with the perf data. | 225 Exception: if there's anything wrong with the perf data. |
208 """ | 226 """ |
209 if not self._IsPerfTest(test): | 227 if not self._IsPerfTest(test): |
210 return | 228 return |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 duration_ms = 0 | 353 duration_ms = 0 |
336 message = str(e) | 354 message = str(e) |
337 if not message: | 355 if not message: |
338 message = 'No information.' | 356 message = 'No information.' |
339 results.AddResult(test_result.InstrumentationTestResult( | 357 results.AddResult(test_result.InstrumentationTestResult( |
340 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, | 358 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, |
341 log=message)) | 359 log=message)) |
342 raw_result = None | 360 raw_result = None |
343 self.TestTeardown(test, raw_result) | 361 self.TestTeardown(test, raw_result) |
344 return (results, None if results.DidRunPass() else test) | 362 return (results, None if results.DidRunPass() else test) |
OLD | NEW |