| 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 |
| 11 import re | 11 import re |
| 12 import sys | 12 import sys |
| 13 import tempfile | 13 import tempfile |
| 14 | 14 |
| 15 from pylib import cmd_helper | 15 from pylib import cmd_helper |
| 16 from pylib import constants | 16 from pylib import constants |
| 17 from pylib.device import device_utils | 17 from pylib.device import device_utils |
| 18 | 18 |
| 19 sys.path.insert(0, | 19 sys.path.insert(0, |
| 20 os.path.join(constants.DIR_SOURCE_ROOT, | 20 os.path.join(constants.DIR_SOURCE_ROOT, |
| 21 'build', 'util', 'lib', 'common')) | 21 'build', 'util', 'lib', 'common')) |
| 22 | 22 |
| 23 import unittest_util # pylint: disable=F0401 | 23 import unittest_util # pylint: disable=F0401 |
| 24 | 24 |
| 25 # If you change the cached output of proguard, increment this number | 25 # If you change the cached output of proguard, increment this number |
| 26 PICKLE_FORMAT_VERSION = 2 | 26 PICKLE_FORMAT_VERSION = 3 |
| 27 | 27 |
| 28 | 28 |
| 29 class TestJar(object): | 29 class TestJar(object): |
| 30 _ANNOTATIONS = frozenset( | 30 _ANNOTATIONS = frozenset( |
| 31 ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', | 31 ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', |
| 32 'FlakyTest', 'DisabledTest', 'Manual', 'PerfTest', 'HostDrivenTest', | 32 'FlakyTest', 'DisabledTest', 'Manual', 'PerfTest', 'HostDrivenTest', |
| 33 'IntegrationTest']) | 33 'IntegrationTest']) |
| 34 _DEFAULT_ANNOTATION = 'SmallTest' | 34 _DEFAULT_ANNOTATION = 'SmallTest' |
| 35 _PROGUARD_CLASS_RE = re.compile(r'\s*?- Program class:\s*([\S]+)$') | 35 _PROGUARD_CLASS_RE = re.compile(r'\s*?- Program class:\s*([\S]+)$') |
| 36 _PROGUARD_SUPERCLASS_RE = re.compile(r'\s*? Superclass:\s*([\S]+)$') | 36 _PROGUARD_SUPERCLASS_RE = re.compile(r'\s*? Superclass:\s*([\S]+)$') |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 'tools/proguard/lib/proguard.jar') | 48 'tools/proguard/lib/proguard.jar') |
| 49 if not os.path.exists(self._PROGUARD_PATH): | 49 if not os.path.exists(self._PROGUARD_PATH): |
| 50 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_BUILD_TOP'], | 50 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_BUILD_TOP'], |
| 51 'external/proguard/lib/proguard.jar') | 51 'external/proguard/lib/proguard.jar') |
| 52 self._jar_path = jar_path | 52 self._jar_path = jar_path |
| 53 self._pickled_proguard_name = self._jar_path + '-proguard.pickle' | 53 self._pickled_proguard_name = self._jar_path + '-proguard.pickle' |
| 54 self._test_methods = {} | 54 self._test_methods = {} |
| 55 if not self._GetCachedProguardData(): | 55 if not self._GetCachedProguardData(): |
| 56 self._GetProguardData() | 56 self._GetProguardData() |
| 57 | 57 |
| 58 @staticmethod |
| 59 def _CalculateMd5(path): |
| 60 # TODO(jbudorick): Move MD5sum calculations out of here and |
| 61 # AndroidCommands to their own module. |
| 62 out = cmd_helper.GetCmdOutput( |
| 63 [os.path.join(constants.GetOutDirectory(), |
| 64 'md5sum_bin_host'), |
| 65 path]) |
| 66 return out |
| 67 |
| 58 def _GetCachedProguardData(self): | 68 def _GetCachedProguardData(self): |
| 59 if (os.path.exists(self._pickled_proguard_name) and | 69 if (os.path.exists(self._pickled_proguard_name) and |
| 60 (os.path.getmtime(self._pickled_proguard_name) > | 70 (os.path.getmtime(self._pickled_proguard_name) > |
| 61 os.path.getmtime(self._jar_path))): | 71 os.path.getmtime(self._jar_path))): |
| 62 logging.info('Loading cached proguard output from %s', | 72 logging.info('Loading cached proguard output from %s', |
| 63 self._pickled_proguard_name) | 73 self._pickled_proguard_name) |
| 64 try: | 74 try: |
| 65 with open(self._pickled_proguard_name, 'r') as r: | 75 with open(self._pickled_proguard_name, 'r') as r: |
| 66 d = pickle.loads(r.read()) | 76 d = pickle.loads(r.read()) |
| 67 if d['VERSION'] == PICKLE_FORMAT_VERSION: | 77 jar_md5 = self._CalculateMd5(self._jar_path) |
| 78 if (d['JAR_MD5SUM'] == jar_md5 and |
| 79 d['VERSION'] == PICKLE_FORMAT_VERSION): |
| 68 self._test_methods = d['TEST_METHODS'] | 80 self._test_methods = d['TEST_METHODS'] |
| 69 return True | 81 return True |
| 70 except: | 82 except: |
| 71 logging.warning('PICKLE_FORMAT_VERSION has changed, ignoring cache') | 83 logging.warning('PICKLE_FORMAT_VERSION has changed, ignoring cache') |
| 72 return False | 84 return False |
| 73 | 85 |
| 74 def _GetProguardData(self): | 86 def _GetProguardData(self): |
| 75 logging.info('Retrieving test methods via proguard.') | 87 logging.info('Retrieving test methods via proguard.') |
| 76 | 88 |
| 77 with tempfile.NamedTemporaryFile() as proguard_output: | 89 with tempfile.NamedTemporaryFile() as proguard_output: |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 annotation_name + ':' + annotation_value) | 187 annotation_name + ':' + annotation_value) |
| 176 self._test_methods[qualified_method] = { | 188 self._test_methods[qualified_method] = { |
| 177 'annotations': method_annotations | 189 'annotations': method_annotations |
| 178 } | 190 } |
| 179 if min_sdk_level is not None: | 191 if min_sdk_level is not None: |
| 180 self._test_methods[qualified_method]['min_sdk_level'] = ( | 192 self._test_methods[qualified_method]['min_sdk_level'] = ( |
| 181 int(min_sdk_level)) | 193 int(min_sdk_level)) |
| 182 | 194 |
| 183 logging.info('Storing proguard output to %s', self._pickled_proguard_name) | 195 logging.info('Storing proguard output to %s', self._pickled_proguard_name) |
| 184 d = {'VERSION': PICKLE_FORMAT_VERSION, | 196 d = {'VERSION': PICKLE_FORMAT_VERSION, |
| 185 'TEST_METHODS': self._test_methods} | 197 'TEST_METHODS': self._test_methods, |
| 198 'JAR_MD5SUM': self._CalculateMd5(self._jar_path)} |
| 186 with open(self._pickled_proguard_name, 'w') as f: | 199 with open(self._pickled_proguard_name, 'w') as f: |
| 187 f.write(pickle.dumps(d)) | 200 f.write(pickle.dumps(d)) |
| 188 | 201 |
| 189 | 202 |
| 190 @staticmethod | 203 @staticmethod |
| 191 def _IsTestMethod(test): | 204 def _IsTestMethod(test): |
| 192 class_name, method = test.split('#') | 205 class_name, method = test.split('#') |
| 193 return class_name.endswith('Test') and method.startswith('test') | 206 return class_name.endswith('Test') and method.startswith('test') |
| 194 | 207 |
| 195 def GetTestAnnotations(self, test): | 208 def GetTestAnnotations(self, test): |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 'ro.build.version.sdk').pGet(None)] | 312 'ro.build.version.sdk').pGet(None)] |
| 300 tests = filter( | 313 tests = filter( |
| 301 lambda t: self._IsTestValidForSdkRange(t, min(sdk_versions)), | 314 lambda t: self._IsTestValidForSdkRange(t, min(sdk_versions)), |
| 302 tests) | 315 tests) |
| 303 | 316 |
| 304 return tests | 317 return tests |
| 305 | 318 |
| 306 @staticmethod | 319 @staticmethod |
| 307 def IsHostDrivenTest(test): | 320 def IsHostDrivenTest(test): |
| 308 return 'pythonDrivenTests' in test | 321 return 'pythonDrivenTests' in test |
| OLD | NEW |