diff options
author | agrieve <agrieve@chromium.org> | 2015-10-13 16:23:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-13 23:24:31 +0000 |
commit | 065d7462c301d58b12415c7591e5647ab766fe56 (patch) | |
tree | 5e46a3eb278770a5e40e17e99e9a56652d051aea /build | |
parent | 3ade2f22f2a1a3118c5bef2daa9df79f10bab530 (diff) | |
download | chromium_src-065d7462c301d58b12415c7591e5647ab766fe56.zip chromium_src-065d7462c301d58b12415c7591e5647ab766fe56.tar.gz chromium_src-065d7462c301d58b12415c7591e5647ab766fe56.tar.bz2 |
Android gtest runner: Only query device for test list when necessary
When --gtest_filter is used and contains a list of tests without
wildcards, it is not necessary to query the device for the list of
tests.
This speeds up local development where it's comment to run just a single
test at a time (saves 3 seconds).
BUG=540857
Review URL: https://codereview.chromium.org/1393223002
Cr-Commit-Position: refs/heads/master@{#353901}
Diffstat (limited to 'build')
-rw-r--r-- | build/android/pylib/gtest/gtest_test_instance.py | 4 | ||||
-rw-r--r-- | build/android/pylib/local/device/local_device_gtest_run.py | 42 |
2 files changed, 44 insertions, 2 deletions
diff --git a/build/android/pylib/gtest/gtest_test_instance.py b/build/android/pylib/gtest/gtest_test_instance.py index c32adb2..e61b89c 100644 --- a/build/android/pylib/gtest/gtest_test_instance.py +++ b/build/android/pylib/gtest/gtest_test_instance.py @@ -197,6 +197,10 @@ class GtestTestInstance(test_instance.TestInstance): self._app_data_files = None self._app_data_file_dir = None + @property + def gtest_filter(self): + return self._gtest_filter + #override def TestType(self): return 'gtest' diff --git a/build/android/pylib/local/device/local_device_gtest_run.py b/build/android/pylib/local/device/local_device_gtest_run.py index 85af2bc..81d85fd 100644 --- a/build/android/pylib/local/device/local_device_gtest_run.py +++ b/build/android/pylib/local/device/local_device_gtest_run.py @@ -52,6 +52,32 @@ def PullAppFilesImpl(device, package, files, directory): break device.PullFile(device_file, host_file) + +def _ExtractTestsFromFilter(gtest_filter): + """Returns the list of tests specified by the given filter. + + Returns: + None if the device should be queried for the test list instead. + """ + # Empty means all tests, - means exclude filter. + if not gtest_filter or '-' in gtest_filter: + return None + + patterns = gtest_filter.split(':') + # For a single pattern, allow it even if it has a wildcard so long as the + # wildcard comes at the end and there is at least one . to prove the scope is + # not too large. + # This heuristic is not necessarily faster, but normally is. + if len(patterns) == 1 and patterns[0].endswith('*'): + no_suffix = patterns[0].rstrip('*') + if '*' not in no_suffix and '.' in no_suffix: + return patterns + + if '*' in gtest_filter: + return None + return patterns + + class _ApkDelegate(object): def __init__(self, test_instance): self._activity = test_instance.activity @@ -221,6 +247,16 @@ class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): #override def _GetTests(self): + # When the exact list of tests to run is given via command-line (e.g. when + # locally iterating on a specific test), skip querying the device (which + # takes ~3 seconds). + tests = _ExtractTestsFromFilter(self._test_instance.gtest_filter) + if tests: + return tests + + # Even when there's only one device, it still makes sense to retrieve the + # test list so that tests can be split up and run in batches rather than all + # at once (since test output is not streamed). @local_device_test_run.handle_shard_failures_with( on_failure=self._env.BlacklistDevice) def list_tests(dev): @@ -230,9 +266,11 @@ class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): tests = self._test_instance.FilterTests(tests) return tests + # Query all devices in case one fails. test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None) - tests = list(sorted(set().union(*[set(tl) for tl in test_lists if tl]))) - return tests + # TODO(agrieve): Make this fail rather than return an empty list when + # all devices fail. + return list(sorted(set().union(*[set(tl) for tl in test_lists if tl]))) #override def _RunTest(self, device, test): |