| 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 collections |    8 import collections | 
|    9 import logging |    9 import logging | 
|   10 import os |   10 import os | 
|   11 import pickle |   11 import pickle | 
|   12 import re |   12 import re | 
 |   13 import sys | 
|   13  |   14  | 
|   14 from pylib import cmd_helper |   15 from pylib import cmd_helper | 
|   15 from pylib import constants |   16 from pylib import constants | 
|   16  |   17  | 
 |   18 sys.path.insert(0, | 
 |   19                 os.path.join(constants.DIR_SOURCE_ROOT, | 
 |   20                              'build', 'util', 'lib', 'common')) | 
 |   21  | 
 |   22 import unittest_util | 
|   17  |   23  | 
|   18 # If you change the cached output of proguard, increment this number |   24 # If you change the cached output of proguard, increment this number | 
|   19 PICKLE_FORMAT_VERSION = 1 |   25 PICKLE_FORMAT_VERSION = 1 | 
|   20  |   26  | 
|   21  |   27  | 
|   22 class TestJar(object): |   28 class TestJar(object): | 
|   23   _ANNOTATIONS = frozenset( |   29   _ANNOTATIONS = frozenset( | 
|   24       ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', |   30       ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', | 
|   25        'FlakyTest', 'DisabledTest', 'Manual', 'PerfTest', 'HostDrivenTest']) |   31        'FlakyTest', 'DisabledTest', 'Manual', 'PerfTest', 'HostDrivenTest']) | 
|   26   _DEFAULT_ANNOTATION = 'SmallTest' |   32   _DEFAULT_ANNOTATION = 'SmallTest' | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  170     """Get a list of test methods with no known annotations.""" |  176     """Get a list of test methods with no known annotations.""" | 
|  171     tests_missing_annotations = [] |  177     tests_missing_annotations = [] | 
|  172     for test_method in self.GetTestMethods(): |  178     for test_method in self.GetTestMethods(): | 
|  173       annotations_ = frozenset(self.GetTestAnnotations(test_method)) |  179       annotations_ = frozenset(self.GetTestAnnotations(test_method)) | 
|  174       if (annotations_.isdisjoint(self._ANNOTATIONS) and |  180       if (annotations_.isdisjoint(self._ANNOTATIONS) and | 
|  175           not self.IsHostDrivenTest(test_method)): |  181           not self.IsHostDrivenTest(test_method)): | 
|  176         tests_missing_annotations.append(test_method) |  182         tests_missing_annotations.append(test_method) | 
|  177     return sorted(tests_missing_annotations) |  183     return sorted(tests_missing_annotations) | 
|  178  |  184  | 
|  179   def GetAllMatchingTests(self, annotation_filter_list, |  185   def GetAllMatchingTests(self, annotation_filter_list, | 
|  180                            exclude_annotation_list, test_filter): |  186                           exclude_annotation_list, test_filter): | 
|  181     """Get a list of tests matching any of the annotations and the filter. |  187     """Get a list of tests matching any of the annotations and the filter. | 
|  182  |  188  | 
|  183     Args: |  189     Args: | 
|  184       annotation_filter_list: List of test annotations. A test must have at |  190       annotation_filter_list: List of test annotations. A test must have at | 
|  185         least one of these annotations. A test without any annotations is |  191         least one of these annotations. A test without any annotations is | 
|  186         considered to be SmallTest. |  192         considered to be SmallTest. | 
|  187       exclude_annotation_list: List of test annotations. A test must not have |  193       exclude_annotation_list: List of test annotations. A test must not have | 
|  188         any of these annotations. |  194         any of these annotations. | 
|  189       test_filter: Filter used for partial matching on the test method names. |  195       test_filter: Filter used for partial matching on the test method names. | 
|  190  |  196  | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  203       if exclude_annotation_list: |  209       if exclude_annotation_list: | 
|  204         excluded_tests = self.GetAnnotatedTests(exclude_annotation_list) |  210         excluded_tests = self.GetAnnotatedTests(exclude_annotation_list) | 
|  205         available_tests = list(set(available_tests) - set(excluded_tests)) |  211         available_tests = list(set(available_tests) - set(excluded_tests)) | 
|  206     else: |  212     else: | 
|  207       available_tests = [m for m in self.GetTestMethods() |  213       available_tests = [m for m in self.GetTestMethods() | 
|  208                          if not self.IsHostDrivenTest(m)] |  214                          if not self.IsHostDrivenTest(m)] | 
|  209  |  215  | 
|  210     tests = [] |  216     tests = [] | 
|  211     if test_filter: |  217     if test_filter: | 
|  212       # |available_tests| are in adb instrument format: package.path.class#test. |  218       # |available_tests| are in adb instrument format: package.path.class#test. | 
|  213       filter_without_hash = test_filter.replace('#', '.') |  219  | 
|  214       tests = [t for t in available_tests |  220       # Maps a 'class.test' name to each 'package.path.class#test' name. | 
|  215                if filter_without_hash in t.replace('#', '.')] |  221       sanitized_test_names = dict([ | 
 |  222           (t.split('.')[-1].replace('#', '.'), t) for t in available_tests]) | 
 |  223       # Filters 'class.test' names and populates |tests| with the corresponding | 
 |  224       # 'package.path.class#test' names. | 
 |  225       tests = [ | 
 |  226           sanitized_test_names[t] for t in unittest_util.FilterTestNames( | 
 |  227               sanitized_test_names.keys(), test_filter.replace('#', '.'))] | 
|  216     else: |  228     else: | 
|  217       tests = available_tests |  229       tests = available_tests | 
|  218  |  230  | 
|  219     return tests |  231     return tests | 
|  220  |  232  | 
|  221   @staticmethod |  233   @staticmethod | 
|  222   def IsHostDrivenTest(test): |  234   def IsHostDrivenTest(test): | 
|  223     return 'pythonDrivenTests' in test |  235     return 'pythonDrivenTests' in test | 
| OLD | NEW |