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

Side by Side Diff: build/android/pylib/local/device/local_device_gtest_run.py

Issue 1393223002: Android gtest runner: Only query device for test list when necessary (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gtest-faster-7
Patch Set: Created 5 years, 2 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/gtest/gtest_test_instance.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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):
jbudorick 2015/10/08 15:01:46 It's hard for me to describe why, but this whole m
agrieve 2015/10/08 15:59:47 Yeah, I had at first just cached the test list lik
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
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 # Result should be the same for all devices, so just use the first one. 258 # When there's only one device, it still makes sense to retrieve the test
233 return list_tests(self._env.devices[0]) 259 # list since test output is not retrieve until after the test completes.
jbudorick 2015/10/08 15:01:46 Why do you say that it still makes sense to retrie
agrieve 2015/10/08 15:59:46 Clarified (but not 100% sure it's even the case, s
260 gtest_filter = self._test_instance.gtest_filter
261 # But when running only a single test, skip querying the device (which
262 # takes ~3 seconds).
263 tests = _ExtractTestsFromFilter(gtest_filter)
264
265 if not tests:
266 # Result should be the same for all devices, so just use the first one.
267 tests = list_tests(self._env.devices[0])
268 return tests
234 269
235 #override 270 #override
236 def _RunTest(self, device, test): 271 def _RunTest(self, device, test):
237 # Run the test. 272 # Run the test.
238 timeout = (self._test_instance.shard_timeout 273 timeout = (self._test_instance.shard_timeout
239 * self.GetTool(device).GetTimeoutScale()) 274 * self.GetTool(device).GetTimeoutScale())
240 output = self._delegate.Run( 275 output = self._delegate.Run(
241 test, device, timeout=timeout, retries=0) 276 test, device, timeout=timeout, retries=0)
242 for s in self._servers[str(device)]: 277 for s in self._servers[str(device)]:
243 s.Reset() 278 s.Reset()
244 if self._test_instance.app_files: 279 if self._test_instance.app_files:
245 self._delegate.PullAppFiles(device, self._test_instance.app_files, 280 self._delegate.PullAppFiles(device, self._test_instance.app_files,
246 self._test_instance.app_file_dir) 281 self._test_instance.app_file_dir)
247 self._delegate.Clear(device) 282 self._delegate.Clear(device)
248 283
249 # Parse the output. 284 # Parse the output.
250 # TODO(jbudorick): Transition test scripts away from parsing stdout. 285 # TODO(jbudorick): Transition test scripts away from parsing stdout.
251 results = self._test_instance.ParseGTestOutput(output) 286 results = self._test_instance.ParseGTestOutput(output)
252 return results 287 return results
253 288
254 #override 289 #override
255 def TearDown(self): 290 def TearDown(self):
256 @local_device_test_run.handle_shard_failures 291 @local_device_test_run.handle_shard_failures
257 def individual_device_tear_down(dev): 292 def individual_device_tear_down(dev):
258 for s in self._servers.get(str(dev), []): 293 for s in self._servers.get(str(dev), []):
259 s.TearDown() 294 s.TearDown()
260 295
261 self._env.parallel_devices.pMap(individual_device_tear_down) 296 self._env.parallel_devices.pMap(individual_device_tear_down)
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/gtest_test_instance.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698