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

Side by Side Diff: scripts/slave/recipe_modules/auto_bisect/test_api.py

Issue 2247373002: Refactor stages 1, 2 and test_api overhaul. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Created 4 years, 4 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 2015 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 import math
5
6 from collections import defaultdict
7
8 from recipe_engine import recipe_test_api
9
10
11 class AutoBisectTestApi(recipe_test_api.RecipeTestApi):
12
13 def compare_samples_data(self, data, rev_a, rev_b):
14 values_a = data[rev_a.commit_hash]['parsed_values'][:rev_a.test_run_count]
15 values_b = data[rev_b.commit_hash]['parsed_values'][:rev_b.test_run_count]
16 while len(values_a) < rev_a.test_run_count:
17 if values_a:
18 values_a.append(values_a[-1])
19 else:
20 values_a.append(0)
21
22 while len(values_b) < rev_b.test_run_count:
23 if values_b:
24 values_b.append(values_b[-1])
25 else:
26 values_b.append(0)
27
28 avg = lambda x: sum(x)/float((len(x) or 1))
29 mean_a = avg(values_a)
30 mean_b = avg(values_b)
31 var_a = map (lambda x: (x - mean_a) ** 2, values_a)
32 var_b = map (lambda x: (x - mean_b) ** 2, values_b)
33 std_dev_a = math.sqrt(avg(var_a))
34 std_dev_b = math.sqrt(avg(var_b))
35 result = 'needMoreData'
36 if len(values_a) >= 5 and len(values_b) >= 5:
37 if mean_a != mean_b:
38 result = True
39 if len(values_a) >= 18 and len(values_b) >= 18:
40 if mean_a == mean_b:
41 result = False
42 return self.m.json.output_stream(
43 {
44 'sample_a': {
45 'debug_values': values_a,
46 'mean': mean_a,
47 'std_dev': std_dev_a
48 },
49 'sample_b': {
50 'debug_values': values_b,
51 'mean': mean_b,
52 'std_dev': std_dev_b,
53 },
54 'result': result
55 })
56
57 @recipe_test_api.mod_test_data
58 def hash_cp_map(self, items):
59 result = {}
60 for item in items:
61 if 'hash' in item and 'commit_pos' in item:
62 result[item['commit_pos']] = self.m.json.output_stream(
63 {'git_sha': item['hash']})
64 return result
65
66 @recipe_test_api.mod_test_data
67 @staticmethod
68 def revision_data(items):
69 result = {}
70 for item in items:
71 if 'hash' in item:
72 result[item['hash']] = item
73 return result
74
75 @recipe_test_api.mod_test_data
76 def revision_list(self, items):
77 result = {}
78 for item in items:
79 if 'hash' in item:
80 depot = item.get('depot', 'chromium')
81 result.setdefault(depot, [])
82 result[depot].append([item['hash'], item.get('commit_pos')])
83 # Exclude the ends of the revision range.
84 result['chromium'] = result['chromium'][1:-1]
85 for depot in result:
86 result[depot] = self.m.json.output_stream(result[depot])
87 return result
88
89 @recipe_test_api.mod_test_data
90 def deps_change(self, items):
91 # If the revision has the key DEPS_change, we mock the result of git show to
92 # appear as if DEPS was among the files changed by the CL.
93 result = {}
94 for item in items:
95 if 'hash' in item:
96 git_output = ''
97 if 'DEPS_change' in item:
98 git_output = 'DEPS'
99 result[item['hash']] = self.m.raw_io.stream_output(git_output)
100 return result
101
102 @recipe_test_api.mod_test_data
103 def diff_patch(self):
104 return self.m.raw_io.stream_output("""
105 diff --git a/DEPS b/DEPS
106 index 029be3b..2b3ea0a 100644
107 --- a/DEPS
108 +++ b/DEPS
109 @@ -13,7 +13,7 @@ deps = {
110 '@98fc59a5896f4ea990a4d527548204fed8f06c64',
111 'build/third_party/infra_libs':
112 'https://chromium.googlesource.com/infra/infra/packages/infra_libs.git'
113 - '@a13e6745a4edd01fee683e4157ea0195872e64eb',
114 + '@15ea0920b5f83d0aff4bd042e95bc388d069d51c',
115 'build/third_party/lighttpd':
116 'https://chromium.googlesource.com/chromium/deps/lighttpd.git'
117 '@9dfa55d15937a688a92cbf2b7a8621b0927d06eb',
118 """)
119
120 @recipe_test_api.mod_test_data
121 def deps(self, items):
122 result = {}
123 for item in items:
124 if 'hash' in item:
125 deps_content = ''
126 if 'DEPS' in item:
127 deps_content = item['DEPS']
128 result[item['hash']] = self.m.raw_io.stream_output(deps_content)
129 return result
130
131 @recipe_test_api.mod_test_data
132 def run_results(self, items):
133 def single_result(v):
134 return self.m.raw_io.stream_output(
135 data = v.get('stdout', 'text from actual benchmark, (ignored)'),
136 retcode = v.get('retcode', 0))
137
138 result = {'default': recipe_test_api.StepTestData()}
139 for item in items:
140 if 'hash' in item and 'test_results' in item:
141 result[item['hash']] = [single_result(v) for v in item['test_results']]
142 return result
143
144 @recipe_test_api.mod_test_data
145 def cl_info(self, items):
146 result = {}
147 for item in items:
148 if 'hash' in item:
149 if 'cl_info' in item:
150 info = item['cl_info']
151 else:
152 info = {}
153 result[item['hash']] = self.m.json.output_stream(info)
154 return result
155
156 def __call__(self, config_items):
157 return (
158 self.revision_data(config_items)
159 + self.hash_cp_map(config_items)
160 + self.revision_list(config_items)
161 + self.run_results(config_items)
162 + self.deps_change(config_items)
163 + self.deps(config_items)
164 + self.cl_info (config_items)
165 + self.diff_patch()
166 )
167
168 # """Takes massive dictionary to populate test_data for all steps."""
169 # get commit hash
170 # get test results(gsutil) ?
171 # fetch deps
172 # generating patch
173 # reading culprit information
174 # expanding revision range
175 # hashing modified deps
176 # fetch builder state
177 # fetch build details
178 # (check image) gsutil
179 #
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698