Index: build/android/pylib/host_driven/run_python_tests.py |
diff --git a/build/android/pylib/host_driven/run_python_tests.py b/build/android/pylib/host_driven/run_python_tests.py |
index 3f31c29dc9115664d8d1da78045cc764894ff41d..a0e4e8896a1e465f7926a60f63403178772e5847 100644 |
--- a/build/android/pylib/host_driven/run_python_tests.py |
+++ b/build/android/pylib/host_driven/run_python_tests.py |
@@ -10,45 +10,20 @@ import sys |
import types |
from pylib import android_commands |
+from pylib import dispatch |
from pylib.base import base_test_result |
+from pylib.base import shard |
from pylib.instrumentation import test_package |
from pylib.instrumentation import test_runner |
from pylib.utils import report_results |
import python_test_base |
-from python_test_sharder import PythonTestSharder |
+import python_test_sharder |
from test_info_collection import TestInfoCollection |
-def _GetPythonFiles(root, files): |
- """Returns all files from |files| that end in 'Test.py'. |
- |
- Args: |
- root: A directory name with python files. |
- files: A list of file names. |
- |
- Returns: |
- A list with all Python driven test file paths. |
- """ |
- return [os.path.join(root, f) for f in files if f.endswith('Test.py')] |
- |
- |
-def _InferImportNameFromFile(python_file): |
- """Given a file, infer the import name for that file. |
- |
- Example: /usr/foo/bar/baz.py -> baz. |
- |
- Args: |
- python_file: path to the Python file, ostensibly to import later. |
- |
- Returns: |
- The module name for the given file. |
- """ |
- return os.path.splitext(os.path.basename(python_file))[0] |
- |
- |
-def DispatchPythonTests(options): |
- """Dispatches the Python tests. If there are multiple devices, use sharding. |
+def RunHostDrivenTests(options): |
+ """Runs Python host-driven tests. |
Args: |
options: command line options. |
@@ -60,12 +35,6 @@ def DispatchPythonTests(options): |
Exception: If there are no attached devices. |
""" |
- attached_devices = android_commands.GetAttachedDevices() |
- if not attached_devices: |
- raise Exception('You have no devices attached or visible!') |
- if options.test_device: |
- attached_devices = [options.test_device] |
- |
test_collection = TestInfoCollection() |
all_tests = _GetAllTests(options.python_test_root, options.official_build) |
test_collection.AddTests(all_tests) |
@@ -82,35 +51,40 @@ def DispatchPythonTests(options): |
test_names = [t.qualified_name for t in available_tests] |
logging.debug('Final list of tests to run: ' + str(test_names)) |
- # Copy files to each device before running any tests. |
- for device_id in attached_devices: |
- logging.debug('Pushing files to device %s', device_id) |
- test_pkg = test_package.TestPackage(options.test_apk_path, |
- options.test_apk_jar_path) |
- test_files_copier = test_runner.TestRunner( |
- options, device_id, 0, test_pkg, []) |
- test_files_copier.InstallTestPackage() |
- if options.push_deps: |
- logging.info('Pushing data deps to device.') |
- test_files_copier.PushDataDeps() |
- else: |
- logging.warning('Skipping pushing data deps to device.') |
- |
- # Actually run the tests. |
- if len(attached_devices) > 1 and options.wait_for_debugger: |
- logging.warning('Debugger can not be sharded, ' |
- 'using first available device') |
- attached_devices = attached_devices[:1] |
- logging.debug('Running Python tests') |
- sharder = PythonTestSharder(attached_devices, available_tests, options) |
- test_results = sharder.RunShardedTests() |
- |
- if not test_results.DidRunPass(): |
- return (test_results, 1) |
- |
- return (test_results, 0) |
+ def TestRunnerFactory(device, shard_index): |
+ return python_test_sharder.PythonTestRunner(options, device, shard_index) |
+ |
+ return dispatch.Dispatch(options, available_tests, TestRunnerFactory) |
+ |
+ |
+def _GetPythonFiles(root, files): |
+ """Returns all files from |files| that end in 'Test.py'. |
+ |
+ Args: |
+ root: A directory name with python files. |
+ files: A list of file names. |
+ |
+ Returns: |
+ A list with all Python driven test file paths. |
+ """ |
+ return [os.path.join(root, f) for f in files if f.endswith('Test.py')] |
+ |
+ |
+def _InferImportNameFromFile(python_file): |
+ """Given a file, infer the import name for that file. |
+ |
+ Example: /usr/foo/bar/baz.py -> baz. |
+ |
+ Args: |
+ python_file: path to the Python file, ostensibly to import later. |
+ |
+ Returns: |
+ The module name for the given file. |
+ """ |
+ return os.path.splitext(os.path.basename(python_file))[0] |
+# TODO(gkanwar): replace these functions with functionality from unittest |
def _GetTestModules(python_test_root, is_official_build): |
"""Retrieve a sorted list of pythonDrivenTests. |