| 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 | 13 from pylib import constants |
| 14 from pylib.base.test_result import TestResults | 14 from pylib.base.test_result import TestResults |
| 15 from pylib.instrumentation import apk_info | 15 from pylib.instrumentation import apk_info |
| 16 from pylib.instrumentation import run_java_tests | 16 from pylib.instrumentation import test_runner |
| 17 from pylib.instrumentation.run_java_tests import FatalTestException | |
| 18 | 17 |
| 19 import python_test_base | 18 import python_test_base |
| 20 from python_test_caller import CallPythonTest | 19 from python_test_caller import CallPythonTest |
| 21 from python_test_sharder import PythonTestSharder | 20 from python_test_sharder import PythonTestSharder |
| 22 from test_info_collection import TestInfoCollection | 21 from test_info_collection import TestInfoCollection |
| 23 | 22 |
| 24 | 23 |
| 25 def _GetPythonFiles(root, files): | 24 def _GetPythonFiles(root, files): |
| 26 """Returns all files from |files| that end in 'Test.py'. | 25 """Returns all files from |files| that end in 'Test.py'. |
| 27 | 26 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 | 53 |
| 55 Args: | 54 Args: |
| 56 options: command line options. | 55 options: command line options. |
| 57 | 56 |
| 58 Returns: | 57 Returns: |
| 59 A list of test results. | 58 A list of test results. |
| 60 """ | 59 """ |
| 61 | 60 |
| 62 attached_devices = android_commands.GetAttachedDevices() | 61 attached_devices = android_commands.GetAttachedDevices() |
| 63 if not attached_devices: | 62 if not attached_devices: |
| 64 raise FatalTestException('You have no devices attached or visible!') | 63 raise Exception('You have no devices attached or visible!') |
| 65 if options.device: | 64 if options.device: |
| 66 attached_devices = [options.device] | 65 attached_devices = [options.device] |
| 67 | 66 |
| 68 test_collection = TestInfoCollection() | 67 test_collection = TestInfoCollection() |
| 69 all_tests = _GetAllTests(options.python_test_root, options.official_build) | 68 all_tests = _GetAllTests(options.python_test_root, options.official_build) |
| 70 test_collection.AddTests(all_tests) | 69 test_collection.AddTests(all_tests) |
| 71 test_names = [t.qualified_name for t in all_tests] | 70 test_names = [t.qualified_name for t in all_tests] |
| 72 logging.debug('All available tests: ' + str(test_names)) | 71 logging.debug('All available tests: ' + str(test_names)) |
| 73 | 72 |
| 74 available_tests = test_collection.GetAvailableTests( | 73 available_tests = test_collection.GetAvailableTests( |
| 75 options.annotation, options.test_filter) | 74 options.annotation, options.test_filter) |
| 76 | 75 |
| 77 if not available_tests: | 76 if not available_tests: |
| 78 logging.warning('No Python tests to run with current args.') | 77 logging.warning('No Python tests to run with current args.') |
| 79 return TestResults() | 78 return TestResults() |
| 80 | 79 |
| 81 available_tests *= options.number_of_runs | 80 available_tests *= options.number_of_runs |
| 82 test_names = [t.qualified_name for t in available_tests] | 81 test_names = [t.qualified_name for t in available_tests] |
| 83 logging.debug('Final list of tests to run: ' + str(test_names)) | 82 logging.debug('Final list of tests to run: ' + str(test_names)) |
| 84 | 83 |
| 85 # Copy files to each device before running any tests. | 84 # Copy files to each device before running any tests. |
| 86 for device_id in attached_devices: | 85 for device_id in attached_devices: |
| 87 logging.debug('Pushing files to device %s', device_id) | 86 logging.debug('Pushing files to device %s', device_id) |
| 88 apks = [apk_info.ApkInfo(options.test_apk_path, options.test_apk_jar_path)] | 87 apks = [apk_info.ApkInfo(options.test_apk_path, options.test_apk_jar_path)] |
| 89 test_files_copier = run_java_tests.TestRunner(options, device_id, | 88 test_files_copier = test_runner.TestRunner(options, device_id, None, False, |
| 90 None, False, 0, apks, []) | 89 0, apks, []) |
| 91 test_files_copier.CopyTestFilesOnce() | 90 test_files_copier.CopyTestFilesOnce() |
| 92 | 91 |
| 93 # Actually run the tests. | 92 # Actually run the tests. |
| 94 if len(attached_devices) > 1 and options.wait_for_debugger: | 93 if len(attached_devices) > 1 and options.wait_for_debugger: |
| 95 logging.warning('Debugger can not be sharded, ' | 94 logging.warning('Debugger can not be sharded, ' |
| 96 'using first available device') | 95 'using first available device') |
| 97 attached_devices = attached_devices[:1] | 96 attached_devices = attached_devices[:1] |
| 98 logging.debug('Running Python tests') | 97 logging.debug('Running Python tests') |
| 99 sharder = PythonTestSharder(attached_devices, available_tests, options) | 98 sharder = PythonTestSharder(attached_devices, available_tests, options) |
| 100 test_results = sharder.RunShardedTests() | 99 test_results = sharder.RunShardedTests() |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 Returns: | 198 Returns: |
| 200 List of test case objects for all available test methods. | 199 List of test case objects for all available test methods. |
| 201 """ | 200 """ |
| 202 if not test_root: | 201 if not test_root: |
| 203 return [] | 202 return [] |
| 204 all_tests = [] | 203 all_tests = [] |
| 205 test_module_list = _GetTestModules(test_root, is_official_build) | 204 test_module_list = _GetTestModules(test_root, is_official_build) |
| 206 for module in test_module_list: | 205 for module in test_module_list: |
| 207 all_tests.extend(_GetTestClassesFromModule(module)) | 206 all_tests.extend(_GetTestClassesFromModule(module)) |
| 208 return all_tests | 207 return all_tests |
| OLD | NEW |