Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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:])) |
| OLD | NEW |