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

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

Issue 2375663003: Add json test results format support for SwarmingIsolatedScriptTest (Closed)
Patch Set: Address Sergiy comments 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('Unexpected value type in %s' % result_json)
46
47 merged_results['successes'].extend(successes)
48 merged_results['failures'].extend(failures)
49 merged_results['valid'] = merged_results['valid'] and valid
50 return merged_results
51
52
53 def _merge_json_test_result_format(shard_results_list):
54 # This code is specialized to the Chromium JSON test results format version 3:
55 # https://www.chromium.org/developers/the-json-test-results-format
56
57 # These are required fields for the JSON test result format version 3.
58 merged_results = {
59 'tests': {},
60 'interrupted': False,
61 'path_delimiter': '',
62 'version': 3,
63 'seconds_since_epoch': float('inf'),
64 'num_failures_by_type': {
65 }
66 }
67 # To make sure that we don't mutate existing shard_results_list.
68 shard_results_list = copy.deepcopy(shard_results_list)
69 for result_json in shard_results_list:
70 if not ('tests' in result_json and
71 'interrupted' in result_json and
72 'path_delimiter' in result_json and
73 'version' in result_json and
74 'seconds_since_epoch' in result_json and
75 'num_failures_by_type' in result_json):
76 raise Exception('Invalid json test results')
77
78 # Traverse the result_json's test trie & merged_results's test tries in
79 # DFS order & add the n to merged['tests'].
80 curr_result_nodes_queue = [result_json['tests']]
81 merged_results_nodes_queue = [merged_results['tests']]
82 while curr_result_nodes_queue:
83 curr_node = curr_result_nodes_queue.pop()
84 merged_node = merged_results_nodes_queue.pop()
85 for k, v in curr_node.iteritems():
86 if k in merged_node:
87 curr_result_nodes_queue.append(v)
88 merged_results_nodes_queue.append(merged_node[k])
89 else:
90 merged_node[k] = v
91
92 # Update the rest of the fields for merged_results.
93 merged_results['interrupted'] |= result_json['interrupted']
94 if not merged_results['path_delimiter']:
95 merged_results['path_delimiter'] = result_json['path_delimiter']
96 elif merged_results['path_delimiter'] != result_json['path_delimiter']:
97 raise Exception( # pragma: no cover - covered by results_merger_unittest
98 'Incosistent path delimiter: %s %s' %
99 (merged_results['path_delimiter'],
100 result_json['path_delimiter']))
101 if result_json['version'] != 3:
102 raise Exception( # pragma: no cover - covered by results_merger_unittest
103 'Only version 3 of json test result format is supported')
104 merged_results['seconds_since_epoch'] = min(
105 merged_results['seconds_since_epoch'],
106 result_json['seconds_since_epoch'])
107 for result_type, count in result_json['num_failures_by_type'].iteritems():
108 merged_results['num_failures_by_type'].setdefault(result_type, 0)
109 merged_results['num_failures_by_type'][result_type] += count
110 return merged_results
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698