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

Side by Side Diff: scripts/slave/recipe_modules/test_results/resources/upload_test_results.py

Issue 2464843003: Revert of [recipe_modules/test_results] Refactor the logic of generating full json results files (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """See README.md for usage instructions. 6 """See README.md for usage instructions.
7 7
8 This file heavily modified from build/scripts/slave/gtest_slave_utils.py and 8 This file heavily modified from build/scripts/slave/gtest_slave_utils.py and
9 is intended to replace it as all tests move to swarming. 9 is intended to replace it as all tests move to swarming.
10 TODO(estaab): Remove build/scripts/slave/gtest.* once this is fully deployed. 10 TODO(estaab): Remove build/scripts/slave/gtest.* once this is fully deployed.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 for test, results in result_sets.iteritems(): 42 for test, results in result_sets.iteritems():
43 for result in results: 43 for result in results:
44 result = test_result.TestResult( 44 result = test_result.TestResult(
45 test, 45 test,
46 status=result['status'], 46 status=result['status'],
47 elapsed_time=result.get('elapsed_time_ms', 0) / 1000.) 47 elapsed_time=result.get('elapsed_time_ms', 0) / 1000.)
48 test_results_map.setdefault(test, []).append(result) 48 test_results_map.setdefault(test, []).append(result)
49 return test_results_map 49 return test_results_map
50 50
51 51
52 def generate_json_results_file(results_json, builder_name, build_number, 52 def generate_json_results(test_results_map, builder_name, build_number,
53 results_directory, chrome_revision, master_name): 53 results_directory, chrome_revision, master_name):
54 """Generates JSON results files from the given |results_json|. 54 """Generates JSON results files from the given test_results_map.
55 55
56 Args: 56 Args:
57 results_json: the raw test results object that follows GTest format. 57 test_results_map: A map of TestResult.
58 """ 58 """
59 results_map = get_results_map_from_json(results_json)
60 if not os.path.exists(results_directory): 59 if not os.path.exists(results_directory):
61 os.makedirs(results_directory) 60 os.makedirs(results_directory)
62 61
63 print('Generating json: ' 62 print('Generating json: '
64 'builder_name:%s, build_number:%s, ' 63 'builder_name:%s, build_number:%s, '
65 'results_directory:%s, ' 64 'results_directory:%s, '
66 'chrome_revision:%s ' 65 'chrome_revision:%s '
67 'master_name:%s' % 66 'master_name:%s' %
68 (builder_name, build_number, 67 (builder_name, build_number,
69 results_directory, 68 results_directory,
70 chrome_revision, 69 chrome_revision,
71 master_name)) 70 master_name))
72 71
73 # TODO(estaab): This doesn't need to be an object. Make it a simple function. 72 # TODO(estaab): This doesn't need to be an object. Make it a simple function.
74 generator = JSONResultsGenerator( 73 generator = JSONResultsGenerator(
75 builder_name, build_number, 74 builder_name, build_number,
76 results_directory, 75 results_directory,
77 test_results_map, 76 test_results_map,
78 svn_revisions=[('chromium', chrome_revision)], 77 svn_revisions=[('chromium', chrome_revision)],
79 master_name=master_name) 78 master_name=master_name)
80 generator.generate_json_output() 79 generator.generate_json_output()
81 generator.generate_times_ms_file() 80 generator.generate_times_ms_file()
82 return [(f, os.path.join(results_directory, f)) for f in
83 (FULL_RESULTS_FILENAME, TIMES_MS_FILENAME)]
84 81
85 82
86 def main(): 83 def main():
87 option_parser = optparse.OptionParser() 84 option_parser = optparse.OptionParser()
88 option_parser.add_option('--test-type', 85 option_parser.add_option('--test-type',
89 help='Test type that generated the results json,' 86 help='Test type that generated the results json,'
90 ' e.g. unit-tests.') 87 ' e.g. unit-tests.')
91 option_parser.add_option('--results-directory', default=os.getcwd(), 88 option_parser.add_option('--results-directory', default=os.getcwd(),
92 help='Output results directory source dir.') 89 help='Output results directory source dir.')
93 option_parser.add_option('--input-json', 90 option_parser.add_option('--input-json',
(...skipping 27 matching lines...) Expand all
121 if not options.input_json: 118 if not options.input_json:
122 option_parser.error('--input-json needs to be specified.') 119 option_parser.error('--input-json needs to be specified.')
123 return 1 120 return 1
124 121
125 if options.test_results_server and not options.master_name: 122 if options.test_results_server and not options.master_name:
126 logging.warn('--test-results-server is given but ' 123 logging.warn('--test-results-server is given but '
127 '--master-name is not specified; the results won\'t be ' 124 '--master-name is not specified; the results won\'t be '
128 'uploaded to the server.') 125 'uploaded to the server.')
129 126
130 with file(options.input_json) as json_file: 127 with file(options.input_json) as json_file:
131 results_json = json_file.read() 128 results_map = get_results_map_from_json(json_file.read())
132 129
133 files = generate_json_results_file( 130 generate_json_results(results_map, options.builder_name,
134 results_json, builder_name=options.builder_name, 131 options.build_number, options.results_directory,
135 builder_number=options.build_number, 132 options.chrome_revision, options.master_name)
136 results_directory=options.results_directory,
137 chrome_revision=options.chrome_revision,
138 master_name=options.master_name)
139 133
140 # Upload to a test results server if specified. 134 # Upload to a test results server if specified.
141 if options.test_results_server and options.master_name: 135 if options.test_results_server and options.master_name:
142 print 'Uploading JSON files for builder "%s" to server "%s"' % ( 136 print 'Uploading JSON files for builder "%s" to server "%s"' % (
143 options.builder_name, options.test_results_server) 137 options.builder_name, options.test_results_server)
144 attrs = [('builder', options.builder_name), 138 attrs = [('builder', options.builder_name),
145 ('testtype', options.test_type), 139 ('testtype', options.test_type),
146 ('master', options.master_name)] 140 ('master', options.master_name)]
147 141
142 files = [(f, os.path.join(options.results_directory, f)) for f in
143 (FULL_RESULTS_FILENAME, TIMES_MS_FILENAME)]
144
148 # Set uploading timeout in case appengine server is having problem. 145 # Set uploading timeout in case appengine server is having problem.
149 # 120 seconds are more than enough to upload test results. 146 # 120 seconds are more than enough to upload test results.
150 test_results_uploader.upload_test_results( 147 test_results_uploader.upload_test_results(
151 options.test_results_server, attrs, files, 120) 148 options.test_results_server, attrs, files, 120)
152 return 0 149 return 0
153 150
154 151
155 if __name__ == '__main__': 152 if __name__ == '__main__':
156 sys.exit(main()) 153 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698