Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import itertools | 5 import itertools |
| 6 import os | 6 import os |
| 7 import posixpath | 7 import posixpath |
| 8 | 8 |
| 9 from devil.android import device_errors | 9 from devil.android import device_errors |
| 10 from devil.android import device_temp_file | 10 from devil.android import device_temp_file |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 for f in files: | 45 for f in files: |
| 46 device_file = posixpath.join(device_dir, f) | 46 device_file = posixpath.join(device_dir, f) |
| 47 host_file = os.path.join(host_dir, *f.split(posixpath.sep)) | 47 host_file = os.path.join(host_dir, *f.split(posixpath.sep)) |
| 48 host_file_base, ext = os.path.splitext(host_file) | 48 host_file_base, ext = os.path.splitext(host_file) |
| 49 for i in itertools.count(): | 49 for i in itertools.count(): |
| 50 host_file = '%s_%d%s' % (host_file_base, i, ext) | 50 host_file = '%s_%d%s' % (host_file_base, i, ext) |
| 51 if not os.path.exists(host_file): | 51 if not os.path.exists(host_file): |
| 52 break | 52 break |
| 53 device.PullFile(device_file, host_file) | 53 device.PullFile(device_file, host_file) |
| 54 | 54 |
| 55 | |
| 56 def _ExtractTestsFromFilter(gtest_filter): | |
| 57 """Returns the list of tests specified by the given filter. | |
| 58 | |
| 59 Returns: | |
| 60 None if the device should be queried for the test list instead. | |
| 61 """ | |
| 62 # Empty means all tests, - means exclude filter. | |
| 63 if not gtest_filter or '-' in gtest_filter: | |
| 64 return None | |
| 65 | |
| 66 patterns = gtest_filter.split(':') | |
| 67 # For a single pattern, allow it even if it has a wildcard so long as the | |
| 68 # wildcard comes at the end and there is at least one . to prove the scope is | |
| 69 # not too large. | |
| 70 # This heuristic is not necessarily faster, but normally is. | |
| 71 if len(patterns) == 1 and patterns[0].endswith('*'): | |
| 72 no_suffix = patterns[0].rstrip('*') | |
| 73 if '*' not in no_suffix and '.' in no_suffix: | |
| 74 return patterns | |
| 75 | |
| 76 if '*' in gtest_filter: | |
| 77 return None | |
| 78 return patterns | |
| 79 | |
| 80 | |
| 55 class _ApkDelegate(object): | 81 class _ApkDelegate(object): |
| 56 def __init__(self, test_instance): | 82 def __init__(self, test_instance): |
| 57 self._activity = test_instance.activity | 83 self._activity = test_instance.activity |
| 58 self._apk = test_instance.apk | 84 self._apk = test_instance.apk |
| 59 self._package = test_instance.package | 85 self._package = test_instance.package |
| 60 self._runner = test_instance.runner | 86 self._runner = test_instance.runner |
| 61 self._permissions = test_instance.permissions | 87 self._permissions = test_instance.permissions |
| 62 | 88 |
| 63 self._component = '%s/%s' % (self._package, self._runner) | 89 self._component = '%s/%s' % (self._package, self._runner) |
| 64 self._extras = test_instance.extras | 90 self._extras = test_instance.extras |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 #override | 248 #override |
| 223 def _GetTests(self): | 249 def _GetTests(self): |
| 224 @local_device_test_run.handle_shard_failures | 250 @local_device_test_run.handle_shard_failures |
| 225 def list_tests(dev): | 251 def list_tests(dev): |
| 226 tests = self._delegate.Run( | 252 tests = self._delegate.Run( |
| 227 None, dev, flags='--gtest_list_tests', timeout=10) | 253 None, dev, flags='--gtest_list_tests', timeout=10) |
| 228 tests = gtest_test_instance.ParseGTestListTests(tests) | 254 tests = gtest_test_instance.ParseGTestListTests(tests) |
| 229 tests = self._test_instance.FilterTests(tests) | 255 tests = self._test_instance.FilterTests(tests) |
| 230 return tests | 256 return tests |
| 231 | 257 |
| 232 test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None) | 258 # When the list of tests to run is given via command-line, skip querying the |
|
jbudorick
2015/10/13 17:17:48
As written, this is structured in a way that impli
agrieve
2015/10/13 20:13:27
Done (and updated comments to be a bit more specia
| |
| 233 tests = list(sorted(set().union(*[set(tl) for tl in test_lists if tl]))) | 259 # device (which takes ~3 seconds). |
| 260 gtest_filter = self._test_instance.gtest_filter | |
| 261 tests = _ExtractTestsFromFilter(gtest_filter) | |
| 262 | |
| 263 # Even when there's only one device, it still makes sense to retrieve the | |
| 264 # test list so that tests can be split up and run in batches rather than all | |
| 265 # at once (since test output is not streamed). | |
| 266 if not tests: | |
| 267 # Query all devices in case one fails. | |
| 268 test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None) | |
| 269 tests = list(sorted(set().union(*[set(tl) for tl in test_lists if tl]))) | |
| 234 return tests | 270 return tests |
| 235 | 271 |
| 236 #override | 272 #override |
| 237 def _RunTest(self, device, test): | 273 def _RunTest(self, device, test): |
| 238 # Run the test. | 274 # Run the test. |
| 239 timeout = (self._test_instance.shard_timeout | 275 timeout = (self._test_instance.shard_timeout |
| 240 * self.GetTool(device).GetTimeoutScale()) | 276 * self.GetTool(device).GetTimeoutScale()) |
| 241 output = self._delegate.Run( | 277 output = self._delegate.Run( |
| 242 test, device, timeout=timeout, retries=0) | 278 test, device, timeout=timeout, retries=0) |
| 243 for s in self._servers[str(device)]: | 279 for s in self._servers[str(device)]: |
| 244 s.Reset() | 280 s.Reset() |
| 245 if self._test_instance.app_files: | 281 if self._test_instance.app_files: |
| 246 self._delegate.PullAppFiles(device, self._test_instance.app_files, | 282 self._delegate.PullAppFiles(device, self._test_instance.app_files, |
| 247 self._test_instance.app_file_dir) | 283 self._test_instance.app_file_dir) |
| 248 self._delegate.Clear(device) | 284 self._delegate.Clear(device) |
| 249 | 285 |
| 250 # Parse the output. | 286 # Parse the output. |
| 251 # TODO(jbudorick): Transition test scripts away from parsing stdout. | 287 # TODO(jbudorick): Transition test scripts away from parsing stdout. |
| 252 results = self._test_instance.ParseGTestOutput(output) | 288 results = self._test_instance.ParseGTestOutput(output) |
| 253 return results | 289 return results |
| 254 | 290 |
| 255 #override | 291 #override |
| 256 def TearDown(self): | 292 def TearDown(self): |
| 257 @local_device_test_run.handle_shard_failures | 293 @local_device_test_run.handle_shard_failures |
| 258 def individual_device_tear_down(dev): | 294 def individual_device_tear_down(dev): |
| 259 for s in self._servers.get(str(dev), []): | 295 for s in self._servers.get(str(dev), []): |
| 260 s.TearDown() | 296 s.TearDown() |
| 261 | 297 |
| 262 self._env.parallel_devices.pMap(individual_device_tear_down) | 298 self._env.parallel_devices.pMap(individual_device_tear_down) |
| OLD | NEW |