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 collections | 5 import collections |
6 import copy | 6 import copy |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import pickle | 9 import pickle |
10 import re | 10 import re |
(...skipping 15 matching lines...) Expand all Loading... | |
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 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' | 30 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' |
31 _DEFAULT_ANNOTATIONS = [ | 31 _DEFAULT_ANNOTATIONS = [ |
32 'Smoke', 'SmallTest', 'MediumTest', 'LargeTest', | 32 'Smoke', 'SmallTest', 'MediumTest', 'LargeTest', |
33 'EnormousTest', 'IntegrationTest'] | 33 'EnormousTest', 'IntegrationTest'] |
34 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [ | 34 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [ |
35 'DisabledTest', 'FlakyTest'] | 35 'DisabledTest', 'FlakyTest'] |
36 _VALID_ANNOTATIONS = set(['Manual'] + _DEFAULT_ANNOTATIONS + | |
37 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS) | |
36 _EXTRA_DRIVER_TEST_LIST = ( | 38 _EXTRA_DRIVER_TEST_LIST = ( |
37 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') | 39 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') |
38 _EXTRA_DRIVER_TEST_LIST_FILE = ( | 40 _EXTRA_DRIVER_TEST_LIST_FILE = ( |
39 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') | 41 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') |
40 _EXTRA_DRIVER_TARGET_PACKAGE = ( | 42 _EXTRA_DRIVER_TARGET_PACKAGE = ( |
41 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') | 43 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') |
42 _EXTRA_DRIVER_TARGET_CLASS = ( | 44 _EXTRA_DRIVER_TARGET_CLASS = ( |
43 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') | 45 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') |
44 _EXTRA_TIMEOUT_SCALE = ( | 46 _EXTRA_TIMEOUT_SCALE = ( |
45 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') | 47 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') |
46 | 48 |
47 _PARAMETERIZED_TEST_ANNOTATION = 'ParameterizedTest' | 49 _PARAMETERIZED_TEST_ANNOTATION = 'ParameterizedTest' |
48 _PARAMETERIZED_TEST_SET_ANNOTATION = 'ParameterizedTest$Set' | 50 _PARAMETERIZED_TEST_SET_ANNOTATION = 'ParameterizedTest$Set' |
49 _NATIVE_CRASH_RE = re.compile('native crash', re.IGNORECASE) | 51 _NATIVE_CRASH_RE = re.compile('native crash', re.IGNORECASE) |
50 _PICKLE_FORMAT_VERSION = 10 | 52 _PICKLE_FORMAT_VERSION = 10 |
51 | 53 |
52 | 54 |
55 class MissingSizeAnnotationError(Exception): | |
56 def __init__(self, class_name): | |
57 super(MissingSizeAnnotationError, self).__init__(class_name + | |
58 ': Test method is missing required size annotation. Add one of: ' + | |
59 ', '.join('@' + a for a in _VALID_ANNOTATIONS)) | |
60 | |
61 | |
53 # TODO(jbudorick): Make these private class methods of | 62 # TODO(jbudorick): Make these private class methods of |
54 # InstrumentationTestInstance once the instrumentation test_runner is | 63 # InstrumentationTestInstance once the instrumentation test_runner is |
55 # deprecated. | 64 # deprecated. |
56 def ParseAmInstrumentRawOutput(raw_output): | 65 def ParseAmInstrumentRawOutput(raw_output): |
57 """Parses the output of an |am instrument -r| call. | 66 """Parses the output of an |am instrument -r| call. |
58 | 67 |
59 Args: | 68 Args: |
60 raw_output: the output of an |am instrument -r| call as a list of lines | 69 raw_output: the output of an |am instrument -r| call as a list of lines |
61 Returns: | 70 Returns: |
62 A 3-tuple containing: | 71 A 3-tuple containing: |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 | 556 |
548 def gtest_filter(c, m): | 557 def gtest_filter(c, m): |
549 if not self._test_filter: | 558 if not self._test_filter: |
550 return True | 559 return True |
551 # Allow fully-qualified name as well as an omitted package. | 560 # Allow fully-qualified name as well as an omitted package. |
552 names = ['%s.%s' % (c['class'], m['method']), | 561 names = ['%s.%s' % (c['class'], m['method']), |
553 '%s.%s' % (c['class'].split('.')[-1], m['method'])] | 562 '%s.%s' % (c['class'].split('.')[-1], m['method'])] |
554 return unittest_util.FilterTestNames(names, self._test_filter) | 563 return unittest_util.FilterTestNames(names, self._test_filter) |
555 | 564 |
556 def annotation_filter(all_annotations): | 565 def annotation_filter(all_annotations): |
557 if not self._annotations: | 566 if not self._annotations or not all_annotations: |
jbudorick
2016/04/29 00:38:34
Can `not all_annotations` ever be true here?
agrieve
2016/04/29 19:26:02
Whoops, meant to revert that part! Done.
| |
558 return True | 567 return True |
559 return any_annotation_matches(self._annotations, all_annotations) | 568 return any_annotation_matches(self._annotations, all_annotations) |
560 | 569 |
561 def excluded_annotation_filter(all_annotations): | 570 def excluded_annotation_filter(all_annotations): |
562 if not self._excluded_annotations: | 571 if not self._excluded_annotations: |
563 return True | 572 return True |
564 return not any_annotation_matches(self._excluded_annotations, | 573 return not any_annotation_matches(self._excluded_annotations, |
565 all_annotations) | 574 all_annotations) |
566 | 575 |
567 def any_annotation_matches(annotations, all_annotations): | 576 def any_annotation_matches(annotations, all_annotations): |
568 return any( | 577 return any( |
569 ak in all_annotations and (av is None or av == all_annotations[ak]) | 578 ak in all_annotations and (av is None or av == all_annotations[ak]) |
570 for ak, av in annotations.iteritems()) | 579 for ak, av in annotations.iteritems()) |
571 | 580 |
572 filtered_classes = [] | 581 filtered_classes = [] |
573 for c in tests: | 582 for c in tests: |
574 filtered_methods = [] | 583 filtered_methods = [] |
575 for m in c['methods']: | 584 for m in c['methods']: |
576 # Gtest filtering | 585 # Gtest filtering |
577 if not gtest_filter(c, m): | 586 if not gtest_filter(c, m): |
578 continue | 587 continue |
579 | 588 |
580 all_annotations = dict(c['annotations']) | 589 all_annotations = dict(c['annotations']) |
581 all_annotations.update(m['annotations']) | 590 all_annotations.update(m['annotations']) |
591 | |
592 # Enforce that all tests declare their size. | |
593 if not any(a in _VALID_ANNOTATIONS for a in all_annotations): | |
594 raise MissingSizeAnnotationError('%s.%s' % (c['class'], m['method'])) | |
595 | |
582 if (not annotation_filter(all_annotations) | 596 if (not annotation_filter(all_annotations) |
583 or not excluded_annotation_filter(all_annotations)): | 597 or not excluded_annotation_filter(all_annotations)): |
584 continue | 598 continue |
585 | 599 |
586 filtered_methods.append(m) | 600 filtered_methods.append(m) |
587 | 601 |
588 if filtered_methods: | 602 if filtered_methods: |
589 filtered_class = dict(c) | 603 filtered_class = dict(c) |
590 filtered_class['methods'] = filtered_methods | 604 filtered_class['methods'] = filtered_methods |
591 filtered_classes.append(filtered_class) | 605 filtered_classes.append(filtered_class) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 def GenerateTestResults( | 656 def GenerateTestResults( |
643 result_code, result_bundle, statuses, start_ms, duration_ms): | 657 result_code, result_bundle, statuses, start_ms, duration_ms): |
644 return GenerateTestResults(result_code, result_bundle, statuses, | 658 return GenerateTestResults(result_code, result_bundle, statuses, |
645 start_ms, duration_ms) | 659 start_ms, duration_ms) |
646 | 660 |
647 #override | 661 #override |
648 def TearDown(self): | 662 def TearDown(self): |
649 if self._isolate_delegate: | 663 if self._isolate_delegate: |
650 self._isolate_delegate.Clear() | 664 self._isolate_delegate.Clear() |
651 | 665 |
OLD | NEW |