OLD | NEW |
---|---|
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 Loading... | |
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 'ListTheTests', base_test_result.ResultType.PASS) |
craigdh
2014/04/03 21:58:06
Since this only applies to gtests, the resulting e
| |
223 android_commands.errors.DeviceUnresponsiveError), e: | 224 result.test_list = self.GetAllTests() |
craigdh
2014/04/03 21:58:06
just move the code from GetAllTests() inline here,
| |
224 logging.warning('Failed obtaining test list from %s with exception: %s', | 225 results = base_test_result.TestRunResults() |
225 device, e) | 226 results.AddResult(result) |
226 raise Exception('Failed to obtain test list from devices.') | 227 return results, None |
228 return TestListerRunner(test_options, device, test_package) | |
229 | |
230 results, _no_retry = test_dispatcher.RunTests( | |
231 ['ListTheTests'], TestListerRunnerFactory, devices) | |
232 tests = [] | |
233 for r in results.GetAll(): | |
234 tests.extend(r.test_list) | |
235 return tests | |
227 | 236 |
228 | 237 |
229 def _FilterTestsUsingPrefixes(all_tests, pre=False, manual=False): | 238 def _FilterTestsUsingPrefixes(all_tests, pre=False, manual=False): |
230 """Removes tests with disabled prefixes. | 239 """Removes tests with disabled prefixes. |
231 | 240 |
232 Args: | 241 Args: |
233 all_tests: List of tests to filter. | 242 all_tests: List of tests to filter. |
234 pre: If True, include tests with PRE_ prefix. | 243 pre: If True, include tests with PRE_ prefix. |
235 manual: If True, include tests with MANUAL_ prefix. | 244 manual: If True, include tests with MANUAL_ prefix. |
236 | 245 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 test_package = test_package_exe.TestPackageExecutable( | 301 test_package = test_package_exe.TestPackageExecutable( |
293 test_options.suite_name) | 302 test_options.suite_name) |
294 if not os.path.exists(test_package.suite_path): | 303 if not os.path.exists(test_package.suite_path): |
295 raise Exception( | 304 raise Exception( |
296 'Did not find %s target. Ensure it has been built.' | 305 'Did not find %s target. Ensure it has been built.' |
297 % test_options.suite_name) | 306 % test_options.suite_name) |
298 logging.warning('Found target %s', test_package.suite_path) | 307 logging.warning('Found target %s', test_package.suite_path) |
299 | 308 |
300 _GenerateDepsDirUsingIsolate(test_options.suite_name) | 309 _GenerateDepsDirUsingIsolate(test_options.suite_name) |
301 | 310 |
311 tests = _GetTests(test_options, test_package, devices) | |
312 | |
302 # Constructs a new TestRunner with the current options. | 313 # Constructs a new TestRunner with the current options. |
303 def TestRunnerFactory(device, _shard_index): | 314 def TestRunnerFactory(device, _shard_index): |
304 return test_runner.TestRunner( | 315 return test_runner.TestRunner( |
305 test_options, | 316 test_options, |
306 device, | 317 device, |
307 test_package) | 318 test_package) |
308 | 319 |
309 tests = _GetTestsFromDevice(TestRunnerFactory, devices) | |
310 if test_options.run_disabled: | 320 if test_options.run_disabled: |
311 test_options = test_options._replace( | 321 test_options = test_options._replace( |
312 test_arguments=('%s --gtest_also_run_disabled_tests' % | 322 test_arguments=('%s --gtest_also_run_disabled_tests' % |
313 test_options.test_arguments)) | 323 test_options.test_arguments)) |
314 else: | 324 else: |
315 tests = _FilterDisabledTests(tests, test_options.suite_name, | 325 tests = _FilterDisabledTests(tests, test_options.suite_name, |
316 bool(test_options.gtest_filter)) | 326 bool(test_options.gtest_filter)) |
317 if test_options.gtest_filter: | 327 if test_options.gtest_filter: |
318 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) | 328 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) |
319 | 329 |
320 # Coalesce unit tests into a single test per device | 330 # Coalesce unit tests into a single test per device |
321 if test_options.suite_name != 'content_browsertests': | 331 if test_options.suite_name != 'content_browsertests': |
322 num_devices = len(devices) | 332 num_devices = len(devices) |
323 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] | 333 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] |
324 tests = [t for t in tests if t] | 334 tests = [t for t in tests if t] |
325 | 335 |
326 return (TestRunnerFactory, tests) | 336 return (TestRunnerFactory, tests) |
OLD | NEW |