Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: build/android/pylib/host_driven/run_python_tests.py

Issue 15942016: Creates a new test running script test_runner.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import base_test_result 14 from pylib.base import base_test_result
15 from pylib.instrumentation import test_package 15 from pylib.instrumentation import test_package as instrumentation_test_package
16 from pylib.instrumentation import test_runner 16 from pylib.instrumentation import test_runner as instrumentation_test_runner
17 from pylib.uiautomator import test_package as uiautomator_test_package
18 from pylib.uiautomator import test_runner as uiautomator_test_runner
19 from pylib.utils import report_results
17 20
18 import python_test_base 21 import python_test_base
19 from python_test_caller import CallPythonTest 22 from python_test_caller import CallPythonTest
20 from python_test_sharder import PythonTestSharder 23 from python_test_sharder import PythonTestSharder
21 from test_info_collection import TestInfoCollection 24 from test_info_collection import TestInfoCollection
22 25
23 26
24 def _GetPythonFiles(root, files): 27 def _GetPythonFiles(root, files):
25 """Returns all files from |files| that end in 'Test.py'. 28 """Returns all files from |files| that end in 'Test.py'.
26 29
(...skipping 27 matching lines...) Expand all
54 Args: 57 Args:
55 options: command line options. 58 options: command line options.
56 59
57 Returns: 60 Returns:
58 A list of test results. 61 A list of test results.
59 """ 62 """
60 63
61 attached_devices = android_commands.GetAttachedDevices() 64 attached_devices = android_commands.GetAttachedDevices()
62 if not attached_devices: 65 if not attached_devices:
63 raise Exception('You have no devices attached or visible!') 66 raise Exception('You have no devices attached or visible!')
64 if options.device: 67 if options.test_device:
65 attached_devices = [options.device] 68 attached_devices = [options.test_device]
frankf 2013/06/11 02:50:15 Why this name change?
gkanwar 2013/06/12 01:27:32 There were previously two settings: --device for i
66 69
67 test_collection = TestInfoCollection() 70 test_collection = TestInfoCollection()
68 all_tests = _GetAllTests(options.python_test_root, options.official_build) 71 all_tests = _GetAllTests(options.python_test_root, options.official_build)
69 test_collection.AddTests(all_tests) 72 test_collection.AddTests(all_tests)
70 test_names = [t.qualified_name for t in all_tests] 73 test_names = [t.qualified_name for t in all_tests]
71 logging.debug('All available tests: ' + str(test_names)) 74 logging.debug('All available tests: ' + str(test_names))
72 75
73 available_tests = test_collection.GetAvailableTests( 76 available_tests = test_collection.GetAvailableTests(
74 options.annotations, options.exclude_annotations, options.test_filter) 77 options.annotations, options.exclude_annotations, options.test_filter)
75 78
76 if not available_tests: 79 if not available_tests:
77 logging.warning('No Python tests to run with current args.') 80 logging.warning('No Python tests to run with current args.')
78 return base_test_result.TestRunResults() 81 return base_test_result.TestRunResults()
79 82
80 test_names = [t.qualified_name for t in available_tests] 83 test_names = [t.qualified_name for t in available_tests]
81 logging.debug('Final list of tests to run: ' + str(test_names)) 84 logging.debug('Final list of tests to run: ' + str(test_names))
82 85
83 # Copy files to each device before running any tests. 86 # Copy files to each device before running any tests.
84 for device_id in attached_devices: 87 for device_id in attached_devices:
85 logging.debug('Pushing files to device %s', device_id) 88 logging.debug('Pushing files to device %s', device_id)
86 test_pkg = test_package.TestPackage(options.test_apk_path, 89 try:
87 options.test_apk_jar_path) 90 test_pkg = instrumentation_test_package.TestPackage(options.test_apk_path,
frankf 2013/06/11 02:50:15 Hmm. Actually let's not touch host_driven tests as
gkanwar 2013/06/12 01:27:32 Done.
88 test_files_copier = test_runner.TestRunner( 91 options.test_apk_jar_path)
89 options, device_id, 0, test_pkg, []) 92 test_files_copier = instrumentation_test_runner.TestRunner(
90 test_files_copier.PushDependencies() 93 options, device_id, 0, test_pkg, [])
94 test_files_copier.PushDependencies()
95 except AttributeError as e:
96 logging.debug('No test APK defined, we are not running '
97 'non-UIAutomator instrumentation tests.')
98 try:
99 test_pkg = uiautomator_test_package.TestPackage(options.test_apk_path,
100 options.test_apk_jar_path)
101 test_files_copier = uiautomator_test_runner.TestRunner(
102 options, device_id, 0, test_pkg, [])
103 test_files_copier.PushDependencies()
104 except AttributeError as e:
105 logging.debug('No test JAR defined, we are not running '
106 'UIAutomator instrumentation tests.')
91 107
92 # Actually run the tests. 108 # Actually run the tests.
93 if len(attached_devices) > 1 and options.wait_for_debugger: 109 if len(attached_devices) > 1 and options.wait_for_debugger:
94 logging.warning('Debugger can not be sharded, ' 110 logging.warning('Debugger can not be sharded, '
95 'using first available device') 111 'using first available device')
96 attached_devices = attached_devices[:1] 112 attached_devices = attached_devices[:1]
97 logging.debug('Running Python tests') 113 logging.debug('Running Python tests')
98 sharder = PythonTestSharder(attached_devices, available_tests, options) 114 sharder = PythonTestSharder(attached_devices, available_tests, options)
99 test_results = sharder.RunShardedTests() 115 test_results = sharder.RunShardedTests()
100 116
101 return test_results 117 return test_results
102 118
103 119
120 def Dispatch(options):
121 """Wraps DispatchPythonTests to log and return the number of failed tests."""
122
123 results = DispatchPythonTests(options)
124 report_results.LogFull(
125 results=results,
126 test_type='HostDriven',
127 test_package=os.path.basename(options.test_apk),
128 annotation=options.annotations,
129 build_type=options.build_type,
130 flakiness_server=options.flakiness_dashboard_server)
131 return len(results.GetNotPass())
132
133
104 def _GetTestModules(python_test_root, is_official_build): 134 def _GetTestModules(python_test_root, is_official_build):
105 """Retrieve a sorted list of pythonDrivenTests. 135 """Retrieve a sorted list of pythonDrivenTests.
106 136
107 Walks the location of pythonDrivenTests, imports them, and provides the list 137 Walks the location of pythonDrivenTests, imports them, and provides the list
108 of imported modules to the caller. 138 of imported modules to the caller.
109 139
110 Args: 140 Args:
111 python_test_root: the path to walk, looking for pythonDrivenTests 141 python_test_root: the path to walk, looking for pythonDrivenTests
112 is_official_build: whether to run only those tests marked 'official' 142 is_official_build: whether to run only those tests marked 'official'
113 143
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 Returns: 228 Returns:
199 List of test case objects for all available test methods. 229 List of test case objects for all available test methods.
200 """ 230 """
201 if not test_root: 231 if not test_root:
202 return [] 232 return []
203 all_tests = [] 233 all_tests = []
204 test_module_list = _GetTestModules(test_root, is_official_build) 234 test_module_list = _GetTestModules(test_root, is_official_build)
205 for module in test_module_list: 235 for module in test_module_list:
206 all_tests.extend(_GetTestClassesFromModule(module)) 236 all_tests.extend(_GetTestClassesFromModule(module))
207 return all_tests 237 return all_tests
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698