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

Side by Side Diff: scripts/slave/recipe_modules/swarming/resources/collect_gtest_task.py

Issue 2372713003: Reland of Size limit gtest collect (Closed)
Patch Set: Fix size limit. Created 4 years, 2 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 | « 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 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 import json 6 import json
7 import optparse 7 import optparse
8 import os 8 import os
9 import shutil 9 import shutil
10 import subprocess 10 import subprocess
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 MISSING_SHARDS_MSG % as_str) 88 MISSING_SHARDS_MSG % as_str)
89 # Not all tests run, combined JSON summary can not be trusted. 89 # Not all tests run, combined JSON summary can not be trusted.
90 merged['global_tags'].add('UNRELIABLE_RESULTS') 90 merged['global_tags'].add('UNRELIABLE_RESULTS')
91 91
92 # Convert to jsonish dict. 92 # Convert to jsonish dict.
93 for key in ('all_tests', 'disabled_tests', 'global_tags'): 93 for key in ('all_tests', 'disabled_tests', 'global_tags'):
94 merged[key] = sorted(merged[key]) 94 merged[key] = sorted(merged[key])
95 return merged 95 return merged
96 96
97 97
98 # 100 MB
99 OUTPUT_JSON_SIZE_LIMIT = 100 * 1024 * 1024
100
101
98 def load_shard_json(output_dir, index): 102 def load_shard_json(output_dir, index):
99 """Reads JSON output of a single shard.""" 103 """Reads JSON output of a single shard."""
100 # 'output.json' is set in swarming/api.py, gtest_task method. 104 # 'output.json' is set in swarming/api.py, gtest_task method.
101 path = os.path.join(output_dir, str(index), 'output.json') 105 path = os.path.join(output_dir, str(index), 'output.json')
102 try: 106 try:
107 filesize = os.stat(path).st_size
108 if filesize > OUTPUT_JSON_SIZE_LIMIT:
Vadim Sh. 2016/09/27 00:10:56 please log this to stderr
109 raise ValueError()
110
103 with open(path) as f: 111 with open(path) as f:
104 return json.load(f) 112 return json.load(f)
105 except (IOError, ValueError): 113 except (IOError, ValueError):
Vadim Sh. 2016/09/27 00:10:56 catch OSError here, since os.stat can raise it now
106 print >> sys.stderr, 'Missing or invalid gtest JSON file: %s' % path 114 print >> sys.stderr, 'Missing or invalid gtest JSON file: %s' % path
107 return None 115 return None
108 116
109 117
110 def merge_list_of_dicts(left, right): 118 def merge_list_of_dicts(left, right):
111 """Merges dicts left[0] with right[0], left[1] with right[1], etc.""" 119 """Merges dicts left[0] with right[0], left[1] with right[1], etc."""
112 output = [] 120 output = []
113 for i in xrange(max(len(left), len(right))): 121 for i in xrange(max(len(left), len(right))):
114 left_dict = left[i] if i < len(left) else {} 122 left_dict = left[i] if i < len(left) else {}
115 right_dict = right[i] if i < len(right) else {} 123 right_dict = right[i] if i < len(right) else {}
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 'failed to process gtest output JSON', traceback.format_exc()) 198 'failed to process gtest output JSON', traceback.format_exc())
191 199
192 finally: 200 finally:
193 shutil.rmtree(task_output_dir, ignore_errors=True) 201 shutil.rmtree(task_output_dir, ignore_errors=True)
194 202
195 return exit_code 203 return exit_code
196 204
197 205
198 if __name__ == '__main__': 206 if __name__ == '__main__':
199 sys.exit(main(sys.argv[1:])) 207 sys.exit(main(sys.argv[1:]))
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