OLD | NEW |
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 Loading... |
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(gtest_json, builder_name, build_number, | 52 def generate_json_results_file_for_json( |
53 results_directory, chrome_revision, master_name): | 53 results_json, builder_name, build_number, |
| 54 results_directory, chrome_revision, master_name): |
| 55 """Generates JSON results file from the given |results_json|. |
| 56 |
| 57 Args: |
| 58 results_json: the raw test results object that follows full json results |
| 59 format. |
| 60 |
| 61 Returns: |
| 62 A list that contains a single tuple (<file name>, <file path>). The tuple |
| 63 represents the full test results file. |
| 64 """ |
| 65 if not os.path.exists(results_directory): |
| 66 os.makedirs(results_directory) |
| 67 json_results_file_path = os.path.abspath( |
| 68 os.path.join(results_directory, FULL_RESULTS_FILENAME)) |
| 69 results_json['builder_name'] = builder_name |
| 70 results_json['build_number'] = build_number |
| 71 results_json['chromium_revision'] = chrome_revision |
| 72 results_json['master_name'] = master_name |
| 73 with open(json_results_file_path, 'w') as f: |
| 74 json.dump(results_json, f) |
| 75 return [(FULL_RESULTS_FILENAME, json_results_file_path)] |
| 76 |
| 77 |
| 78 def generate_json_results_file_for_gtest( |
| 79 gtest_json, builder_name, build_number, results_directory, chrome_revision, |
| 80 master_name): |
54 """Generates JSON results files from the given |gtest_json|. | 81 """Generates JSON results files from the given |gtest_json|. |
55 | 82 |
56 Args: | 83 Args: |
57 gtest_json: the raw test results object that follows GTest format. | 84 gtest_json: the raw test results object that follows GTest format. |
58 | 85 |
59 Returns: | 86 Returns: |
60 A list of tuples (<file name>, <file path>). The list has two | 87 A list of tuples (<file name>, <file path>). The list has two |
61 elements: the first represent the full test results file, and the | 88 elements: the first represent the full test results file, and the |
62 second is is the times_ms.json file. | 89 second is is the times_ms.json file. |
63 """ | 90 """ |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 logging.warn('--test-results-server is given but ' | 158 logging.warn('--test-results-server is given but ' |
132 '--master-name is not specified; the results won\'t be ' | 159 '--master-name is not specified; the results won\'t be ' |
133 'uploaded to the server.') | 160 'uploaded to the server.') |
134 | 161 |
135 with file(options.input_json) as json_file: | 162 with file(options.input_json) as json_file: |
136 results_json = json_file.read() | 163 results_json = json_file.read() |
137 | 164 |
138 content = json.loads(results_json) | 165 content = json.loads(results_json) |
139 if content.get('version', 0) >= 3: | 166 if content.get('version', 0) >= 3: |
140 print 'Input JSON file probably has full json results format' | 167 print 'Input JSON file probably has full json results format' |
141 files = [(FULL_RESULTS_FILENAME, os.path.abspath(options.input_json))] | 168 files = generate_json_results_file_for_json( |
| 169 content, builder_name=options.builder_name, |
| 170 build_number=options.build_number, |
| 171 results_directory=options.results_directory, |
| 172 chrome_revision=options.chrome_revision, |
| 173 master_name=options.master_name) |
142 else: | 174 else: |
143 print ('Input JSON file probably has gtest format. Converting to full json' | 175 print ('Input JSON file probably has gtest format. Converting to full json' |
144 ' results format') | 176 ' results format') |
145 files = generate_json_results_file( | 177 files = generate_json_results_file_for_gtest( |
146 results_json, builder_name=options.builder_name, | 178 results_json, builder_name=options.builder_name, |
147 build_number=options.build_number, | 179 build_number=options.build_number, |
148 results_directory=options.results_directory, | 180 results_directory=options.results_directory, |
149 chrome_revision=options.chrome_revision, | 181 chrome_revision=options.chrome_revision, |
150 master_name=options.master_name) | 182 master_name=options.master_name) |
151 | 183 |
152 # Upload to a test results server if specified. | 184 # Upload to a test results server if specified. |
153 if options.test_results_server and options.master_name: | 185 if options.test_results_server and options.master_name: |
154 print 'Uploading JSON files for builder "%s" to server "%s"' % ( | 186 print 'Uploading JSON files for builder "%s" to server "%s"' % ( |
155 options.builder_name, options.test_results_server) | 187 options.builder_name, options.test_results_server) |
156 attrs = [('builder', options.builder_name), | 188 attrs = [('builder', options.builder_name), |
157 ('testtype', options.test_type), | 189 ('testtype', options.test_type), |
158 ('master', options.master_name)] | 190 ('master', options.master_name)] |
159 | 191 |
160 # Set uploading timeout in case appengine server is having problem. | 192 # Set uploading timeout in case appengine server is having problem. |
161 # 120 seconds are more than enough to upload test results. | 193 # 120 seconds are more than enough to upload test results. |
162 test_results_uploader.upload_test_results( | 194 test_results_uploader.upload_test_results( |
163 options.test_results_server, attrs, files, 120) | 195 options.test_results_server, attrs, files, 120) |
164 return 0 | 196 return 0 |
165 | 197 |
166 | 198 |
167 if __name__ == '__main__': | 199 if __name__ == '__main__': |
168 sys.exit(main(sys.argv[1:])) | 200 sys.exit(main(sys.argv[1:])) |
OLD | NEW |