Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: build/android/pylib/instrumentation/instrumentation_test_instance.py

Issue 1863353002: 🎯 Fail if an instrumentation test is missing size annotation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add annotation for SiteSettingsPreferencesTest.java Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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', 'PerfTest'] + _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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698