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