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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 _PROGUARD_ANNOTATION_RE = re.compile(r'\s*?- Annotation \[L(\S*);\]:$') | 35 _PROGUARD_ANNOTATION_RE = re.compile(r'\s*?- Annotation \[L(\S*);\]:$') |
36 _PROGUARD_ANNOTATION_CONST_RE = ( | 36 _PROGUARD_ANNOTATION_CONST_RE = ( |
37 re.compile(r'\s*?- Constant element value.*$')) | 37 re.compile(r'\s*?- Constant element value.*$')) |
38 _PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'\s*?- \S+? \[(.*)\]$') | 38 _PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'\s*?- \S+? \[(.*)\]$') |
39 | 39 |
40 def __init__(self, jar_path): | 40 def __init__(self, jar_path): |
41 if not os.path.exists(jar_path): | 41 if not os.path.exists(jar_path): |
42 raise Exception('%s not found, please build it' % jar_path) | 42 raise Exception('%s not found, please build it' % jar_path) |
43 | 43 |
44 self._PROGUARD_PATH = os.path.join(constants.ANDROID_SDK_ROOT, | 44 self._PROGUARD_PATH = os.path.join(constants.ANDROID_SDK_ROOT, |
45 'tools/proguard/bin/proguard.sh') | 45 'tools/proguard/lib/proguard.jar') |
46 if not os.path.exists(self._PROGUARD_PATH): | 46 if not os.path.exists(self._PROGUARD_PATH): |
47 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_BUILD_TOP'], | 47 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_BUILD_TOP'], |
48 'external/proguard/bin/proguard.sh') | 48 'external/proguard/lib/proguard.jar') |
49 self._jar_path = jar_path | 49 self._jar_path = jar_path |
50 self._annotation_map = collections.defaultdict(list) | 50 self._annotation_map = collections.defaultdict(list) |
51 self._pickled_proguard_name = self._jar_path + '-proguard.pickle' | 51 self._pickled_proguard_name = self._jar_path + '-proguard.pickle' |
52 self._test_methods = [] | 52 self._test_methods = [] |
53 if not self._GetCachedProguardData(): | 53 if not self._GetCachedProguardData(): |
54 self._GetProguardData() | 54 self._GetProguardData() |
55 | 55 |
56 def _GetCachedProguardData(self): | 56 def _GetCachedProguardData(self): |
57 if (os.path.exists(self._pickled_proguard_name) and | 57 if (os.path.exists(self._pickled_proguard_name) and |
58 (os.path.getmtime(self._pickled_proguard_name) > | 58 (os.path.getmtime(self._pickled_proguard_name) > |
59 os.path.getmtime(self._jar_path))): | 59 os.path.getmtime(self._jar_path))): |
60 logging.info('Loading cached proguard output from %s', | 60 logging.info('Loading cached proguard output from %s', |
61 self._pickled_proguard_name) | 61 self._pickled_proguard_name) |
62 try: | 62 try: |
63 with open(self._pickled_proguard_name, 'r') as r: | 63 with open(self._pickled_proguard_name, 'r') as r: |
64 d = pickle.loads(r.read()) | 64 d = pickle.loads(r.read()) |
65 if d['VERSION'] == PICKLE_FORMAT_VERSION: | 65 if d['VERSION'] == PICKLE_FORMAT_VERSION: |
66 self._annotation_map = d['ANNOTATION_MAP'] | 66 self._annotation_map = d['ANNOTATION_MAP'] |
67 self._test_methods = d['TEST_METHODS'] | 67 self._test_methods = d['TEST_METHODS'] |
68 return True | 68 return True |
69 except: | 69 except: |
70 logging.warning('PICKLE_FORMAT_VERSION has changed, ignoring cache') | 70 logging.warning('PICKLE_FORMAT_VERSION has changed, ignoring cache') |
71 return False | 71 return False |
72 | 72 |
73 def _GetProguardData(self): | 73 def _GetProguardData(self): |
74 proguard_output = cmd_helper.GetCmdOutput([self._PROGUARD_PATH, | 74 proguard_output = cmd_helper.GetCmdOutput(['java', '-jar', |
| 75 self._PROGUARD_PATH, |
75 '-injars', self._jar_path, | 76 '-injars', self._jar_path, |
76 '-dontshrink', | 77 '-dontshrink', |
77 '-dontoptimize', | 78 '-dontoptimize', |
78 '-dontobfuscate', | 79 '-dontobfuscate', |
79 '-dontpreverify', | 80 '-dontpreverify', |
80 '-dump', | 81 '-dump', |
81 ]).split('\n') | 82 ]).split('\n') |
82 clazz = None | 83 clazz = None |
83 method = None | 84 method = None |
84 annotation = None | 85 annotation = None |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 sanitized_test_names[t] for t in unittest_util.FilterTestNames( | 226 sanitized_test_names[t] for t in unittest_util.FilterTestNames( |
226 sanitized_test_names.keys(), test_filter.replace('#', '.'))] | 227 sanitized_test_names.keys(), test_filter.replace('#', '.'))] |
227 else: | 228 else: |
228 tests = available_tests | 229 tests = available_tests |
229 | 230 |
230 return tests | 231 return tests |
231 | 232 |
232 @staticmethod | 233 @staticmethod |
233 def IsHostDrivenTest(test): | 234 def IsHostDrivenTest(test): |
234 return 'pythonDrivenTests' in test | 235 return 'pythonDrivenTests' in test |
OLD | NEW |