| 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 imp | 5 import imp |
| 6 import itertools | 6 import itertools |
| 7 import os | 7 import os |
| 8 import posixpath | 8 import posixpath |
| 9 | 9 |
| 10 from devil.android import device_errors | 10 from devil.android import device_errors |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 device_file = posixpath.join(device_dir, f) | 62 device_file = posixpath.join(device_dir, f) |
| 63 host_file = os.path.join(host_dir, *f.split(posixpath.sep)) | 63 host_file = os.path.join(host_dir, *f.split(posixpath.sep)) |
| 64 host_file_base, ext = os.path.splitext(host_file) | 64 host_file_base, ext = os.path.splitext(host_file) |
| 65 for i in itertools.count(): | 65 for i in itertools.count(): |
| 66 host_file = '%s_%d%s' % (host_file_base, i, ext) | 66 host_file = '%s_%d%s' % (host_file_base, i, ext) |
| 67 if not os.path.exists(host_file): | 67 if not os.path.exists(host_file): |
| 68 break | 68 break |
| 69 device.PullFile(device_file, host_file) | 69 device.PullFile(device_file, host_file) |
| 70 | 70 |
| 71 | 71 |
| 72 def _ExtractTestsFromFilter(gtest_filter): |
| 73 """Returns the list of tests specified by the given filter. |
| 74 |
| 75 Returns: |
| 76 None if the device should be queried for the test list instead. |
| 77 """ |
| 78 # Empty means all tests, - means exclude filter. |
| 79 if not gtest_filter or '-' in gtest_filter: |
| 80 return None |
| 81 |
| 82 patterns = gtest_filter.split(':') |
| 83 # For a single pattern, allow it even if it has a wildcard so long as the |
| 84 # wildcard comes at the end and there is at least one . to prove the scope is |
| 85 # not too large. |
| 86 # This heuristic is not necessarily faster, but normally is. |
| 87 if len(patterns) == 1 and patterns[0].endswith('*'): |
| 88 no_suffix = patterns[0].rstrip('*') |
| 89 if '*' not in no_suffix and '.' in no_suffix: |
| 90 return patterns |
| 91 |
| 92 if '*' in gtest_filter: |
| 93 return None |
| 94 return patterns |
| 95 |
| 96 |
| 72 class _ApkDelegate(object): | 97 class _ApkDelegate(object): |
| 73 def __init__(self, test_instance): | 98 def __init__(self, test_instance): |
| 74 self._activity = test_instance.activity | 99 self._activity = test_instance.activity |
| 75 self._apk_helper = test_instance.apk_helper | 100 self._apk_helper = test_instance.apk_helper |
| 76 self._package = test_instance.package | 101 self._package = test_instance.package |
| 77 self._runner = test_instance.runner | 102 self._runner = test_instance.runner |
| 78 self._permissions = test_instance.permissions | 103 self._permissions = test_instance.permissions |
| 79 self._suite = test_instance.suite | 104 self._suite = test_instance.suite |
| 80 self._component = '%s/%s' % (self._package, self._runner) | 105 self._component = '%s/%s' % (self._package, self._runner) |
| 81 self._extras = test_instance.extras | 106 self._extras = test_instance.extras |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 device_count = len(self._env.devices) | 298 device_count = len(self._env.devices) |
| 274 shards = [] | 299 shards = [] |
| 275 for i in xrange(0, device_count): | 300 for i in xrange(0, device_count): |
| 276 unbounded_shard = tests[i::device_count] | 301 unbounded_shard = tests[i::device_count] |
| 277 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] | 302 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] |
| 278 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] | 303 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] |
| 279 return shards | 304 return shards |
| 280 | 305 |
| 281 #override | 306 #override |
| 282 def _GetTests(self): | 307 def _GetTests(self): |
| 308 if self._test_instance.extract_test_list_from_filter: |
| 309 # When the exact list of tests to run is given via command-line (e.g. when |
| 310 # locally iterating on a specific test), skip querying the device (which |
| 311 # takes ~3 seconds). |
| 312 tests = _ExtractTestsFromFilter(self._test_instance.gtest_filter) |
| 313 if tests: |
| 314 return tests |
| 315 |
| 283 # Even when there's only one device, it still makes sense to retrieve the | 316 # Even when there's only one device, it still makes sense to retrieve the |
| 284 # test list so that tests can be split up and run in batches rather than all | 317 # test list so that tests can be split up and run in batches rather than all |
| 285 # at once (since test output is not streamed). | 318 # at once (since test output is not streamed). |
| 286 @local_device_test_run.handle_shard_failures_with( | 319 @local_device_test_run.handle_shard_failures_with( |
| 287 on_failure=self._env.BlacklistDevice) | 320 on_failure=self._env.BlacklistDevice) |
| 288 def list_tests(dev): | 321 def list_tests(dev): |
| 289 tests = self._delegate.Run( | 322 tests = self._delegate.Run( |
| 290 None, dev, flags='--gtest_list_tests', timeout=20) | 323 None, dev, flags='--gtest_list_tests', timeout=20) |
| 291 tests = gtest_test_instance.ParseGTestListTests(tests) | 324 tests = gtest_test_instance.ParseGTestListTests(tests) |
| 292 tests = self._test_instance.FilterTests(tests) | 325 tests = self._test_instance.FilterTests(tests) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 def TearDown(self): | 358 def TearDown(self): |
| 326 @local_device_test_run.handle_shard_failures | 359 @local_device_test_run.handle_shard_failures |
| 327 def individual_device_tear_down(dev): | 360 def individual_device_tear_down(dev): |
| 328 for s in self._servers.get(str(dev), []): | 361 for s in self._servers.get(str(dev), []): |
| 329 s.TearDown() | 362 s.TearDown() |
| 330 | 363 |
| 331 tool = self.GetTool(dev) | 364 tool = self.GetTool(dev) |
| 332 tool.CleanUpEnvironment() | 365 tool.CleanUpEnvironment() |
| 333 | 366 |
| 334 self._env.parallel_devices.pMap(individual_device_tear_down) | 367 self._env.parallel_devices.pMap(individual_device_tear_down) |
| OLD | NEW |