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

Side by Side Diff: scripts/slave/recipe_modules/swarming/results_merger.py

Issue 2375663003: Add json test results format support for SwarmingIsolatedScriptTest (Closed)
Patch Set: Add no cover 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
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import copy
6
7
8 def merge_test_results(shard_results_list):
9 """ Merge list of results.
10
11 Args:
12 shard_results_list: list of results to merge. All the results must have the
13 same format. Supported format are simplified JSON format & Chromium JSON
14 test results format version 3 (see
15 https://www.chromium.org/developers/the-json-test-results-format)
16
17 Returns:
18 a dictionary that represent the merged results. Its format follow the same
19 format of all results in |shard_results_list|.
20 """
21 if 'seconds_since_epoch' in shard_results_list[0]:
22 return _merge_json_test_result_format(shard_results_list)
23 else:
24 return _merge_simplified_json_format(shard_results_list)
25
26
27 def _merge_simplified_json_format(shard_results_list):
28 # This code is specialized to the "simplified" JSON format that used to be
29 # the standard for recipes.
30
31 # These are the only keys we pay attention to in the output JSON.
32 merged_results = {
33 'successes': [],
34 'failures': [],
35 'valid': True,
36 }
37
38 for result_json in shard_results_list:
39 successes = result_json.get('successes', [])
40 failures = result_json.get('failures', [])
41 valid = result_json.get('valid', True)
42
43 if (not isinstance(successes, list) or not isinstance(failures, list) or
44 not isinstance(valid, bool)):
45 raise Exception(
46 'Unexpected value type in %s' % result_json) # pragma: no cover
47
48 merged_results['successes'].extend(successes)
49 merged_results['failures'].extend(failures)
50 merged_results['valid'] = merged_results['valid'] and valid
51 return merged_results
52
53
54 def _merge_json_test_result_format(shard_results_list):
55 # This code is specialized to the Chromium JSON test results format version 3:
56 # https://www.chromium.org/developers/the-json-test-results-format
57
58 # These are required fields for the JSON test result format version 3.
59 merged_results = {
60 'tests': {},
61 'interrupted': False,
62 'path_delimiter': '',
63 'version': 3,
64 'seconds_since_epoch': float('inf'),
65 'num_failures_by_type': {
66 }
67 }
68 # To make sure that we don't mutate existing shard_results_list.
69 shard_results_list = copy.deepcopy(shard_results_list)
70 for result_json in shard_results_list:
71 if not ('tests' in result_json and
72 'interrupted' in result_json and
73 'path_delimiter' in result_json and
74 'version' in result_json and
75 'seconds_since_epoch' in result_json and
76 'num_failures_by_type' in result_json):
77 raise Exception('Invalid json test results')
78
79 # Traverse the result_json's test trie & merged_results's test tries in
80 # DFS order & add the n to merged['tests'].
81 curr_result_nodes_queue = [result_json['tests']]
82 merged_results_nodes_queue = [merged_results['tests']]
83 while curr_result_nodes_queue:
84 curr_node = curr_result_nodes_queue.pop()
85 merged_node = merged_results_nodes_queue.pop()
86 for k, v in curr_node.iteritems():
87 if k in merged_node:
88 curr_result_nodes_queue.append(v)
89 merged_results_nodes_queue.append(merged_node[k])
90 else:
91 merged_node[k] = v
92
93 # Update the rest of the fields for merged_results.
94 merged_results['interrupted'] |= result_json['interrupted']
95 if not merged_results['path_delimiter']:
96 merged_results['path_delimiter'] = result_json['path_delimiter']
97 elif merged_results['path_delimiter'] != result_json['path_delimiter']:
98 raise Exception( # pragma: no cover - covered by results_merger_unittest
99 'Incosistent path delimiter: %s %s' %
100 (merged_results['path_delimiter'],
101 result_json['path_delimiter']))
102 if result_json['version'] != 3:
103 raise Exception( # pragma: no cover - covered by results_merger_unittest
104 'Only version 3 of json test result format is supported')
105 merged_results['seconds_since_epoch'] = min(
106 merged_results['seconds_since_epoch'],
107 result_json['seconds_since_epoch'])
108 for result_type, count in result_json['num_failures_by_type'].iteritems():
109 merged_results['num_failures_by_type'].setdefault(result_type, 0)
110 merged_results['num_failures_by_type'][result_type] += count
111 return merged_results
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/swarming/api.py ('k') | scripts/slave/recipe_modules/swarming/tests/results_merger_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698