| 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 | 6 |
| 7 import fnmatch | 7 import fnmatch |
| 8 import glob | 8 import glob |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 import shutil | 11 import shutil |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 from pylib import android_commands | 14 from pylib import android_commands |
| 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 ports | 17 from pylib import ports |
| 18 from pylib.base import base_test_result | |
| 19 | 18 |
| 20 import gtest_config | |
| 21 import test_package_apk | 19 import test_package_apk |
| 22 import test_package_exe | 20 import test_package_exe |
| 23 import test_runner | 21 import test_runner |
| 24 | 22 |
| 25 sys.path.insert(0, | 23 sys.path.insert(0, |
| 26 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib')) | 24 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib')) |
| 27 from common import unittest_util | 25 from common import unittest_util |
| 28 | 26 |
| 29 | 27 |
| 30 _ISOLATE_FILE_PATHS = { | 28 _ISOLATE_FILE_PATHS = { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 tests, bool(gtest_filter), bool(gtest_filter)) | 249 tests, bool(gtest_filter), bool(gtest_filter)) |
| 252 tests = unittest_util.FilterTestNames( | 250 tests = unittest_util.FilterTestNames( |
| 253 tests, _GetDisabledTestsFilterFromFile(suite_name)) | 251 tests, _GetDisabledTestsFilterFromFile(suite_name)) |
| 254 | 252 |
| 255 if gtest_filter: | 253 if gtest_filter: |
| 256 tests = unittest_util.FilterTestNames(tests, gtest_filter) | 254 tests = unittest_util.FilterTestNames(tests, gtest_filter) |
| 257 | 255 |
| 258 return tests | 256 return tests |
| 259 | 257 |
| 260 | 258 |
| 261 def Setup(test_options): | 259 def Setup(test_options, devices): |
| 262 """Create the test runner factory and tests. | 260 """Create the test runner factory and tests. |
| 263 | 261 |
| 264 Args: | 262 Args: |
| 265 test_options: A GTestOptions object. | 263 test_options: A GTestOptions object. |
| 264 devices: A list of attached devices. |
| 266 | 265 |
| 267 Returns: | 266 Returns: |
| 268 A tuple of (TestRunnerFactory, tests). | 267 A tuple of (TestRunnerFactory, tests). |
| 269 """ | 268 """ |
| 270 | 269 |
| 271 if not ports.ResetTestServerPortAllocation(): | 270 if not ports.ResetTestServerPortAllocation(): |
| 272 raise Exception('Failed to reset test server port.') | 271 raise Exception('Failed to reset test server port.') |
| 273 | 272 |
| 274 test_package = test_package_apk.TestPackageApk(test_options.suite_name) | 273 test_package = test_package_apk.TestPackageApk(test_options.suite_name) |
| 275 if not os.path.exists(test_package.suite_path): | 274 if not os.path.exists(test_package.suite_path): |
| 276 test_package = test_package_exe.TestPackageExecutable( | 275 test_package = test_package_exe.TestPackageExecutable( |
| 277 test_options.suite_name) | 276 test_options.suite_name) |
| 278 if not os.path.exists(test_package.suite_path): | 277 if not os.path.exists(test_package.suite_path): |
| 279 raise Exception( | 278 raise Exception( |
| 280 'Did not find %s target. Ensure it has been built.' | 279 'Did not find %s target. Ensure it has been built.' |
| 281 % test_options.suite_name) | 280 % test_options.suite_name) |
| 282 logging.warning('Found target %s', test_package.suite_path) | 281 logging.warning('Found target %s', test_package.suite_path) |
| 283 | 282 |
| 284 _GenerateDepsDirUsingIsolate(test_options.suite_name) | 283 _GenerateDepsDirUsingIsolate(test_options.suite_name) |
| 285 | 284 |
| 286 # Constructs a new TestRunner with the current options. | 285 # Constructs a new TestRunner with the current options. |
| 287 def TestRunnerFactory(device, shard_index): | 286 def TestRunnerFactory(device, shard_index): |
| 288 return test_runner.TestRunner( | 287 return test_runner.TestRunner( |
| 289 test_options, | 288 test_options, |
| 290 device, | 289 device, |
| 291 test_package) | 290 test_package) |
| 292 | 291 |
| 293 attached_devices = android_commands.GetAttachedDevices() | |
| 294 tests = _GetTestsFiltered(test_options.suite_name, test_options.gtest_filter, | 292 tests = _GetTestsFiltered(test_options.suite_name, test_options.gtest_filter, |
| 295 TestRunnerFactory, attached_devices) | 293 TestRunnerFactory, devices) |
| 296 # Coalesce unit tests into a single test per device | 294 # Coalesce unit tests into a single test per device |
| 297 if test_options.suite_name != 'content_browsertests': | 295 if test_options.suite_name != 'content_browsertests': |
| 298 num_devices = len(attached_devices) | 296 num_devices = len(devices) |
| 299 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] | 297 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] |
| 300 tests = [t for t in tests if t] | 298 tests = [t for t in tests if t] |
| 301 | 299 |
| 302 return (TestRunnerFactory, tests) | 300 return (TestRunnerFactory, tests) |
| OLD | NEW |