Chromium Code Reviews| 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 copy | 5 import copy |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import pickle | 8 import pickle |
| 9 import re | 9 import re |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 _ACTIVITY_RESULT_CANCELED = 0 | 29 _ACTIVITY_RESULT_CANCELED = 0 |
| 30 _ACTIVITY_RESULT_OK = -1 | 30 _ACTIVITY_RESULT_OK = -1 |
| 31 | 31 |
| 32 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' | 32 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' |
| 33 _DEFAULT_ANNOTATIONS = [ | 33 _DEFAULT_ANNOTATIONS = [ |
| 34 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', 'IntegrationTest'] | 34 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', 'IntegrationTest'] |
| 35 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [ | 35 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [ |
| 36 'DisabledTest', 'FlakyTest'] | 36 'DisabledTest', 'FlakyTest'] |
| 37 _VALID_ANNOTATIONS = set(['Manual'] + _DEFAULT_ANNOTATIONS + | 37 _VALID_ANNOTATIONS = set(['Manual'] + _DEFAULT_ANNOTATIONS + |
| 38 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS) | 38 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS) |
| 39 | |
| 40 # These test methods are inherited from android.test base test class and | |
| 41 # should be permitted for not having size annotation. For more, please check | |
| 42 # https://developer.android.com/reference/android/test/AndroidTestCase.html | |
| 43 # https://developer.android.com/reference/android/test/ServiceTestCase.html | |
| 44 _TEST_WITHOUT_SIZE_ANNOTATIONS = [ | |
|
jbudorick
2017/07/21 19:35:08
what the... what are these? Where did they come fr
| |
| 45 'testAndroidTestCaseSetupProperly', 'testServiceTestCaseSetUpProperly'] | |
| 46 | |
| 39 _EXTRA_DRIVER_TEST_LIST = ( | 47 _EXTRA_DRIVER_TEST_LIST = ( |
| 40 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') | 48 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') |
| 41 _EXTRA_DRIVER_TEST_LIST_FILE = ( | 49 _EXTRA_DRIVER_TEST_LIST_FILE = ( |
| 42 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') | 50 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') |
| 43 _EXTRA_DRIVER_TARGET_PACKAGE = ( | 51 _EXTRA_DRIVER_TARGET_PACKAGE = ( |
| 44 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') | 52 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') |
| 45 _EXTRA_DRIVER_TARGET_CLASS = ( | 53 _EXTRA_DRIVER_TARGET_CLASS = ( |
| 46 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') | 54 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') |
| 47 _EXTRA_TIMEOUT_SCALE = ( | 55 _EXTRA_TIMEOUT_SCALE = ( |
| 48 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') | 56 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 60 super(MissingSizeAnnotationError, self).__init__(class_name + | 68 super(MissingSizeAnnotationError, self).__init__(class_name + |
| 61 ': Test method is missing required size annotation. Add one of: ' + | 69 ': Test method is missing required size annotation. Add one of: ' + |
| 62 ', '.join('@' + a for a in _VALID_ANNOTATIONS)) | 70 ', '.join('@' + a for a in _VALID_ANNOTATIONS)) |
| 63 | 71 |
| 64 | 72 |
| 65 class TestListPickleException(test_exception.TestException): | 73 class TestListPickleException(test_exception.TestException): |
| 66 pass | 74 pass |
| 67 | 75 |
| 68 | 76 |
| 69 # TODO(jbudorick): Make these private class methods of | 77 # TODO(jbudorick): Make these private class methods of |
| 70 # InstrumentationTestInstance once the instrumentation test_runner is | 78 # InstrumentationTestInstance once the instrumentation junit3_runner_class is |
| 71 # deprecated. | 79 # deprecated. |
| 72 def ParseAmInstrumentRawOutput(raw_output): | 80 def ParseAmInstrumentRawOutput(raw_output): |
| 73 """Parses the output of an |am instrument -r| call. | 81 """Parses the output of an |am instrument -r| call. |
| 74 | 82 |
| 75 Args: | 83 Args: |
| 76 raw_output: the output of an |am instrument -r| call as a list of lines | 84 raw_output: the output of an |am instrument -r| call as a list of lines |
| 77 Returns: | 85 Returns: |
| 78 A 3-tuple containing: | 86 A 3-tuple containing: |
| 79 - the instrumentation code as an integer | 87 - the instrumentation code as an integer |
| 80 - the instrumentation result as a list of lines | 88 - the instrumentation result as a list of lines |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 | 164 |
| 157 return results | 165 return results |
| 158 | 166 |
| 159 | 167 |
| 160 def FilterTests(tests, test_filter=None, annotations=None, | 168 def FilterTests(tests, test_filter=None, annotations=None, |
| 161 excluded_annotations=None): | 169 excluded_annotations=None): |
| 162 """Filter a list of tests | 170 """Filter a list of tests |
| 163 | 171 |
| 164 Args: | 172 Args: |
| 165 tests: a list of tests. e.g. [ | 173 tests: a list of tests. e.g. [ |
| 166 {'annotations": {}, 'class': 'com.example.TestA', 'methods':[]}, | 174 {'annotations": {}, 'class': 'com.example.TestA', 'method':'test1'}, |
| 167 {'annotations": {}, 'class': 'com.example.TestB', 'methods':[]}] | 175 {'annotations": {}, 'class': 'com.example.TestB', 'method':'test2'}] |
| 168 test_filter: googletest-style filter string. | 176 test_filter: googletest-style filter string. |
| 169 annotations: a dict of wanted annotations for test methods. | 177 annotations: a dict of wanted annotations for test methods. |
| 170 exclude_annotations: a dict of annotations to exclude. | 178 exclude_annotations: a dict of annotations to exclude. |
| 171 | 179 |
| 172 Return: | 180 Return: |
| 173 A list of filtered tests | 181 A list of filtered tests |
| 174 """ | 182 """ |
| 175 def gtest_filter(t): | 183 def gtest_filter(t): |
| 176 if not test_filter: | 184 if not test_filter: |
| 177 return True | 185 return True |
| 178 # Allow fully-qualified name as well as an omitted package. | 186 # Allow fully-qualified name as well as an omitted package. |
| 179 unqualified_class_test = { | 187 unqualified_class_test = { |
| 180 'class': t['class'].split('.')[-1], | 188 'class': t['class'].split('.')[-1], |
| 181 'method': t['method'] | 189 'method': t['method'] |
| 182 } | 190 } |
| 183 names = [ | 191 names = [ |
| 184 GetTestName(t, sep='.'), | 192 GetTestName(t, sep='.'), |
| 185 GetTestName(unqualified_class_test, sep='.'), | 193 GetTestName(unqualified_class_test, sep='.'), |
| 186 GetUniqueTestName(t, sep='.') | 194 GetUniqueTestName(t, sep='.') |
| 187 ] | 195 ] |
| 188 | 196 |
| 197 if t['is_junit4']: | |
| 198 names += [ | |
| 199 GetTestNameWithoutParameterPostfix(t, sep='.'), | |
| 200 GetTestNameWithoutParameterPostfix(unqualified_class_test, sep='.') | |
| 201 ] | |
| 202 | |
| 189 pattern_groups = test_filter.split('-') | 203 pattern_groups = test_filter.split('-') |
| 190 if len(pattern_groups) > 1: | 204 if len(pattern_groups) > 1: |
| 191 negative_filter = pattern_groups[1] | 205 negative_filter = pattern_groups[1] |
| 192 if unittest_util.FilterTestNames(names, negative_filter): | 206 if unittest_util.FilterTestNames(names, negative_filter): |
| 193 return [] | 207 return [] |
| 194 | 208 |
| 195 positive_filter = pattern_groups[0] | 209 positive_filter = pattern_groups[0] |
| 196 return unittest_util.FilterTestNames(names, positive_filter) | 210 return unittest_util.FilterTestNames(names, positive_filter) |
| 197 | 211 |
| 198 def annotation_filter(all_annotations): | 212 def annotation_filter(all_annotations): |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 221 return filter_av in av | 235 return filter_av in av |
| 222 return filter_av == av | 236 return filter_av == av |
| 223 | 237 |
| 224 filtered_tests = [] | 238 filtered_tests = [] |
| 225 for t in tests: | 239 for t in tests: |
| 226 # Gtest filtering | 240 # Gtest filtering |
| 227 if not gtest_filter(t): | 241 if not gtest_filter(t): |
| 228 continue | 242 continue |
| 229 | 243 |
| 230 # Enforce that all tests declare their size. | 244 # Enforce that all tests declare their size. |
| 231 if not any(a in _VALID_ANNOTATIONS for a in t['annotations']): | 245 if (not any(a in _VALID_ANNOTATIONS for a in t['annotations']) |
| 246 and t['method'] not in _TEST_WITHOUT_SIZE_ANNOTATIONS): | |
| 232 raise MissingSizeAnnotationError(GetTestName(t)) | 247 raise MissingSizeAnnotationError(GetTestName(t)) |
| 233 | 248 |
| 234 if (not annotation_filter(t['annotations']) | 249 if (not annotation_filter(t['annotations']) |
| 235 or not excluded_annotation_filter(t['annotations'])): | 250 or not excluded_annotation_filter(t['annotations'])): |
| 236 continue | 251 continue |
| 237 | 252 |
| 238 filtered_tests.append(t) | 253 filtered_tests.append(t) |
| 239 | 254 |
| 240 return filtered_tests | 255 return filtered_tests |
| 241 | 256 |
| 242 | 257 |
| 258 def _GetAllTestsFromRunnerPickle(test_apk): | |
| 259 pickle_path = '%s-runner.pickle' % test_apk.path | |
| 260 return _GetTestsFromPickle(pickle_path, test_apk.path) | |
| 261 | |
| 262 | |
| 263 # TODO(yolandyan): remove this once the tests are converted to junit4 | |
| 243 def GetAllTestsFromJar(test_jar): | 264 def GetAllTestsFromJar(test_jar): |
| 244 pickle_path = '%s-proguard.pickle' % test_jar | 265 pickle_path = '%s-proguard.pickle' % test_jar |
| 245 try: | 266 try: |
| 246 tests = _GetTestsFromPickle(pickle_path, test_jar) | 267 tests = _GetTestsFromPickle(pickle_path, test_jar) |
| 247 except TestListPickleException as e: | 268 except TestListPickleException as e: |
| 248 logging.info('Could not get tests from pickle: %s', e) | 269 logging.info('Could not get tests from pickle: %s', e) |
| 249 logging.info('Getting tests from JAR via proguard.') | 270 logging.info('Getting tests from JAR via proguard.') |
| 250 tests = _GetTestsFromProguard(test_jar) | 271 tests = _GetTestsFromProguard(test_jar) |
| 251 _SaveTestsToPickle(pickle_path, test_jar, tests) | 272 _SaveTestsToPickle(pickle_path, test_jar, tests) |
| 252 return tests | 273 return tests |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 for class_name, class_info in package_info['classes'].iteritems(): | 352 for class_name, class_info in package_info['classes'].iteritems(): |
| 332 if class_name.endswith('Test'): | 353 if class_name.endswith('Test'): |
| 333 tests.append({ | 354 tests.append({ |
| 334 'class': '%s.%s' % (package_name, class_name), | 355 'class': '%s.%s' % (package_name, class_name), |
| 335 'annotations': {}, | 356 'annotations': {}, |
| 336 'methods': get_test_methods(class_info['methods']), | 357 'methods': get_test_methods(class_info['methods']), |
| 337 'superclass': class_info['superclass'], | 358 'superclass': class_info['superclass'], |
| 338 }) | 359 }) |
| 339 return tests | 360 return tests |
| 340 | 361 |
| 341 | |
| 342 def _SaveTestsToPickle(pickle_path, jar_path, tests): | 362 def _SaveTestsToPickle(pickle_path, jar_path, tests): |
| 343 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] | 363 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] |
| 344 pickle_data = { | 364 pickle_data = { |
| 345 'VERSION': _PICKLE_FORMAT_VERSION, | 365 'VERSION': _PICKLE_FORMAT_VERSION, |
| 346 'JAR_MD5SUM': jar_md5, | 366 'JAR_MD5SUM': jar_md5, |
| 347 'TEST_METHODS': tests, | 367 'TEST_METHODS': tests, |
| 348 } | 368 } |
| 349 with open(pickle_path, 'w') as pickle_file: | 369 with open(pickle_path, 'w') as pickle_file: |
| 350 pickle.dump(pickle_data, pickle_file) | 370 pickle.dump(pickle_data, pickle_file) |
| 351 | 371 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 374 | 394 |
| 375 Args: | 395 Args: |
| 376 test: the instrumentation test dict. | 396 test: the instrumentation test dict. |
| 377 sep: the character(s) that should join the class name and the method name. | 397 sep: the character(s) that should join the class name and the method name. |
| 378 Returns: | 398 Returns: |
| 379 The test name as a string. | 399 The test name as a string. |
| 380 """ | 400 """ |
| 381 return '%s%s%s' % (test['class'], sep, test['method']) | 401 return '%s%s%s' % (test['class'], sep, test['method']) |
| 382 | 402 |
| 383 | 403 |
| 404 def GetTestNameWithoutParameterPostfix( | |
| 405 test, sep='#', parameterization_sep='__'): | |
| 406 """Gets the name of the given JUnit4 test without parameter postfix. | |
| 407 | |
| 408 For most WebView JUnit4 javatests, each test is parameterizatized with | |
| 409 "__sandboxed_mode" to run in both non-sandboxed mode and sandboxed mode. | |
| 410 | |
| 411 This function returns the name of the test without parameterization | |
| 412 so test filters can match both parameterized and non-parameterized tests. | |
| 413 | |
| 414 Args: | |
| 415 test: the instrumentation test dict. | |
| 416 sep: the character(s) that should join the class name and the method name. | |
| 417 parameterization_sep: the character(s) that seperate method name and method | |
| 418 parameterization postfix. | |
| 419 Returns: | |
| 420 The test name without parameter postfix as a string. | |
| 421 """ | |
| 422 name = GetTestName(test, sep=sep) | |
| 423 return name.split(parameterization_sep)[0] | |
| 424 | |
| 425 | |
| 384 def GetUniqueTestName(test, sep='#'): | 426 def GetUniqueTestName(test, sep='#'): |
| 385 """Gets the unique name of the given test. | 427 """Gets the unique name of the given test. |
| 386 | 428 |
| 387 This will include text to disambiguate between tests for which GetTestName | 429 This will include text to disambiguate between tests for which GetTestName |
| 388 would return the same name. | 430 would return the same name. |
| 389 | 431 |
| 390 Args: | 432 Args: |
| 391 test: the instrumentation test dict. | 433 test: the instrumentation test dict. |
| 392 sep: the character(s) that should join the class name and the method name. | 434 sep: the character(s) that should join the class name and the method name. |
| 393 Returns: | 435 Returns: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 406 | 448 |
| 407 self._additional_apks = [] | 449 self._additional_apks = [] |
| 408 self._apk_under_test = None | 450 self._apk_under_test = None |
| 409 self._apk_under_test_incremental_install_script = None | 451 self._apk_under_test_incremental_install_script = None |
| 410 self._package_info = None | 452 self._package_info = None |
| 411 self._suite = None | 453 self._suite = None |
| 412 self._test_apk = None | 454 self._test_apk = None |
| 413 self._test_apk_incremental_install_script = None | 455 self._test_apk_incremental_install_script = None |
| 414 self._test_jar = None | 456 self._test_jar = None |
| 415 self._test_package = None | 457 self._test_package = None |
| 416 self._test_runner = None | 458 self._junit3_runner_class = None |
| 417 self._test_runner_junit4 = None | 459 self._junit4_runner_class = None |
| 418 self._test_support_apk = None | 460 self._test_support_apk = None |
| 419 self._initializeApkAttributes(args, error_func) | 461 self._initializeApkAttributes(args, error_func) |
| 420 | 462 |
| 421 self._data_deps = None | 463 self._data_deps = None |
| 422 self._data_deps_delegate = None | 464 self._data_deps_delegate = None |
| 423 self._runtime_deps_path = None | 465 self._runtime_deps_path = None |
| 424 self._initializeDataDependencyAttributes(args, data_deps_delegate) | 466 self._initializeDataDependencyAttributes(args, data_deps_delegate) |
| 425 | 467 |
| 426 self._annotations = None | 468 self._annotations = None |
| 427 self._excluded_annotations = None | 469 self._excluded_annotations = None |
| 428 self._test_filter = None | 470 self._test_filter = None |
| 429 self._initializeTestFilterAttributes(args) | 471 self._initializeTestFilterAttributes(args) |
| 430 | 472 |
| 473 self._tests_from_runner = None | |
| 474 | |
| 431 self._flags = None | 475 self._flags = None |
| 432 self._initializeFlagAttributes(args) | 476 self._initializeFlagAttributes(args) |
| 433 | 477 |
| 434 self._driver_apk = None | 478 self._driver_apk = None |
| 435 self._driver_package = None | 479 self._driver_package = None |
| 436 self._driver_name = None | 480 self._driver_name = None |
| 437 self._initializeDriverAttributes() | 481 self._initializeDriverAttributes() |
| 438 | 482 |
| 439 self._render_results_dir = None | 483 self._render_results_dir = None |
| 440 self._screenshot_dir = None | 484 self._screenshot_dir = None |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 error_func('Unable to find test APK: %s' % self._test_apk.path) | 558 error_func('Unable to find test APK: %s' % self._test_apk.path) |
| 515 if not self._test_jar: | 559 if not self._test_jar: |
| 516 logging.warning('Test jar not specified. Test runner will not have ' | 560 logging.warning('Test jar not specified. Test runner will not have ' |
| 517 'Java annotation info available. May not handle test ' | 561 'Java annotation info available. May not handle test ' |
| 518 'timeouts correctly.') | 562 'timeouts correctly.') |
| 519 elif not os.path.exists(self._test_jar): | 563 elif not os.path.exists(self._test_jar): |
| 520 error_func('Unable to find test JAR: %s' % self._test_jar) | 564 error_func('Unable to find test JAR: %s' % self._test_jar) |
| 521 | 565 |
| 522 self._test_package = self._test_apk.GetPackageName() | 566 self._test_package = self._test_apk.GetPackageName() |
| 523 all_instrumentations = self._test_apk.GetAllInstrumentations() | 567 all_instrumentations = self._test_apk.GetAllInstrumentations() |
| 524 test_runners = [ | 568 all_junit3_runner_classes = [ |
| 525 x for x in all_instrumentations if ('true' not in x.get( | 569 x for x in all_instrumentations if ('true' not in x.get( |
| 526 'chromium-junit4', ''))] | 570 'chromium-junit4', ''))] |
| 527 test_runners_junit4 = [ | 571 all_junit4_test_runner_classes = [ |
| 528 x for x in all_instrumentations if ('true' in x.get( | 572 x for x in all_instrumentations if ('true' in x.get( |
| 529 'chromium-junit4', ''))] | 573 'chromium-junit4', ''))] |
| 530 | 574 |
| 531 if len(test_runners) > 1: | 575 if len(all_junit3_runner_classes) > 1: |
| 532 logging.warning('This test apk has more than one JUnit3 instrumentation') | 576 logging.warning('This test apk has more than one JUnit3 instrumentation') |
| 533 if len(test_runners_junit4) > 1: | 577 if len(all_junit4_test_runner_classes) > 1: |
| 534 logging.warning('This test apk has more than one JUnit4 instrumentation') | 578 logging.warning('This test apk has more than one JUnit4 instrumentation') |
| 535 | 579 |
| 536 self._test_runner = ( | 580 self._junit3_runner_class = ( |
| 537 test_runners[0]['android:name'] if test_runners else | 581 all_junit3_runner_classes[0]['android:name'] |
| 538 self.test_apk.GetInstrumentationName()) | 582 if all_junit3_runner_classes else self.test_apk.GetInstrumentationName()) |
| 539 self._test_runner_junit4 = ( | 583 |
| 540 test_runners_junit4[0]['android:name'] if test_runners_junit4 else None) | 584 self._junit4_runner_class = ( |
| 585 all_junit4_test_runner_classes[0]['android:name'] | |
| 586 if all_junit4_test_runner_classes else None) | |
| 541 | 587 |
| 542 self._package_info = None | 588 self._package_info = None |
| 543 if self._apk_under_test: | 589 if self._apk_under_test: |
| 544 package_under_test = self._apk_under_test.GetPackageName() | 590 package_under_test = self._apk_under_test.GetPackageName() |
| 545 for package_info in constants.PACKAGE_INFO.itervalues(): | 591 for package_info in constants.PACKAGE_INFO.itervalues(): |
| 546 if package_under_test == package_info.package: | 592 if package_under_test == package_info.package: |
| 547 self._package_info = package_info | 593 self._package_info = package_info |
| 548 break | 594 break |
| 549 if not self._package_info: | 595 if not self._package_info: |
| 550 logging.warning('Unable to find package info for %s', self._test_package) | 596 logging.warning('Unable to find package info for %s', self._test_package) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 | 730 |
| 685 @property | 731 @property |
| 686 def flags(self): | 732 def flags(self): |
| 687 return self._flags | 733 return self._flags |
| 688 | 734 |
| 689 @property | 735 @property |
| 690 def gs_results_bucket(self): | 736 def gs_results_bucket(self): |
| 691 return self._gs_results_bucket | 737 return self._gs_results_bucket |
| 692 | 738 |
| 693 @property | 739 @property |
| 740 def junit3_runner_class(self): | |
| 741 return self._junit3_runner_class | |
| 742 | |
| 743 @property | |
| 744 def junit4_runner_class(self): | |
| 745 return self._junit4_runner_class | |
| 746 | |
| 747 @property | |
| 694 def should_save_logcat(self): | 748 def should_save_logcat(self): |
| 695 return self._should_save_logcat | 749 return self._should_save_logcat |
| 696 | 750 |
| 697 @property | 751 @property |
| 698 def package_info(self): | 752 def package_info(self): |
| 699 return self._package_info | 753 return self._package_info |
| 700 | 754 |
| 701 @property | 755 @property |
| 702 def render_results_dir(self): | 756 def render_results_dir(self): |
| 703 return self._render_results_dir | 757 return self._render_results_dir |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 732 | 786 |
| 733 @property | 787 @property |
| 734 def test_support_apk(self): | 788 def test_support_apk(self): |
| 735 return self._test_support_apk | 789 return self._test_support_apk |
| 736 | 790 |
| 737 @property | 791 @property |
| 738 def test_package(self): | 792 def test_package(self): |
| 739 return self._test_package | 793 return self._test_package |
| 740 | 794 |
| 741 @property | 795 @property |
| 742 def test_runner(self): | 796 def tests_from_runner(self): |
| 743 return self._test_runner | 797 return self._tests_from_runner |
| 744 | |
| 745 @property | |
| 746 def test_runner_junit4(self): | |
| 747 return self._test_runner_junit4 | |
| 748 | 798 |
| 749 @property | 799 @property |
| 750 def timeout_scale(self): | 800 def timeout_scale(self): |
| 751 return self._timeout_scale | 801 return self._timeout_scale |
| 752 | 802 |
| 753 @property | 803 @property |
| 754 def total_external_shards(self): | 804 def total_external_shards(self): |
| 755 return self._total_external_shards | 805 return self._total_external_shards |
| 756 | 806 |
| 757 @property | 807 @property |
| 758 def ui_screenshot_dir(self): | 808 def ui_screenshot_dir(self): |
| 759 return self._ui_screenshot_dir | 809 return self._ui_screenshot_dir |
| 760 | 810 |
| 761 #override | 811 #override |
| 762 def TestType(self): | 812 def TestType(self): |
| 763 return 'instrumentation' | 813 return 'instrumentation' |
| 764 | 814 |
| 765 #override | 815 #override |
| 766 def SetUp(self): | 816 def SetUp(self): |
| 767 self._data_deps.extend( | 817 self._data_deps.extend( |
| 768 self._data_deps_delegate(self._runtime_deps_path)) | 818 self._data_deps_delegate(self._runtime_deps_path)) |
| 769 | 819 |
| 770 def GetDataDependencies(self): | 820 def GetDataDependencies(self): |
| 771 return self._data_deps | 821 return self._data_deps |
| 772 | 822 |
| 773 def GetTests(self): | 823 def GetTests(self): |
| 774 if self.test_jar: | 824 if self.junit4_runner_class: |
| 825 if self.tests_from_runner is None: | |
| 826 raise Exception('Failed to list out tests from junit4 runner') | |
| 827 tests = self.tests_from_runner | |
| 828 elif self.test_jar: | |
| 775 tests = GetAllTestsFromJar(self.test_jar) | 829 tests = GetAllTestsFromJar(self.test_jar) |
| 776 else: | 830 else: |
| 777 tests = GetAllTestsFromApk(self.test_apk.path) | 831 tests = GetAllTestsFromApk(self.test_apk.path) |
| 778 inflated_tests = self._ParameterizeTestsWithFlags(self._InflateTests(tests)) | 832 inflated_tests = self._ParameterizeTestsWithFlags(self._InflateTests(tests)) |
| 779 if self._test_runner_junit4 is None and any( | 833 if self._junit4_runner_class is None and any( |
| 780 t['is_junit4'] for t in inflated_tests): | 834 t['is_junit4'] for t in inflated_tests): |
| 781 raise MissingJUnit4RunnerException() | 835 raise MissingJUnit4RunnerException() |
| 782 filtered_tests = FilterTests( | 836 filtered_tests = FilterTests( |
| 783 inflated_tests, self._test_filter, self._annotations, | 837 inflated_tests, self._test_filter, self._annotations, |
| 784 self._excluded_annotations) | 838 self._excluded_annotations) |
| 785 if self._test_filter and not filtered_tests: | 839 if self._test_filter and not filtered_tests: |
| 786 for t in inflated_tests: | 840 for t in inflated_tests: |
| 787 logging.debug(' %s', GetUniqueTestName(t)) | 841 logging.debug(' %s', GetUniqueTestName(t)) |
| 788 raise UnmatchedFilterException(self._test_filter) | 842 raise UnmatchedFilterException(self._test_filter) |
| 789 return filtered_tests | 843 return filtered_tests |
| 790 | 844 |
| 845 def SetTestsFromRunner(self, raw_tests): | |
| 846 self._tests_from_runner = raw_tests | |
| 847 | |
| 791 # pylint: disable=no-self-use | 848 # pylint: disable=no-self-use |
| 792 def _InflateTests(self, tests): | 849 def _InflateTests(self, tests): |
| 793 inflated_tests = [] | 850 inflated_tests = [] |
| 794 for c in tests: | 851 for c in tests: |
| 795 for m in c['methods']: | 852 for m in c['methods']: |
| 796 a = dict(c['annotations']) | 853 a = dict(c['annotations']) |
| 797 a.update(m['annotations']) | 854 a.update(m['annotations']) |
| 798 inflated_tests.append({ | 855 inflated_tests.append({ |
| 799 'class': c['class'], | 856 'class': c['class'], |
| 800 'method': m['method'], | 857 'method': m['method'], |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 816 for p in parameters[1:]: | 873 for p in parameters[1:]: |
| 817 parameterized_t = copy.copy(t) | 874 parameterized_t = copy.copy(t) |
| 818 parameterized_t['flags'] = ['--%s' % p] | 875 parameterized_t['flags'] = ['--%s' % p] |
| 819 new_tests.append(parameterized_t) | 876 new_tests.append(parameterized_t) |
| 820 return tests + new_tests | 877 return tests + new_tests |
| 821 | 878 |
| 822 def GetDriverEnvironmentVars( | 879 def GetDriverEnvironmentVars( |
| 823 self, test_list=None, test_list_file_path=None): | 880 self, test_list=None, test_list_file_path=None): |
| 824 env = { | 881 env = { |
| 825 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package, | 882 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package, |
| 826 _EXTRA_DRIVER_TARGET_CLASS: self.test_runner, | 883 _EXTRA_DRIVER_TARGET_CLASS: self.junit3_runner_class, |
| 827 _EXTRA_TIMEOUT_SCALE: self._timeout_scale, | 884 _EXTRA_TIMEOUT_SCALE: self._timeout_scale, |
| 828 } | 885 } |
| 829 | 886 |
| 830 if test_list: | 887 if test_list: |
| 831 env[_EXTRA_DRIVER_TEST_LIST] = ','.join(test_list) | 888 env[_EXTRA_DRIVER_TEST_LIST] = ','.join(test_list) |
| 832 | 889 |
| 833 if test_list_file_path: | 890 if test_list_file_path: |
| 834 env[_EXTRA_DRIVER_TEST_LIST_FILE] = ( | 891 env[_EXTRA_DRIVER_TEST_LIST_FILE] = ( |
| 835 os.path.basename(test_list_file_path)) | 892 os.path.basename(test_list_file_path)) |
| 836 | 893 |
| 837 return env | 894 return env |
| 838 | 895 |
| 896 def GetAllTestsFromRunnerPickle(self): | |
| 897 return _GetAllTestsFromRunnerPickle(self.test_apk) | |
| 898 | |
| 899 def SaveTestsToPickle(self, raw_tests): | |
| 900 pickle_path = '%s-runner.pickle' % self.test_apk.path | |
| 901 _SaveTestsToPickle(pickle_path, self.test_apk.path, raw_tests) | |
| 902 | |
| 839 @staticmethod | 903 @staticmethod |
| 840 def ParseAmInstrumentRawOutput(raw_output): | 904 def ParseAmInstrumentRawOutput(raw_output): |
| 841 return ParseAmInstrumentRawOutput(raw_output) | 905 return ParseAmInstrumentRawOutput(raw_output) |
| 842 | 906 |
| 843 @staticmethod | 907 @staticmethod |
| 844 def GenerateTestResults( | 908 def GenerateTestResults( |
| 845 result_code, result_bundle, statuses, start_ms, duration_ms): | 909 result_code, result_bundle, statuses, start_ms, duration_ms): |
| 846 return GenerateTestResults(result_code, result_bundle, statuses, | 910 return GenerateTestResults(result_code, result_bundle, statuses, |
| 847 start_ms, duration_ms) | 911 start_ms, duration_ms) |
| 848 | 912 |
| 849 #override | 913 #override |
| 850 def TearDown(self): | 914 def TearDown(self): |
| 851 pass | 915 pass |
| OLD | NEW |