OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 """Helper class for instrumenation test jar.""" | 5 """Helper class for instrumenation test jar.""" |
6 # pylint: disable=W0702 | 6 # pylint: disable=W0702 |
7 | 7 |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import pickle | 10 import pickle |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 tests_missing_annotations.append(test_method) | 163 tests_missing_annotations.append(test_method) |
164 return sorted(tests_missing_annotations) | 164 return sorted(tests_missing_annotations) |
165 | 165 |
166 def _IsTestValidForSdkRange(self, test_name, attached_min_sdk_level): | 166 def _IsTestValidForSdkRange(self, test_name, attached_min_sdk_level): |
167 required_min_sdk_level = int( | 167 required_min_sdk_level = int( |
168 self.GetTestAnnotations(test_name).get('MinAndroidSdkLevel', 0)) | 168 self.GetTestAnnotations(test_name).get('MinAndroidSdkLevel', 0)) |
169 return (required_min_sdk_level is None or | 169 return (required_min_sdk_level is None or |
170 attached_min_sdk_level >= required_min_sdk_level) | 170 attached_min_sdk_level >= required_min_sdk_level) |
171 | 171 |
172 def GetAllMatchingTests(self, annotation_filter_list, | 172 def GetAllMatchingTests(self, annotation_filter_list, |
173 exclude_annotation_list, test_filter): | 173 exclude_annotation_list, test_filter, devices): |
174 """Get a list of tests matching any of the annotations and the filter. | 174 """Get a list of tests matching any of the annotations and the filter. |
175 | 175 |
176 Args: | 176 Args: |
177 annotation_filter_list: List of test annotations. A test must have at | 177 annotation_filter_list: List of test annotations. A test must have at |
178 least one of these annotations. A test without any annotations is | 178 least one of these annotations. A test without any annotations is |
179 considered to be SmallTest. | 179 considered to be SmallTest. |
180 exclude_annotation_list: List of test annotations. A test must not have | 180 exclude_annotation_list: List of test annotations. A test must not have |
181 any of these annotations. | 181 any of these annotations. |
182 test_filter: Filter used for partial matching on the test method names. | 182 test_filter: Filter used for partial matching on the test method names. |
| 183 devices: The set of devices against which tests will be run. |
183 | 184 |
184 Returns: | 185 Returns: |
185 List of all matching tests. | 186 List of all matching tests. |
186 """ | 187 """ |
187 if annotation_filter_list: | 188 if annotation_filter_list: |
188 available_tests = self.GetAnnotatedTests(annotation_filter_list) | 189 available_tests = self.GetAnnotatedTests(annotation_filter_list) |
189 # Include un-annotated tests in SmallTest. | 190 # Include un-annotated tests in SmallTest. |
190 if annotation_filter_list.count(self._DEFAULT_ANNOTATION) > 0: | 191 if annotation_filter_list.count(self._DEFAULT_ANNOTATION) > 0: |
191 for test in self._GetTestsMissingAnnotation(): | 192 for test in self._GetTestsMissingAnnotation(): |
192 logging.warning( | 193 logging.warning( |
(...skipping 18 matching lines...) Expand all Loading... |
211 # Filters 'class.test' names and populates |tests| with the corresponding | 212 # Filters 'class.test' names and populates |tests| with the corresponding |
212 # 'package.path.class#test' names. | 213 # 'package.path.class#test' names. |
213 tests = [ | 214 tests = [ |
214 sanitized_test_names[t] for t in unittest_util.FilterTestNames( | 215 sanitized_test_names[t] for t in unittest_util.FilterTestNames( |
215 sanitized_test_names.keys(), test_filter.replace('#', '.'))] | 216 sanitized_test_names.keys(), test_filter.replace('#', '.'))] |
216 else: | 217 else: |
217 tests = available_tests | 218 tests = available_tests |
218 | 219 |
219 # Filter out any tests with SDK level requirements that don't match the set | 220 # Filter out any tests with SDK level requirements that don't match the set |
220 # of attached devices. | 221 # of attached devices. |
221 devices = device_utils.DeviceUtils.parallel() | 222 devices = device_utils.DeviceUtils.parallel(devices) |
222 min_sdk_version = min(devices.build_version_sdk.pGet(None)) | 223 min_sdk_version = min(devices.build_version_sdk.pGet(None)) |
223 tests = [t for t in tests | 224 tests = [t for t in tests |
224 if self._IsTestValidForSdkRange(t, min_sdk_version)] | 225 if self._IsTestValidForSdkRange(t, min_sdk_version)] |
225 | 226 |
226 return tests | 227 return tests |
227 | 228 |
228 @staticmethod | 229 @staticmethod |
229 def IsHostDrivenTest(test): | 230 def IsHostDrivenTest(test): |
230 return 'pythonDrivenTests' in test | 231 return 'pythonDrivenTests' in test |
OLD | NEW |