OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import logging | 5 import logging |
6 import os | 6 import os |
7 import pickle | 7 import pickle |
8 import re | 8 import re |
9 import sys | 9 import sys |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common')) | 23 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common')) |
24 import unittest_util | 24 import unittest_util |
25 | 25 |
26 # Ref: http://developer.android.com/reference/android/app/Activity.html | 26 # Ref: http://developer.android.com/reference/android/app/Activity.html |
27 _ACTIVITY_RESULT_CANCELED = 0 | 27 _ACTIVITY_RESULT_CANCELED = 0 |
28 _ACTIVITY_RESULT_OK = -1 | 28 _ACTIVITY_RESULT_OK = -1 |
29 | 29 |
30 _DEFAULT_ANNOTATIONS = [ | 30 _DEFAULT_ANNOTATIONS = [ |
31 'Smoke', 'SmallTest', 'MediumTest', 'LargeTest', | 31 'Smoke', 'SmallTest', 'MediumTest', 'LargeTest', |
32 'EnormousTest', 'IntegrationTest'] | 32 'EnormousTest', 'IntegrationTest'] |
| 33 _EXTRA_ENABLE_HTTP_SERVER = ( |
| 34 'org.chromium.chrome.test.ChromeInstrumentationTestRunner.' |
| 35 + 'EnableTestHttpServer') |
| 36 _EXTRA_OUTSTRUMENTATION_TEST_LIST = ( |
| 37 'org.chromium.test.outstrumentation.master.Outstrumentation.TestList') |
| 38 _EXTRA_OUTSTRUMENTATION_TEST_LIST_FILE = ( |
| 39 'org.chromium.test.outstrumentation.master.Outstrumentation.TestListFile') |
| 40 _EXTRA_OUTSTRUMENTATION_TARGET_PACKAGE = ( |
| 41 'org.chromium.test.outstrumentation.master.Outstrumentation.TargetPackage') |
| 42 _EXTRA_OUTSTRUMENTATION_TARGET_CLASS = ( |
| 43 'org.chromium.test.outstrumentation.master.Outstrumentation.TargetClass') |
33 _NATIVE_CRASH_RE = re.compile('native crash', re.IGNORECASE) | 44 _NATIVE_CRASH_RE = re.compile('native crash', re.IGNORECASE) |
34 _PICKLE_FORMAT_VERSION = 10 | 45 _PICKLE_FORMAT_VERSION = 10 |
35 | 46 |
36 | 47 |
37 # TODO(jbudorick): Make these private class methods of | 48 # TODO(jbudorick): Make these private class methods of |
38 # InstrumentationTestInstance once the instrumentation test_runner is | 49 # InstrumentationTestInstance once the instrumentation test_runner is |
39 # deprecated. | 50 # deprecated. |
40 def ParseAmInstrumentRawOutput(raw_output): | 51 def ParseAmInstrumentRawOutput(raw_output): |
41 """Parses the output of an |am instrument -r| call. | 52 """Parses the output of an |am instrument -r| call. |
42 | 53 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return results | 134 return results |
124 | 135 |
125 | 136 |
126 class InstrumentationTestInstance(test_instance.TestInstance): | 137 class InstrumentationTestInstance(test_instance.TestInstance): |
127 | 138 |
128 def __init__(self, args, isolate_delegate, error_func): | 139 def __init__(self, args, isolate_delegate, error_func): |
129 super(InstrumentationTestInstance, self).__init__() | 140 super(InstrumentationTestInstance, self).__init__() |
130 | 141 |
131 self._apk_under_test = None | 142 self._apk_under_test = None |
132 self._package_info = None | 143 self._package_info = None |
| 144 self._suite = None |
133 self._test_apk = None | 145 self._test_apk = None |
134 self._test_jar = None | 146 self._test_jar = None |
135 self._test_package = None | 147 self._test_package = None |
136 self._test_runner = None | 148 self._test_runner = None |
137 self._test_support_apk = None | 149 self._test_support_apk = None |
138 self.__initializeApkAttributes(args, error_func) | 150 self.__initializeApkAttributes(args, error_func) |
139 | 151 |
140 self._data_deps = None | 152 self._data_deps = None |
141 self._isolate_abs_path = None | 153 self._isolate_abs_path = None |
142 self._isolate_delegate = None | 154 self._isolate_delegate = None |
(...skipping 14 matching lines...) Expand all Loading... |
157 self._apk_under_test = args.apk_under_test | 169 self._apk_under_test = args.apk_under_test |
158 else: | 170 else: |
159 self._apk_under_test = os.path.join( | 171 self._apk_under_test = os.path.join( |
160 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, | 172 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, |
161 '%s.apk' % args.apk_under_test) | 173 '%s.apk' % args.apk_under_test) |
162 | 174 |
163 if not os.path.exists(self._apk_under_test): | 175 if not os.path.exists(self._apk_under_test): |
164 error_func('Unable to find APK under test: %s' % self._apk_under_test) | 176 error_func('Unable to find APK under test: %s' % self._apk_under_test) |
165 | 177 |
166 if args.test_apk.endswith('.apk'): | 178 if args.test_apk.endswith('.apk'): |
167 test_apk_root = os.path.splitext(os.path.basename(args.test_apk))[0] | 179 self._suite = os.path.splitext(os.path.basename(args.test_apk))[0] |
168 self._test_apk = args.test_apk | 180 self._test_apk = args.test_apk |
169 else: | 181 else: |
170 test_apk_root = args.test_apk | 182 self._suite = args.test_apk |
171 self._test_apk = os.path.join( | 183 self._test_apk = os.path.join( |
172 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, | 184 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, |
173 '%s.apk' % args.test_apk) | 185 '%s.apk' % args.test_apk) |
174 | 186 |
175 self._test_jar = os.path.join( | 187 self._test_jar = os.path.join( |
176 constants.GetOutDirectory(), constants.SDK_BUILD_TEST_JAVALIB_DIR, | 188 constants.GetOutDirectory(), constants.SDK_BUILD_TEST_JAVALIB_DIR, |
177 '%s.jar' % test_apk_root) | 189 '%s.jar' % self._suite) |
178 self._test_support_apk = os.path.join( | 190 self._test_support_apk = os.path.join( |
179 constants.GetOutDirectory(), constants.SDK_BUILD_TEST_JAVALIB_DIR, | 191 constants.GetOutDirectory(), constants.SDK_BUILD_TEST_JAVALIB_DIR, |
180 '%sSupport.apk' % test_apk_root) | 192 '%sSupport.apk' % self._suite) |
181 | 193 |
182 if not os.path.exists(self._test_apk): | 194 if not os.path.exists(self._test_apk): |
183 error_func('Unable to find test APK: %s' % self._test_apk) | 195 error_func('Unable to find test APK: %s' % self._test_apk) |
184 if not os.path.exists(self._test_jar): | 196 if not os.path.exists(self._test_jar): |
185 error_func('Unable to find test JAR: %s' % self._test_jar) | 197 error_func('Unable to find test JAR: %s' % self._test_jar) |
186 | 198 |
187 self._test_package = apk_helper.GetPackageName(self.test_apk) | 199 self._test_package = apk_helper.GetPackageName(self.test_apk) |
188 self._test_runner = apk_helper.GetInstrumentationName(self.test_apk) | 200 self._test_runner = apk_helper.GetInstrumentationName(self.test_apk) |
189 | 201 |
190 self._package_info = None | 202 self._package_info = None |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 with open(args.device_flags) as device_flags_file: | 259 with open(args.device_flags) as device_flags_file: |
248 stripped_lines = (l.strip() for l in device_flags_file) | 260 stripped_lines = (l.strip() for l in device_flags_file) |
249 self._flags.extend([flag for flag in stripped_lines if flag]) | 261 self._flags.extend([flag for flag in stripped_lines if flag]) |
250 if hasattr(args, 'device_flags_file') and args.device_flags_file: | 262 if hasattr(args, 'device_flags_file') and args.device_flags_file: |
251 with open(args.device_flags_file) as device_flags_file: | 263 with open(args.device_flags_file) as device_flags_file: |
252 stripped_lines = (l.strip() for l in device_flags_file) | 264 stripped_lines = (l.strip() for l in device_flags_file) |
253 self._flags.extend([flag for flag in stripped_lines if flag]) | 265 self._flags.extend([flag for flag in stripped_lines if flag]) |
254 | 266 |
255 @property | 267 @property |
256 def suite(self): | 268 def suite(self): |
257 return 'instrumentation' | 269 return self._suite |
258 | 270 |
259 @property | 271 @property |
260 def apk_under_test(self): | 272 def apk_under_test(self): |
261 return self._apk_under_test | 273 return self._apk_under_test |
262 | 274 |
263 @property | 275 @property |
264 def flags(self): | 276 def flags(self): |
265 return self._flags | 277 return self._flags |
266 | 278 |
267 @property | 279 @property |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 a = dict(c['annotations']) | 451 a = dict(c['annotations']) |
440 a.update(m['annotations']) | 452 a.update(m['annotations']) |
441 inflated_tests.append({ | 453 inflated_tests.append({ |
442 'class': c['class'], | 454 'class': c['class'], |
443 'method': m['method'], | 455 'method': m['method'], |
444 'annotations': a, | 456 'annotations': a, |
445 }) | 457 }) |
446 return inflated_tests | 458 return inflated_tests |
447 | 459 |
448 @staticmethod | 460 @staticmethod |
| 461 def GetHttpServerEnvironmentVars(): |
| 462 return { |
| 463 _EXTRA_ENABLE_HTTP_SERVER: None, |
| 464 } |
| 465 |
| 466 def GetOutstrumentationEnvironmentVars( |
| 467 self, test_list=None, test_list_file_path=None): |
| 468 env = { |
| 469 _EXTRA_OUTSTRUMENTATION_TARGET_PACKAGE: self.test_package, |
| 470 _EXTRA_OUTSTRUMENTATION_TARGET_CLASS: self.test_runner, |
| 471 } |
| 472 |
| 473 if test_list: |
| 474 env[_EXTRA_OUTSTRUMENTATION_TEST_LIST] = ','.join(test_list) |
| 475 |
| 476 if test_list_file_path: |
| 477 env[_EXTRA_OUTSTRUMENTATION_TEST_LIST_FILE] = ( |
| 478 os.path.basename(test_list_file_path)) |
| 479 |
| 480 return env |
| 481 |
| 482 @staticmethod |
449 def ParseAmInstrumentRawOutput(raw_output): | 483 def ParseAmInstrumentRawOutput(raw_output): |
450 return ParseAmInstrumentRawOutput(raw_output) | 484 return ParseAmInstrumentRawOutput(raw_output) |
451 | 485 |
452 @staticmethod | 486 @staticmethod |
453 def GenerateTestResults( | 487 def GenerateTestResults( |
454 result_code, result_bundle, statuses, start_ms, duration_ms): | 488 result_code, result_bundle, statuses, start_ms, duration_ms): |
455 return GenerateTestResults(result_code, result_bundle, statuses, | 489 return GenerateTestResults(result_code, result_bundle, statuses, |
456 start_ms, duration_ms) | 490 start_ms, duration_ms) |
457 | 491 |
458 #override | 492 #override |
459 def TearDown(self): | 493 def TearDown(self): |
460 if self._isolate_delegate: | 494 if self._isolate_delegate: |
461 self._isolate_delegate.Clear() | 495 self._isolate_delegate.Clear() |
462 | 496 |
OLD | NEW |