| 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_DRIVER_TEST_LIST = ( | |
| 37 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') | |
| 38 _EXTRA_DRIVER_TEST_LIST_FILE = ( | |
| 39 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') | |
| 40 _EXTRA_DRIVER_TARGET_PACKAGE = ( | |
| 41 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') | |
| 42 _EXTRA_DRIVER_TARGET_CLASS = ( | |
| 43 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') | |
| 44 _NATIVE_CRASH_RE = re.compile('native crash', re.IGNORECASE) | 33 _NATIVE_CRASH_RE = re.compile('native crash', re.IGNORECASE) |
| 45 _PICKLE_FORMAT_VERSION = 10 | 34 _PICKLE_FORMAT_VERSION = 10 |
| 46 | 35 |
| 47 | 36 |
| 48 # TODO(jbudorick): Make these private class methods of | 37 # TODO(jbudorick): Make these private class methods of |
| 49 # InstrumentationTestInstance once the instrumentation test_runner is | 38 # InstrumentationTestInstance once the instrumentation test_runner is |
| 50 # deprecated. | 39 # deprecated. |
| 51 def ParseAmInstrumentRawOutput(raw_output): | 40 def ParseAmInstrumentRawOutput(raw_output): |
| 52 """Parses the output of an |am instrument -r| call. | 41 """Parses the output of an |am instrument -r| call. |
| 53 | 42 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return results | 123 return results |
| 135 | 124 |
| 136 | 125 |
| 137 class InstrumentationTestInstance(test_instance.TestInstance): | 126 class InstrumentationTestInstance(test_instance.TestInstance): |
| 138 | 127 |
| 139 def __init__(self, args, isolate_delegate, error_func): | 128 def __init__(self, args, isolate_delegate, error_func): |
| 140 super(InstrumentationTestInstance, self).__init__() | 129 super(InstrumentationTestInstance, self).__init__() |
| 141 | 130 |
| 142 self._apk_under_test = None | 131 self._apk_under_test = None |
| 143 self._package_info = None | 132 self._package_info = None |
| 144 self._suite = None | |
| 145 self._test_apk = None | 133 self._test_apk = None |
| 146 self._test_jar = None | 134 self._test_jar = None |
| 147 self._test_package = None | 135 self._test_package = None |
| 148 self._test_runner = None | 136 self._test_runner = None |
| 149 self._test_support_apk = None | 137 self._test_support_apk = None |
| 150 self._initializeApkAttributes(args, error_func) | 138 self.__initializeApkAttributes(args, error_func) |
| 151 | 139 |
| 152 self._data_deps = None | 140 self._data_deps = None |
| 153 self._isolate_abs_path = None | 141 self._isolate_abs_path = None |
| 154 self._isolate_delegate = None | 142 self._isolate_delegate = None |
| 155 self._isolated_abs_path = None | 143 self._isolated_abs_path = None |
| 156 self._test_data = None | 144 self._test_data = None |
| 157 self._initializeDataDependencyAttributes(args, isolate_delegate) | 145 self.__initializeDataDependencyAttributes(args, isolate_delegate) |
| 158 | 146 |
| 159 self._annotations = None | 147 self._annotations = None |
| 160 self._excluded_annotations = None | 148 self._excluded_annotations = None |
| 161 self._test_filter = None | 149 self._test_filter = None |
| 162 self._initializeTestFilterAttributes(args) | 150 self.__initializeTestFilterAttributes(args) |
| 163 | 151 |
| 164 self._flags = None | 152 self._flags = None |
| 165 self._initializeFlagAttributes(args) | 153 self.__initializeFlagAttributes(args) |
| 166 | 154 |
| 167 self._driver_apk = None | 155 def __initializeApkAttributes(self, args, error_func): |
| 168 self._driver_package = None | |
| 169 self._driver_name = None | |
| 170 self._initializeDriverAttributes() | |
| 171 | |
| 172 def _initializeApkAttributes(self, args, error_func): | |
| 173 if args.apk_under_test.endswith('.apk'): | 156 if args.apk_under_test.endswith('.apk'): |
| 174 self._apk_under_test = args.apk_under_test | 157 self._apk_under_test = args.apk_under_test |
| 175 else: | 158 else: |
| 176 self._apk_under_test = os.path.join( | 159 self._apk_under_test = os.path.join( |
| 177 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, | 160 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, |
| 178 '%s.apk' % args.apk_under_test) | 161 '%s.apk' % args.apk_under_test) |
| 179 | 162 |
| 180 if not os.path.exists(self._apk_under_test): | 163 if not os.path.exists(self._apk_under_test): |
| 181 error_func('Unable to find APK under test: %s' % self._apk_under_test) | 164 error_func('Unable to find APK under test: %s' % self._apk_under_test) |
| 182 | 165 |
| 183 if args.test_apk.endswith('.apk'): | 166 if args.test_apk.endswith('.apk'): |
| 184 self._suite = os.path.splitext(os.path.basename(args.test_apk))[0] | 167 test_apk_root = os.path.splitext(os.path.basename(args.test_apk))[0] |
| 185 self._test_apk = args.test_apk | 168 self._test_apk = args.test_apk |
| 186 else: | 169 else: |
| 187 self._suite = args.test_apk | 170 test_apk_root = args.test_apk |
| 188 self._test_apk = os.path.join( | 171 self._test_apk = os.path.join( |
| 189 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, | 172 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, |
| 190 '%s.apk' % args.test_apk) | 173 '%s.apk' % args.test_apk) |
| 191 | 174 |
| 192 self._test_jar = os.path.join( | 175 self._test_jar = os.path.join( |
| 193 constants.GetOutDirectory(), constants.SDK_BUILD_TEST_JAVALIB_DIR, | 176 constants.GetOutDirectory(), constants.SDK_BUILD_TEST_JAVALIB_DIR, |
| 194 '%s.jar' % self._suite) | 177 '%s.jar' % test_apk_root) |
| 195 self._test_support_apk = os.path.join( | 178 self._test_support_apk = os.path.join( |
| 196 constants.GetOutDirectory(), constants.SDK_BUILD_TEST_JAVALIB_DIR, | 179 constants.GetOutDirectory(), constants.SDK_BUILD_TEST_JAVALIB_DIR, |
| 197 '%sSupport.apk' % self._suite) | 180 '%sSupport.apk' % test_apk_root) |
| 198 | 181 |
| 199 if not os.path.exists(self._test_apk): | 182 if not os.path.exists(self._test_apk): |
| 200 error_func('Unable to find test APK: %s' % self._test_apk) | 183 error_func('Unable to find test APK: %s' % self._test_apk) |
| 201 if not os.path.exists(self._test_jar): | 184 if not os.path.exists(self._test_jar): |
| 202 error_func('Unable to find test JAR: %s' % self._test_jar) | 185 error_func('Unable to find test JAR: %s' % self._test_jar) |
| 203 | 186 |
| 204 self._test_package = apk_helper.GetPackageName(self.test_apk) | 187 self._test_package = apk_helper.GetPackageName(self.test_apk) |
| 205 self._test_runner = apk_helper.GetInstrumentationName(self.test_apk) | 188 self._test_runner = apk_helper.GetInstrumentationName(self.test_apk) |
| 206 | 189 |
| 207 self._package_info = None | 190 self._package_info = None |
| 208 for package_info in constants.PACKAGE_INFO.itervalues(): | 191 for package_info in constants.PACKAGE_INFO.itervalues(): |
| 209 if self._test_package == package_info.test_package: | 192 if self._test_package == package_info.test_package: |
| 210 self._package_info = package_info | 193 self._package_info = package_info |
| 211 if not self._package_info: | 194 if not self._package_info: |
| 212 logging.warning('Unable to find package info for %s', self._test_package) | 195 logging.warning('Unable to find package info for %s', self._test_package) |
| 213 | 196 |
| 214 def _initializeDataDependencyAttributes(self, args, isolate_delegate): | 197 def __initializeDataDependencyAttributes(self, args, isolate_delegate): |
| 215 self._data_deps = [] | 198 self._data_deps = [] |
| 216 if args.isolate_file_path: | 199 if args.isolate_file_path: |
| 217 self._isolate_abs_path = os.path.abspath(args.isolate_file_path) | 200 self._isolate_abs_path = os.path.abspath(args.isolate_file_path) |
| 218 self._isolate_delegate = isolate_delegate | 201 self._isolate_delegate = isolate_delegate |
| 219 self._isolated_abs_path = os.path.join( | 202 self._isolated_abs_path = os.path.join( |
| 220 constants.GetOutDirectory(), '%s.isolated' % self._test_package) | 203 constants.GetOutDirectory(), '%s.isolated' % self._test_package) |
| 221 else: | 204 else: |
| 222 self._isolate_delegate = None | 205 self._isolate_delegate = None |
| 223 | 206 |
| 224 # TODO(jbudorick): Deprecate and remove --test-data once data dependencies | 207 # TODO(jbudorick): Deprecate and remove --test-data once data dependencies |
| 225 # are fully converted to isolate. | 208 # are fully converted to isolate. |
| 226 if args.test_data: | 209 if args.test_data: |
| 227 logging.info('Data dependencies specified via --test-data') | 210 logging.info('Data dependencies specified via --test-data') |
| 228 self._test_data = args.test_data | 211 self._test_data = args.test_data |
| 229 else: | 212 else: |
| 230 self._test_data = None | 213 self._test_data = None |
| 231 | 214 |
| 232 if not self._isolate_delegate and not self._test_data: | 215 if not self._isolate_delegate and not self._test_data: |
| 233 logging.warning('No data dependencies will be pushed.') | 216 logging.warning('No data dependencies will be pushed.') |
| 234 | 217 |
| 235 def _initializeTestFilterAttributes(self, args): | 218 def __initializeTestFilterAttributes(self, args): |
| 236 self._test_filter = args.test_filter | 219 self._test_filter = args.test_filter |
| 237 | 220 |
| 238 def annotation_dict_element(a): | 221 def annotation_dict_element(a): |
| 239 a = a.split('=') | 222 a = a.split('=') |
| 240 return (a[0], a[1] if len(a) == 2 else None) | 223 return (a[0], a[1] if len(a) == 2 else None) |
| 241 | 224 |
| 242 if args.annotation_str: | 225 if args.annotation_str: |
| 243 self._annotations = dict( | 226 self._annotations = dict( |
| 244 annotation_dict_element(a) | 227 annotation_dict_element(a) |
| 245 for a in args.annotation_str.split(',')) | 228 for a in args.annotation_str.split(',')) |
| 246 elif not self._test_filter: | 229 elif not self._test_filter: |
| 247 self._annotations = dict( | 230 self._annotations = dict( |
| 248 annotation_dict_element(a) | 231 annotation_dict_element(a) |
| 249 for a in _DEFAULT_ANNOTATIONS) | 232 for a in _DEFAULT_ANNOTATIONS) |
| 250 else: | 233 else: |
| 251 self._annotations = {} | 234 self._annotations = {} |
| 252 | 235 |
| 253 if args.exclude_annotation_str: | 236 if args.exclude_annotation_str: |
| 254 self._excluded_annotations = dict( | 237 self._excluded_annotations = dict( |
| 255 annotation_dict_element(a) | 238 annotation_dict_element(a) |
| 256 for a in args.exclude_annotation_str.split(',')) | 239 for a in args.exclude_annotation_str.split(',')) |
| 257 else: | 240 else: |
| 258 self._excluded_annotations = {} | 241 self._excluded_annotations = {} |
| 259 | 242 |
| 260 def _initializeFlagAttributes(self, args): | 243 def __initializeFlagAttributes(self, args): |
| 261 self._flags = ['--disable-fre', '--enable-test-intents'] | 244 self._flags = ['--disable-fre', '--enable-test-intents'] |
| 262 # TODO(jbudorick): Transition "--device-flags" to "--device-flags-file" | 245 # TODO(jbudorick): Transition "--device-flags" to "--device-flags-file" |
| 263 if hasattr(args, 'device_flags') and args.device_flags: | 246 if hasattr(args, 'device_flags') and args.device_flags: |
| 264 with open(args.device_flags) as device_flags_file: | 247 with open(args.device_flags) as device_flags_file: |
| 265 stripped_lines = (l.strip() for l in device_flags_file) | 248 stripped_lines = (l.strip() for l in device_flags_file) |
| 266 self._flags.extend([flag for flag in stripped_lines if flag]) | 249 self._flags.extend([flag for flag in stripped_lines if flag]) |
| 267 if hasattr(args, 'device_flags_file') and args.device_flags_file: | 250 if hasattr(args, 'device_flags_file') and args.device_flags_file: |
| 268 with open(args.device_flags_file) as device_flags_file: | 251 with open(args.device_flags_file) as device_flags_file: |
| 269 stripped_lines = (l.strip() for l in device_flags_file) | 252 stripped_lines = (l.strip() for l in device_flags_file) |
| 270 self._flags.extend([flag for flag in stripped_lines if flag]) | 253 self._flags.extend([flag for flag in stripped_lines if flag]) |
| 271 | 254 |
| 272 def _initializeDriverAttributes(self): | 255 @property |
| 273 self._driver_apk = os.path.join( | 256 def suite(self): |
| 274 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, | 257 return 'instrumentation' |
| 275 'OnDeviceInstrumentationDriver.apk') | |
| 276 if os.path.exists(self._driver_apk): | |
| 277 self._driver_package = apk_helper.GetPackageName( | |
| 278 self._driver_apk) | |
| 279 self._driver_name = apk_helper.GetInstrumentationName( | |
| 280 self._driver_apk) | |
| 281 else: | |
| 282 self._driver_apk = None | |
| 283 | 258 |
| 284 @property | 259 @property |
| 285 def apk_under_test(self): | 260 def apk_under_test(self): |
| 286 return self._apk_under_test | 261 return self._apk_under_test |
| 287 | 262 |
| 288 @property | 263 @property |
| 289 def flags(self): | 264 def flags(self): |
| 290 return self._flags | 265 return self._flags |
| 291 | 266 |
| 292 @property | 267 @property |
| 293 def driver_apk(self): | |
| 294 return self._driver_apk | |
| 295 | |
| 296 @property | |
| 297 def driver_package(self): | |
| 298 return self._driver_package | |
| 299 | |
| 300 @property | |
| 301 def driver_name(self): | |
| 302 return self._driver_name | |
| 303 | |
| 304 @property | |
| 305 def package_info(self): | 268 def package_info(self): |
| 306 return self._package_info | 269 return self._package_info |
| 307 | 270 |
| 308 @property | 271 @property |
| 309 def suite(self): | |
| 310 return self._suite | |
| 311 | |
| 312 @property | |
| 313 def test_apk(self): | 272 def test_apk(self): |
| 314 return self._test_apk | 273 return self._test_apk |
| 315 | 274 |
| 316 @property | 275 @property |
| 317 def test_jar(self): | 276 def test_jar(self): |
| 318 return self._test_jar | 277 return self._test_jar |
| 319 | 278 |
| 320 @property | 279 @property |
| 321 def test_support_apk(self): | 280 def test_support_apk(self): |
| 322 return self._test_support_apk | 281 return self._test_support_apk |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 a = dict(c['annotations']) | 439 a = dict(c['annotations']) |
| 481 a.update(m['annotations']) | 440 a.update(m['annotations']) |
| 482 inflated_tests.append({ | 441 inflated_tests.append({ |
| 483 'class': c['class'], | 442 'class': c['class'], |
| 484 'method': m['method'], | 443 'method': m['method'], |
| 485 'annotations': a, | 444 'annotations': a, |
| 486 }) | 445 }) |
| 487 return inflated_tests | 446 return inflated_tests |
| 488 | 447 |
| 489 @staticmethod | 448 @staticmethod |
| 490 def GetHttpServerEnvironmentVars(): | |
| 491 return { | |
| 492 _EXTRA_ENABLE_HTTP_SERVER: None, | |
| 493 } | |
| 494 | |
| 495 def GetDriverEnvironmentVars( | |
| 496 self, test_list=None, test_list_file_path=None): | |
| 497 env = { | |
| 498 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package, | |
| 499 _EXTRA_DRIVER_TARGET_CLASS: self.test_runner, | |
| 500 } | |
| 501 | |
| 502 if test_list: | |
| 503 env[_EXTRA_DRIVER_TEST_LIST] = ','.join(test_list) | |
| 504 | |
| 505 if test_list_file_path: | |
| 506 env[_EXTRA_DRIVER_TEST_LIST_FILE] = ( | |
| 507 os.path.basename(test_list_file_path)) | |
| 508 | |
| 509 return env | |
| 510 | |
| 511 @staticmethod | |
| 512 def ParseAmInstrumentRawOutput(raw_output): | 449 def ParseAmInstrumentRawOutput(raw_output): |
| 513 return ParseAmInstrumentRawOutput(raw_output) | 450 return ParseAmInstrumentRawOutput(raw_output) |
| 514 | 451 |
| 515 @staticmethod | 452 @staticmethod |
| 516 def GenerateTestResults( | 453 def GenerateTestResults( |
| 517 result_code, result_bundle, statuses, start_ms, duration_ms): | 454 result_code, result_bundle, statuses, start_ms, duration_ms): |
| 518 return GenerateTestResults(result_code, result_bundle, statuses, | 455 return GenerateTestResults(result_code, result_bundle, statuses, |
| 519 start_ms, duration_ms) | 456 start_ms, duration_ms) |
| 520 | 457 |
| 521 #override | 458 #override |
| 522 def TearDown(self): | 459 def TearDown(self): |
| 523 if self._isolate_delegate: | 460 if self._isolate_delegate: |
| 524 self._isolate_delegate.Clear() | 461 self._isolate_delegate.Clear() |
| 525 | 462 |
| OLD | NEW |