| 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 cmd_helper | 15 from pylib import cmd_helper |
| 16 from pylib import constants | 16 from pylib import constants |
| 17 from pylib import valgrind_tools |
| 17 | 18 |
| 18 from pylib.base import base_test_result | 19 from pylib.base import base_test_result |
| 19 from pylib.base import test_dispatcher | 20 from pylib.base import test_dispatcher |
| 21 from pylib.device import device_utils |
| 20 from pylib.gtest import test_package_apk | 22 from pylib.gtest import test_package_apk |
| 21 from pylib.gtest import test_package_exe | 23 from pylib.gtest import test_package_exe |
| 22 from pylib.gtest import test_runner | 24 from pylib.gtest import test_runner |
| 23 | 25 |
| 24 sys.path.insert(0, | 26 sys.path.insert(0, |
| 25 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', | 27 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', |
| 26 'common')) | 28 'common')) |
| 27 import unittest_util # pylint: disable=F0401 | 29 import unittest_util # pylint: disable=F0401 |
| 28 | 30 |
| 29 | 31 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 List of tests remaining. | 282 List of tests remaining. |
| 281 """ | 283 """ |
| 282 tests = _FilterTestsUsingPrefixes( | 284 tests = _FilterTestsUsingPrefixes( |
| 283 tests, has_gtest_filter, has_gtest_filter) | 285 tests, has_gtest_filter, has_gtest_filter) |
| 284 tests = unittest_util.FilterTestNames( | 286 tests = unittest_util.FilterTestNames( |
| 285 tests, _GetDisabledTestsFilterFromFile(suite_name)) | 287 tests, _GetDisabledTestsFilterFromFile(suite_name)) |
| 286 | 288 |
| 287 return tests | 289 return tests |
| 288 | 290 |
| 289 | 291 |
| 292 def PushDataDeps(device, test_options, test_package): |
| 293 valgrind_tools.PushFilesForTool(test_options.tool, device) |
| 294 if os.path.exists(constants.ISOLATE_DEPS_DIR): |
| 295 device_dir = ( |
| 296 constants.TEST_EXECUTABLE_DIR |
| 297 if test_package.suite_name == 'breakpad_unittests' |
| 298 else device.GetExternalStoragePath()) |
| 299 device.PushChangedFiles([ |
| 300 (os.path.join(constants.ISOLATE_DEPS_DIR, p), |
| 301 '%s/%s' % (device_dir, p)) |
| 302 for p in os.listdir(constants.ISOLATE_DEPS_DIR)]) |
| 303 |
| 304 |
| 290 def Setup(test_options, devices): | 305 def Setup(test_options, devices): |
| 291 """Create the test runner factory and tests. | 306 """Create the test runner factory and tests. |
| 292 | 307 |
| 293 Args: | 308 Args: |
| 294 test_options: A GTestOptions object. | 309 test_options: A GTestOptions object. |
| 295 devices: A list of attached devices. | 310 devices: A list of attached devices. |
| 296 | 311 |
| 297 Returns: | 312 Returns: |
| 298 A tuple of (TestRunnerFactory, tests). | 313 A tuple of (TestRunnerFactory, tests). |
| 299 """ | 314 """ |
| 300 test_package = test_package_apk.TestPackageApk(test_options.suite_name) | 315 test_package = test_package_apk.TestPackageApk(test_options.suite_name) |
| 301 if not os.path.exists(test_package.suite_path): | 316 if not os.path.exists(test_package.suite_path): |
| 302 exe_test_package = test_package_exe.TestPackageExecutable( | 317 exe_test_package = test_package_exe.TestPackageExecutable( |
| 303 test_options.suite_name) | 318 test_options.suite_name) |
| 304 if not os.path.exists(exe_test_package.suite_path): | 319 if not os.path.exists(exe_test_package.suite_path): |
| 305 raise Exception( | 320 raise Exception( |
| 306 'Did not find %s target. Ensure it has been built.\n' | 321 'Did not find %s target. Ensure it has been built.\n' |
| 307 '(not found at %s or %s)' | 322 '(not found at %s or %s)' |
| 308 % (test_options.suite_name, | 323 % (test_options.suite_name, |
| 309 test_package.suite_path, | 324 test_package.suite_path, |
| 310 exe_test_package.suite_path)) | 325 exe_test_package.suite_path)) |
| 311 test_package = exe_test_package | 326 test_package = exe_test_package |
| 312 logging.warning('Found target %s', test_package.suite_path) | 327 logging.warning('Found target %s', test_package.suite_path) |
| 313 | 328 |
| 314 _GenerateDepsDirUsingIsolate(test_options.suite_name, | 329 _GenerateDepsDirUsingIsolate(test_options.suite_name, |
| 315 test_options.isolate_file_path) | 330 test_options.isolate_file_path) |
| 316 | 331 |
| 332 device_utils.DeviceUtils.parallel(devices).pMap( |
| 333 PushDataDeps, test_options, test_package) |
| 334 |
| 317 tests = _GetTests(test_options, test_package, devices) | 335 tests = _GetTests(test_options, test_package, devices) |
| 318 | 336 |
| 319 # Constructs a new TestRunner with the current options. | 337 # Constructs a new TestRunner with the current options. |
| 320 def TestRunnerFactory(device, _shard_index): | 338 def TestRunnerFactory(device, _shard_index): |
| 321 return test_runner.TestRunner( | 339 return test_runner.TestRunner( |
| 322 test_options, | 340 test_options, |
| 323 device, | 341 device, |
| 324 test_package) | 342 test_package) |
| 325 | 343 |
| 326 if test_options.run_disabled: | 344 if test_options.run_disabled: |
| 327 test_options = test_options._replace( | 345 test_options = test_options._replace( |
| 328 test_arguments=('%s --gtest_also_run_disabled_tests' % | 346 test_arguments=('%s --gtest_also_run_disabled_tests' % |
| 329 test_options.test_arguments)) | 347 test_options.test_arguments)) |
| 330 else: | 348 else: |
| 331 tests = _FilterDisabledTests(tests, test_options.suite_name, | 349 tests = _FilterDisabledTests(tests, test_options.suite_name, |
| 332 bool(test_options.gtest_filter)) | 350 bool(test_options.gtest_filter)) |
| 333 if test_options.gtest_filter: | 351 if test_options.gtest_filter: |
| 334 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) | 352 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) |
| 335 | 353 |
| 336 # Coalesce unit tests into a single test per device | 354 # Coalesce unit tests into a single test per device |
| 337 if test_options.suite_name != 'content_browsertests': | 355 if test_options.suite_name != 'content_browsertests': |
| 338 num_devices = len(devices) | 356 num_devices = len(devices) |
| 339 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] | 357 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] |
| 340 tests = [t for t in tests if t] | 358 tests = [t for t in tests if t] |
| 341 | 359 |
| 342 return (TestRunnerFactory, tests) | 360 return (TestRunnerFactory, tests) |
| OLD | NEW |