| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Runs the Python tests (relies on using the Java test runner).""" | 5 """Runs the Python tests (relies on using the Java test runner).""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import types | 10 import types |
| 11 | 11 |
| 12 from pylib import android_commands | 12 from pylib import android_commands |
| 13 from pylib import constants | |
| 14 from pylib.base import base_test_result | 13 from pylib.base import base_test_result |
| 15 from pylib.instrumentation import test_package | 14 from pylib.instrumentation import test_package |
| 16 from pylib.instrumentation import test_runner | 15 from pylib.instrumentation import test_runner |
| 16 from pylib.utils import report_results |
| 17 | 17 |
| 18 import python_test_base | 18 import python_test_base |
| 19 from python_test_caller import CallPythonTest | |
| 20 from python_test_sharder import PythonTestSharder | 19 from python_test_sharder import PythonTestSharder |
| 21 from test_info_collection import TestInfoCollection | 20 from test_info_collection import TestInfoCollection |
| 22 | 21 |
| 23 | 22 |
| 24 def _GetPythonFiles(root, files): | 23 def _GetPythonFiles(root, files): |
| 25 """Returns all files from |files| that end in 'Test.py'. | 24 """Returns all files from |files| that end in 'Test.py'. |
| 26 | 25 |
| 27 Args: | 26 Args: |
| 28 root: A directory name with python files. | 27 root: A directory name with python files. |
| 29 files: A list of file names. | 28 files: A list of file names. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 | 48 |
| 50 | 49 |
| 51 def DispatchPythonTests(options): | 50 def DispatchPythonTests(options): |
| 52 """Dispatches the Python tests. If there are multiple devices, use sharding. | 51 """Dispatches the Python tests. If there are multiple devices, use sharding. |
| 53 | 52 |
| 54 Args: | 53 Args: |
| 55 options: command line options. | 54 options: command line options. |
| 56 | 55 |
| 57 Returns: | 56 Returns: |
| 58 A list of test results. | 57 A list of test results. |
| 58 |
| 59 Raises: |
| 60 Exception: If there are no attached devices. |
| 59 """ | 61 """ |
| 60 | 62 |
| 61 attached_devices = android_commands.GetAttachedDevices() | 63 attached_devices = android_commands.GetAttachedDevices() |
| 62 if not attached_devices: | 64 if not attached_devices: |
| 63 raise Exception('You have no devices attached or visible!') | 65 raise Exception('You have no devices attached or visible!') |
| 64 if options.device: | 66 if options.test_device: |
| 65 attached_devices = [options.device] | 67 attached_devices = [options.test_device] |
| 66 | 68 |
| 67 test_collection = TestInfoCollection() | 69 test_collection = TestInfoCollection() |
| 68 all_tests = _GetAllTests(options.python_test_root, options.official_build) | 70 all_tests = _GetAllTests(options.python_test_root, options.official_build) |
| 69 test_collection.AddTests(all_tests) | 71 test_collection.AddTests(all_tests) |
| 70 test_names = [t.qualified_name for t in all_tests] | 72 test_names = [t.qualified_name for t in all_tests] |
| 71 logging.debug('All available tests: ' + str(test_names)) | 73 logging.debug('All available tests: ' + str(test_names)) |
| 72 | 74 |
| 73 available_tests = test_collection.GetAvailableTests( | 75 available_tests = test_collection.GetAvailableTests( |
| 74 options.annotations, options.exclude_annotations, options.test_filter) | 76 options.annotations, options.exclude_annotations, options.test_filter) |
| 75 | 77 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 99 logging.warning('Debugger can not be sharded, ' | 101 logging.warning('Debugger can not be sharded, ' |
| 100 'using first available device') | 102 'using first available device') |
| 101 attached_devices = attached_devices[:1] | 103 attached_devices = attached_devices[:1] |
| 102 logging.debug('Running Python tests') | 104 logging.debug('Running Python tests') |
| 103 sharder = PythonTestSharder(attached_devices, available_tests, options) | 105 sharder = PythonTestSharder(attached_devices, available_tests, options) |
| 104 test_results = sharder.RunShardedTests() | 106 test_results = sharder.RunShardedTests() |
| 105 | 107 |
| 106 return test_results | 108 return test_results |
| 107 | 109 |
| 108 | 110 |
| 111 def Dispatch(options): |
| 112 """Wraps DispatchPythonTests to log and return the number of failed tests.""" |
| 113 |
| 114 results = DispatchPythonTests(options) |
| 115 report_results.LogFull( |
| 116 results=results, |
| 117 test_type='HostDriven', |
| 118 test_package=os.path.basename(options.test_apk), |
| 119 annotation=options.annotations, |
| 120 build_type=options.build_type, |
| 121 flakiness_server=options.flakiness_dashboard_server) |
| 122 return len(results.GetNotPass()) |
| 123 |
| 124 |
| 109 def _GetTestModules(python_test_root, is_official_build): | 125 def _GetTestModules(python_test_root, is_official_build): |
| 110 """Retrieve a sorted list of pythonDrivenTests. | 126 """Retrieve a sorted list of pythonDrivenTests. |
| 111 | 127 |
| 112 Walks the location of pythonDrivenTests, imports them, and provides the list | 128 Walks the location of pythonDrivenTests, imports them, and provides the list |
| 113 of imported modules to the caller. | 129 of imported modules to the caller. |
| 114 | 130 |
| 115 Args: | 131 Args: |
| 116 python_test_root: the path to walk, looking for pythonDrivenTests | 132 python_test_root: the path to walk, looking for pythonDrivenTests |
| 117 is_official_build: whether to run only those tests marked 'official' | 133 is_official_build: whether to run only those tests marked 'official' |
| 118 | 134 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 Returns: | 219 Returns: |
| 204 List of test case objects for all available test methods. | 220 List of test case objects for all available test methods. |
| 205 """ | 221 """ |
| 206 if not test_root: | 222 if not test_root: |
| 207 return [] | 223 return [] |
| 208 all_tests = [] | 224 all_tests = [] |
| 209 test_module_list = _GetTestModules(test_root, is_official_build) | 225 test_module_list = _GetTestModules(test_root, is_official_build) |
| 210 for module in test_module_list: | 226 for module in test_module_list: |
| 211 all_tests.extend(_GetTestClassesFromModule(module)) | 227 all_tests.extend(_GetTestClassesFromModule(module)) |
| 212 return all_tests | 228 return all_tests |
| OLD | NEW |