Index: build/android/pylib/gtest/setup.py |
diff --git a/build/android/pylib/gtest/dispatch.py b/build/android/pylib/gtest/setup.py |
similarity index 60% |
rename from build/android/pylib/gtest/dispatch.py |
rename to build/android/pylib/gtest/setup.py |
index 3dfb2620c3f74c4af6bfd7813194933031ac0af5..52f0472835fa6073cca471f0e43e0a97d714ecb6 100644 |
--- a/build/android/pylib/gtest/dispatch.py |
+++ b/build/android/pylib/gtest/setup.py |
@@ -2,9 +2,8 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-"""Dispatches GTests.""" |
+"""Runs GTests.""" |
-import copy |
import fnmatch |
import glob |
import logging |
@@ -14,12 +13,7 @@ import shutil |
from pylib import android_commands |
from pylib import cmd_helper |
from pylib import constants |
-from pylib import ports |
from pylib.base import base_test_result |
-from pylib.base import shard |
-from pylib.utils import emulator |
-from pylib.utils import report_results |
-from pylib.utils import xvfb |
import gtest_config |
import test_runner |
@@ -139,12 +133,13 @@ def _GenerateDepsDirUsingIsolate(test_suite, build_type): |
return deps_dir |
-def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): |
+def _FullyQualifiedTestSuites(use_exe_test_runner, suite_name, |
+ build_type): |
"""Get a list of absolute paths to test suite targets. |
Args: |
- exe: if True, use the executable-based test runner. |
- option_test_suite: the test_suite specified as an option. |
+ use_exe_test_runner: if True, use the executable-based test runner. |
+ suite_name: the suite name specified on the command line. |
build_type: 'Release' or 'Debug'. |
Returns: |
@@ -165,8 +160,8 @@ def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): |
return suite.name, os.path.join(test_suite_dir, relpath) |
test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), build_type) |
- if option_test_suite: |
- all_test_suites = [gtest_config.Suite(exe, option_test_suite)] |
+ if suite_name: |
+ all_test_suites = [gtest_config.Suite(use_exe_test_runner, suite_name)] |
else: |
all_test_suites = gtest_config.STABLE_TEST_SUITES |
@@ -207,8 +202,9 @@ def GetAllEnabledTests(runner_factory, devices): |
then filters it again using the disabled list on the host. |
Args: |
- runner_factory: callable that takes a devices and returns a TestRunner. |
- devices: list of devices. |
+ runner_factory: callable that takes device and shard_index and returns |
+ a TestRunner. |
+ devices: a list of device ids. |
Returns: |
List of all enabled tests. |
@@ -227,133 +223,65 @@ def GetAllEnabledTests(runner_factory, devices): |
raise Exception('No device available to get the list of tests.') |
-def _RunATestSuite(options, suite_name): |
- """Run a single test suite. |
- |
- Helper for Dispatch() to allow stop/restart of the emulator across |
- test bundles. If using the emulator, we start it on entry and stop |
- it on exit. |
+def Setup(use_exe_test_runner, suite_name, test_arguments, timeout, |
+ cleanup_test_files, tool, build_type, webkit, push_deps, |
+ gtest_filter): |
+ """Create the test runner factory and tests. |
Args: |
- options: options for running the tests. |
- suite_name: name of the test suite being run. |
+ use_exe_test_runner: if True, use the executable-based test runner. |
+ suite_name: the suite name specified on the command line. |
+ test_arguments: Additional arguments to pass to the test binary. |
+ timeout: Timeout for each test. |
+ cleanup_test_files: Whether or not to cleanup test files on device. |
+ tool: Name of the Valgrind tool. |
+ build_type: 'Release' or 'Debug'. |
+ webkit: Whether the suite is being run from a WebKit checkout. |
+ push_deps: If True, push all dependencies to the device. |
+ gtest_filter: filter for tests. |
Returns: |
- A tuple of (base_test_result.TestRunResult object, exit code). |
- |
- Raises: |
- Exception: For various reasons including device failure or failing to reset |
- the test server port. |
+ A dictionary from suite names to tuples of (TestRunnerFactory, tests). |
""" |
- attached_devices = [] |
- buildbot_emulators = [] |
- |
- if options.use_emulator: |
- buildbot_emulators = emulator.LaunchEmulators(options.emulator_count, |
- options.abi, |
- wait_for_boot=True) |
- attached_devices = [e.device for e in buildbot_emulators] |
- elif options.test_device: |
- attached_devices = [options.test_device] |
- else: |
- attached_devices = android_commands.GetAttachedDevices() |
- |
- if not attached_devices: |
- raise Exception('A device must be attached and online.') |
- |
- # Reset the test port allocation. It's important to do it before starting |
- # to dispatch any tests. |
- if not ports.ResetTestServerPortAllocation(): |
- raise Exception('Failed to reset test server port.') |
- |
- deps_dir = _GenerateDepsDirUsingIsolate(suite_name, options.build_type) |
- |
- # Constructs a new TestRunner with the current options. |
- def RunnerFactory(device, shard_index): |
- return test_runner.TestRunner( |
- device, |
- options.test_suite, |
- options.test_arguments, |
- options.timeout, |
- options.cleanup_test_files, |
- options.tool, |
- options.build_type, |
- options.webkit, |
- options.push_deps, |
- constants.GTEST_TEST_PACKAGE_NAME, |
- constants.GTEST_TEST_ACTIVITY_NAME, |
- constants.GTEST_COMMAND_LINE_FILE, |
- deps_dir=deps_dir) |
- |
- # Get tests and split them up based on the number of devices. |
- if options.test_filter: |
- all_tests = [t for t in options.test_filter.split(':') if t] |
- else: |
- all_tests = GetAllEnabledTests(RunnerFactory, attached_devices) |
- num_devices = len(attached_devices) |
- tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] |
- tests = [t for t in tests if t] |
- |
- # Run tests. |
- test_results, exit_code = shard.ShardAndRunTests( |
- RunnerFactory, attached_devices, tests, options.build_type, |
- test_timeout=None, num_retries=options.num_retries) |
- |
- report_results.LogFull( |
- results=test_results, |
- test_type='Unit test', |
- test_package=suite_name, |
- build_type=options.build_type, |
- flakiness_server=options.flakiness_dashboard_server) |
- |
- for buildbot_emulator in buildbot_emulators: |
- buildbot_emulator.Shutdown() |
- |
- return (test_results, exit_code) |
- |
+ all_test_suites = _FullyQualifiedTestSuites(use_exe_test_runner, suite_name, |
+ build_type) |
+ # TODO(gkanwar): This breaks the abstraction of having dispatch.py deal |
+ # entirely with the devices. Can we do this another way? |
+ attached_devices = android_commands.GetAttachedDevices() |
-def _ListTestSuites(): |
- """Display a list of available test suites.""" |
- print 'Available test suites are:' |
- for test_suite in gtest_config.STABLE_TEST_SUITES: |
- print test_suite |
+ tests_dict = {} |
+ for suite_name, suite_path in all_test_suites: |
+ deps_dir = _GenerateDepsDirUsingIsolate(suite_name, build_type) |
frankf
2013/07/16 00:02:18
this won't work. You're just overwriting the deps
gkanwar
2013/07/16 17:44:36
Moved dealing with no test suite specified into te
|
+ # Constructs a new TestRunner with the current options. |
+ def TestRunnerFactory(device, shard_index): |
+ return test_runner.TestRunner( |
+ device, |
+ suite_path, |
+ test_arguments, |
+ timeout, |
+ cleanup_test_files, |
+ tool, |
+ build_type, |
+ webkit, |
+ push_deps, |
+ constants.GTEST_TEST_PACKAGE_NAME, |
+ constants.GTEST_TEST_ACTIVITY_NAME, |
+ constants.GTEST_COMMAND_LINE_FILE, |
+ deps_dir=deps_dir) |
+ |
+ # Get tests and split them up based on the number of devices. |
+ # TODO(gkanwar): Sharding shouldn't happen here. |
+ if gtest_filter: |
+ all_tests = [t for t in gtest_filter.split(':') if t] |
+ else: |
+ all_tests = GetAllEnabledTests(TestRunnerFactory, attached_devices) |
+ num_devices = len(attached_devices) |
+ tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] |
+ tests = [t for t in tests if t] |
-def Dispatch(options): |
- """Dispatches the tests, sharding if possible. |
- |
- If options.use_emulator is True, all tests will be run in new emulator |
- instance. |
- |
- Args: |
- options: options for running the tests. |
- |
- Returns: |
- base_test_result.TestRunResults object with the results of running the tests |
- """ |
- results = base_test_result.TestRunResults() |
- |
- if options.test_suite == 'help': |
- _ListTestSuites() |
- return (results, 0) |
- |
- if options.use_xvfb: |
- framebuffer = xvfb.Xvfb() |
- framebuffer.Start() |
+ tests_dict[suite_name] = (TestRunnerFactory, tests) |
- all_test_suites = _FullyQualifiedTestSuites(options.exe, options.test_suite, |
- options.build_type) |
- exit_code = 0 |
- for suite_name, suite_path in all_test_suites: |
- # Give each test suite its own copy of options. |
- test_options = copy.deepcopy(options) |
- test_options.test_suite = suite_path |
- test_results, test_exit_code = _RunATestSuite(test_options, suite_name) |
- results.AddTestRunResults(test_results) |
- if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
- exit_code = test_exit_code |
- |
- if options.use_xvfb: |
- framebuffer.Stop() |
- |
- return (results, exit_code) |
+ # TODO(gkanwar): Once the suite option becomes required test_dict should |
+ # just be a single tuple. |
+ return tests_dict |