| 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 | 13 |
| 14 from pylib import cmd_helper | 14 from pylib import cmd_helper |
| 15 from pylib import constants | 15 from pylib import constants |
| 16 from pylib.device import device_utils | 16 from pylib.device import device_utils |
| 17 from pylib.utils import md5sum |
| 17 from pylib.utils import proguard | 18 from pylib.utils import proguard |
| 18 | 19 |
| 19 sys.path.insert(0, | 20 sys.path.insert(0, |
| 20 os.path.join(constants.DIR_SOURCE_ROOT, | 21 os.path.join(constants.DIR_SOURCE_ROOT, |
| 21 'build', 'util', 'lib', 'common')) | 22 'build', 'util', 'lib', 'common')) |
| 22 | 23 |
| 23 import unittest_util # pylint: disable=F0401 | 24 import unittest_util # pylint: disable=F0401 |
| 24 | 25 |
| 25 # If you change the cached output of proguard, increment this number | 26 # If you change the cached output of proguard, increment this number |
| 26 PICKLE_FORMAT_VERSION = 4 | 27 PICKLE_FORMAT_VERSION = 4 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 48 'tools/proguard/lib/proguard.jar') | 49 'tools/proguard/lib/proguard.jar') |
| 49 if not os.path.exists(self._PROGUARD_PATH): | 50 if not os.path.exists(self._PROGUARD_PATH): |
| 50 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_BUILD_TOP'], | 51 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_BUILD_TOP'], |
| 51 'external/proguard/lib/proguard.jar') | 52 'external/proguard/lib/proguard.jar') |
| 52 self._jar_path = jar_path | 53 self._jar_path = jar_path |
| 53 self._pickled_proguard_name = self._jar_path + '-proguard.pickle' | 54 self._pickled_proguard_name = self._jar_path + '-proguard.pickle' |
| 54 self._test_methods = {} | 55 self._test_methods = {} |
| 55 if not self._GetCachedProguardData(): | 56 if not self._GetCachedProguardData(): |
| 56 self._GetProguardData() | 57 self._GetProguardData() |
| 57 | 58 |
| 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 | |
| 68 def _GetCachedProguardData(self): | 59 def _GetCachedProguardData(self): |
| 69 if (os.path.exists(self._pickled_proguard_name) and | 60 if (os.path.exists(self._pickled_proguard_name) and |
| 70 (os.path.getmtime(self._pickled_proguard_name) > | 61 (os.path.getmtime(self._pickled_proguard_name) > |
| 71 os.path.getmtime(self._jar_path))): | 62 os.path.getmtime(self._jar_path))): |
| 72 logging.info('Loading cached proguard output from %s', | 63 logging.info('Loading cached proguard output from %s', |
| 73 self._pickled_proguard_name) | 64 self._pickled_proguard_name) |
| 74 try: | 65 try: |
| 75 with open(self._pickled_proguard_name, 'r') as r: | 66 with open(self._pickled_proguard_name, 'r') as r: |
| 76 d = pickle.loads(r.read()) | 67 d = pickle.loads(r.read()) |
| 77 jar_md5 = self._CalculateMd5(self._jar_path) | 68 jar_md5 = md5sum.CalculateHostMd5Sums(self._jar_path)[0].hash |
| 78 if (d['JAR_MD5SUM'] == jar_md5 and | 69 if (d['JAR_MD5SUM'] == jar_md5 and |
| 79 d['VERSION'] == PICKLE_FORMAT_VERSION): | 70 d['VERSION'] == PICKLE_FORMAT_VERSION): |
| 80 self._test_methods = d['TEST_METHODS'] | 71 self._test_methods = d['TEST_METHODS'] |
| 81 return True | 72 return True |
| 82 except: | 73 except: |
| 83 logging.warning('PICKLE_FORMAT_VERSION has changed, ignoring cache') | 74 logging.warning('PICKLE_FORMAT_VERSION has changed, ignoring cache') |
| 84 return False | 75 return False |
| 85 | 76 |
| 86 def _GetProguardData(self): | 77 def _GetProguardData(self): |
| 87 logging.info('Retrieving test methods via proguard.') | 78 logging.info('Retrieving test methods via proguard.') |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 for m in test_methods: | 98 for m in test_methods: |
| 108 qualified_method = '%s#%s' % (c['class'], m['method']) | 99 qualified_method = '%s#%s' % (c['class'], m['method']) |
| 109 annotations = dict(class_annotations) | 100 annotations = dict(class_annotations) |
| 110 annotations.update(m['annotations']) | 101 annotations.update(m['annotations']) |
| 111 self._test_methods[qualified_method] = m | 102 self._test_methods[qualified_method] = m |
| 112 self._test_methods[qualified_method]['annotations'] = annotations | 103 self._test_methods[qualified_method]['annotations'] = annotations |
| 113 | 104 |
| 114 logging.info('Storing proguard output to %s', self._pickled_proguard_name) | 105 logging.info('Storing proguard output to %s', self._pickled_proguard_name) |
| 115 d = {'VERSION': PICKLE_FORMAT_VERSION, | 106 d = {'VERSION': PICKLE_FORMAT_VERSION, |
| 116 'TEST_METHODS': self._test_methods, | 107 'TEST_METHODS': self._test_methods, |
| 117 'JAR_MD5SUM': self._CalculateMd5(self._jar_path)} | 108 'JAR_MD5SUM': md5sum.CalculateHostMd5Sums(self._jar_path)[0].hash} |
| 118 with open(self._pickled_proguard_name, 'w') as f: | 109 with open(self._pickled_proguard_name, 'w') as f: |
| 119 f.write(pickle.dumps(d)) | 110 f.write(pickle.dumps(d)) |
| 120 | 111 |
| 121 @staticmethod | 112 @staticmethod |
| 122 def _IsTestMethod(test): | 113 def _IsTestMethod(test): |
| 123 class_name, method = test.split('#') | 114 class_name, method = test.split('#') |
| 124 return class_name.endswith('Test') and method.startswith('test') | 115 return class_name.endswith('Test') and method.startswith('test') |
| 125 | 116 |
| 126 def GetTestAnnotations(self, test): | 117 def GetTestAnnotations(self, test): |
| 127 """Returns a list of all annotations for the given |test|. May be empty.""" | 118 """Returns a list of all annotations for the given |test|. May be empty.""" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 device_utils.DeviceUtils.parallel().GetProp( | 220 device_utils.DeviceUtils.parallel().GetProp( |
| 230 'ro.build.version.sdk').pGet(None)] | 221 'ro.build.version.sdk').pGet(None)] |
| 231 tests = [t for t in tests | 222 tests = [t for t in tests |
| 232 if self._IsTestValidForSdkRange(t, min(sdk_versions))] | 223 if self._IsTestValidForSdkRange(t, min(sdk_versions))] |
| 233 | 224 |
| 234 return tests | 225 return tests |
| 235 | 226 |
| 236 @staticmethod | 227 @staticmethod |
| 237 def IsHostDrivenTest(test): | 228 def IsHostDrivenTest(test): |
| 238 return 'pythonDrivenTests' in test | 229 return 'pythonDrivenTests' in test |
| OLD | NEW |