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

Side by Side Diff: build/android/pylib/gtest/setup.py

Issue 223733004: [Android] Push data deps before listing gtests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Craig's comments. Created 6 years, 8 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 | « no previous file | build/android/pylib/gtest/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """Generates test runner factory and tests for GTests.""" 5 """Generates test runner factory and tests for GTests."""
6 # pylint: disable=W0212 6 # pylint: disable=W0212
7 7
8 import fnmatch 8 import fnmatch
9 import glob 9 import glob
10 import logging 10 import logging
11 import os 11 import os
12 import shutil 12 import shutil
13 import sys 13 import sys
14 14
15 from pylib import android_commands
16 from pylib import cmd_helper 15 from pylib import cmd_helper
17 from pylib import constants 16 from pylib import constants
18 17
18 from pylib.base import base_test_result
19 from pylib.base import test_dispatcher
19 from pylib.gtest import test_package_apk 20 from pylib.gtest import test_package_apk
20 from pylib.gtest import test_package_exe 21 from pylib.gtest import test_package_exe
21 from pylib.gtest import test_runner 22 from pylib.gtest import test_runner
22 23
23 sys.path.insert(0, 24 sys.path.insert(0,
24 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 25 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib',
25 'common')) 26 'common'))
26 import unittest_util # pylint: disable=F0401 27 import unittest_util # pylint: disable=F0401
27 28
28 29
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return '*' 198 return '*'
198 199
199 filters = [x for x in [x.strip() for x in file(filter_file_path).readlines()] 200 filters = [x for x in [x.strip() for x in file(filter_file_path).readlines()]
200 if x and x[0] != '#'] 201 if x and x[0] != '#']
201 disabled_filter = '*-%s' % ':'.join(filters) 202 disabled_filter = '*-%s' % ':'.join(filters)
202 logging.info('Applying filter "%s" obtained from %s', 203 logging.info('Applying filter "%s" obtained from %s',
203 disabled_filter, filter_file_path) 204 disabled_filter, filter_file_path)
204 return disabled_filter 205 return disabled_filter
205 206
206 207
207 def _GetTestsFromDevice(runner_factory, devices): 208 def _GetTests(test_options, test_package, devices):
208 """Get a list of tests from a device. 209 """Get a list of tests.
209 210
210 Args: 211 Args:
211 runner_factory: Callable that takes device and shard_index and returns 212 test_options: A GTestOptions object.
212 a TestRunner. 213 test_package: A TestPackageApk object.
213 devices: A list of device ids. 214 devices: A list of attached devices.
214 215
215 Returns: 216 Returns:
216 All the tests in the test suite. 217 A list of all the tests in the test suite.
217 """ 218 """
218 for device in devices: 219 def TestListerRunnerFactory(device, _shard_index):
219 try: 220 class TestListerRunner(test_runner.TestRunner):
220 logging.info('Obtaining tests from %s', device) 221 def RunTest(self, _test):
221 return runner_factory(device, 0).GetAllTests() 222 result = base_test_result.BaseTestResult(
222 except (android_commands.errors.WaitForResponseTimedOutError, 223 'gtest_list_tests', base_test_result.ResultType.PASS)
223 android_commands.errors.DeviceUnresponsiveError), e: 224 self.test_package.Install(self.adb)
224 logging.warning('Failed obtaining test list from %s with exception: %s', 225 result.test_list = self.test_package.GetAllTests(self.adb)
225 device, e) 226 results = base_test_result.TestRunResults()
226 raise Exception('Failed to obtain test list from devices.') 227 results.AddResult(result)
228 return results, None
229 return TestListerRunner(test_options, device, test_package)
230
231 results, _no_retry = test_dispatcher.RunTests(
232 ['gtest_list_tests'], TestListerRunnerFactory, devices)
233 tests = []
234 for r in results.GetAll():
235 tests.extend(r.test_list)
236 return tests
227 237
228 238
229 def _FilterTestsUsingPrefixes(all_tests, pre=False, manual=False): 239 def _FilterTestsUsingPrefixes(all_tests, pre=False, manual=False):
230 """Removes tests with disabled prefixes. 240 """Removes tests with disabled prefixes.
231 241
232 Args: 242 Args:
233 all_tests: List of tests to filter. 243 all_tests: List of tests to filter.
234 pre: If True, include tests with PRE_ prefix. 244 pre: If True, include tests with PRE_ prefix.
235 manual: If True, include tests with MANUAL_ prefix. 245 manual: If True, include tests with MANUAL_ prefix.
236 246
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 test_package = test_package_exe.TestPackageExecutable( 302 test_package = test_package_exe.TestPackageExecutable(
293 test_options.suite_name) 303 test_options.suite_name)
294 if not os.path.exists(test_package.suite_path): 304 if not os.path.exists(test_package.suite_path):
295 raise Exception( 305 raise Exception(
296 'Did not find %s target. Ensure it has been built.' 306 'Did not find %s target. Ensure it has been built.'
297 % test_options.suite_name) 307 % test_options.suite_name)
298 logging.warning('Found target %s', test_package.suite_path) 308 logging.warning('Found target %s', test_package.suite_path)
299 309
300 _GenerateDepsDirUsingIsolate(test_options.suite_name) 310 _GenerateDepsDirUsingIsolate(test_options.suite_name)
301 311
312 tests = _GetTests(test_options, test_package, devices)
313
302 # Constructs a new TestRunner with the current options. 314 # Constructs a new TestRunner with the current options.
303 def TestRunnerFactory(device, _shard_index): 315 def TestRunnerFactory(device, _shard_index):
304 return test_runner.TestRunner( 316 return test_runner.TestRunner(
305 test_options, 317 test_options,
306 device, 318 device,
307 test_package) 319 test_package)
308 320
309 tests = _GetTestsFromDevice(TestRunnerFactory, devices)
310 if test_options.run_disabled: 321 if test_options.run_disabled:
311 test_options = test_options._replace( 322 test_options = test_options._replace(
312 test_arguments=('%s --gtest_also_run_disabled_tests' % 323 test_arguments=('%s --gtest_also_run_disabled_tests' %
313 test_options.test_arguments)) 324 test_options.test_arguments))
314 else: 325 else:
315 tests = _FilterDisabledTests(tests, test_options.suite_name, 326 tests = _FilterDisabledTests(tests, test_options.suite_name,
316 bool(test_options.gtest_filter)) 327 bool(test_options.gtest_filter))
317 if test_options.gtest_filter: 328 if test_options.gtest_filter:
318 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) 329 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter)
319 330
320 # Coalesce unit tests into a single test per device 331 # Coalesce unit tests into a single test per device
321 if test_options.suite_name != 'content_browsertests': 332 if test_options.suite_name != 'content_browsertests':
322 num_devices = len(devices) 333 num_devices = len(devices)
323 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] 334 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)]
324 tests = [t for t in tests if t] 335 tests = [t for t in tests if t]
325 336
326 return (TestRunnerFactory, tests) 337 return (TestRunnerFactory, tests)
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/gtest/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698