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

Side by Side Diff: tools/android/find_disabled_tests.py

Issue 1853333004: Find disabled tests by creating instrumentation test instances (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « build/android/pylib/instrumentation/instrumentation_test_instance.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Finds all the disabled tests from proguard dump"""
7
8 import argparse
9 import datetime
10 import json
11 import linecache
12 import logging
13 import os
14 import re
15 import sys
16 import time
17 import pprint
18
19
20 _SRC_DIR = os.path.abspath(os.path.join(
21 os.path.dirname(__file__), '..', '..'))
22
23 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android'))
24 from pylib import constants
25 from pylib.instrumentation.instrumentation_test_instance import (
26 InstrumentationTestInstance)
27
28 sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil'))
29 from devil.utils import cmd_helper
30
31 _DISABLED_TESTS_ANNOTATION_LIST = {'DisabledTest': None, 'FlakyTest': None}
32 _GIT_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
33 _EXPORT_TIME_FORMAT = '%Y%m%dT%H%M%S'
34
35 class JSONKeyName(object):
36 TEST_MASTER_KEY = 'tests'
37 RECORD_MASTER_KEY = 'records'
38 REVISION_KEY = 'revision'
39 STATUS_KEY = 'status'
40 TEST_NAME_KEY = 'name'
41 CRBUG_KEY = 'bug_id'
42 CLASS_PATH_KEY = 'class_path'
43 CLASS_NAME_KEY = 'class_name'
44 DF_TEST_AMOUNT_KEY = 'df_test_amount'
45 TOTAL_TEST_AMOUNT_KEY = 'total_test_amount'
46 UTC_BUILDTIME_KEY = 'utc_buildtime'
47 UTC_REVISIONTIME_KEY = 'utc_revisiontime'
48 PLATFORM_KEY = 'platform'
49 PLATFORM_VALUE = 'android'
50
51 def _SerializeTests(arguments):
52 """Create instrumentation test instance and extract disabled tests info"""
53 total_test_amount = 0
54 disabled_test_list = []
55 for test_apk in arguments.test_apks:
56 arguments.test_apk = test_apk
57 test_instance = InstrumentationTestInstance(arguments, None, logging.error)
58 disabled_test_list.extend(test_instance.GetFilteredTests())
59 total_test_amount += test_instance.TotalTestAmount()
60 result = []
61 for test_class in disabled_test_list:
62 class_path = test_class['class']
63 class_name = test_class['class'].split('.')[-1]
64 for test_method in test_class['methods']:
65 # getting annotation of each test case
66 bug_id = None
67 status = []
68 test_annotations = test_method['annotations']
69 assert len(test_annotations) != 0
70 for annotation, content in test_annotations.iteritems():
71 if content is not None:
72 bug_id = content['message']
73 status.append(annotation)
74 # getting test method name of each test
75 test_name = test_method['method']
76 test_dict = {
77 JSONKeyName.CRBUG_KEY: bug_id,
78 JSONKeyName.STATUS_KEY: status,
79 JSONKeyName.TEST_NAME_KEY: test_name,
80 JSONKeyName.CLASS_NAME_KEY: class_name,
81 JSONKeyName.CLASS_PATH_KEY: class_path
82 }
83 result.append(test_dict)
84 return result, total_test_amount
85
86 def _AddRecord(disabled_test_list, utc_buildtime_string, total_test_amount):
87 disabled_test_number = len(disabled_test_list)
88
89 revision = cmd_helper.GetCmdOutput(['git', 'rev-parse', 'HEAD']).strip()
90 raw_time_string = cmd_helper.GetCmdOutput(
91 ['git', 'log', '--pretty=format:%aI', '--max-count=1', 'HEAD'])
92 time_string_search = re.search(r'\d+-\d+-\d+T\d+:\d+:\d+', raw_time_string)
93 if time_string_search is None:
94 raise Exception('Time format incorrect')
95
96 revision_time = time.strptime(time_string_search.group(0), _GIT_TIME_FORMAT)
97 utc_revision_time = datetime.datetime.utcfromtimestamp(
98 time.mktime(revision_time))
99 utc_revision_time = utc_revision_time.strftime(_EXPORT_TIME_FORMAT)
100
101 record_data = [{
102 JSONKeyName.REVISION_KEY: revision,
103 JSONKeyName.UTC_BUILDTIME_KEY: utc_buildtime_string,
104 JSONKeyName.UTC_REVISIONTIME_KEY: utc_revision_time,
105 JSONKeyName.PLATFORM_KEY: JSONKeyName.PLATFORM_VALUE,
106 JSONKeyName.DF_TEST_AMOUNT_KEY: disabled_test_number,
107 JSONKeyName.TOTAL_TEST_AMOUNT_KEY: total_test_amount
108 }]
109 return record_data
110
111 def main():
112 default_build_type = os.environ.get('BUILDTYPE', 'Debug')
113 parser = argparse.ArgumentParser()
114 parser.add_argument('-t', '--test-apks', action='append', default=[],
115 dest='test_apks', help='List all test apks file name ' +
116 'that the script uses to fetch disabled tests from')
117 parser.add_argument('--test_apk_incremental_install_script')
118 parser.add_argument(
119 '--debug', action='store_const', const='Debug', dest='build_type',
120 default=default_build_type,
121 help=('If set, run test suites under out/Debug. '
122 'Default is env var BUILDTYPE or Debug.'))
123 parser.add_argument('-o', '--output-path',
124 help='JSON file output to be uploaded on to gcs')
125 parser.add_argument('-a', '--annotations', dest='annotations',
126 action='append', default=['DisabledTest', 'FlakyTest'],
127 help='Disabled tests annotations, seperated by ,' +
128 'e.g. --annotation-str=DisabledTest,FlakyTest')
129
130 arguments = parser.parse_args(sys.argv[1:])
131 arguments.annotation_str = ','.join(arguments.annotations)
132 arguments.additional_apks = []
133 arguments.apk_under_test = None
134 arguments.apk_under_test_incremental_install_script = None
135 arguments.test_apk_incremental_install_script = None
136 arguments.isolate_file_path = None
137 arguments.test_data = None
138 arguments.test_filter = None
139 arguments.exclude_annotation_str = None
140 arguments.timeout_scale = None
141 constants.SetBuildType(arguments.build_type)
142
143 buildtime = datetime.datetime.utcnow()
144 buildtime_string = buildtime.strftime('%Y%m%dT%H%M%S')
145 test_data, total_test_amount = _SerializeTests(arguments)
146 record_data = _AddRecord(test_data, buildtime_string, total_test_amount)
147
148 if arguments.output_path is None:
149 output_path = constants.GetOutDirectory()
150 else:
151 output_path = arguments.output_path
152 json_output_path = os.path.join(output_path,
153 '%s-android-chrome.json' % buildtime_string)
154 export_data = {
155 JSONKeyName.RECORD_MASTER_KEY: record_data,
156 JSONKeyName.TEST_MASTER_KEY: test_data
157 }
158 with open(json_output_path, 'w') as f:
159 json.dump(export_data, f, indent=2, sort_keys=True)
160
161 if __name__ == "__main__":
162 main()
OLDNEW
« no previous file with comments | « build/android/pylib/instrumentation/instrumentation_test_instance.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698