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

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

Issue 1782333002: Add bisect config validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Rebased Created 4 years, 9 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 | scripts/slave/recipe_modules/auto_bisect/config_validation.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import re 6 import re
7 import time 7 import time
8 import urllib 8 import urllib
9 9
10 from . import config_validation
10 from . import depot_config 11 from . import depot_config
11 from . import revision_state 12 from . import revision_state
12 13
13 _DEPS_SHA_PATCH = """ 14 _DEPS_SHA_PATCH = """
14 diff --git DEPS.sha DEPS.sha 15 diff --git DEPS.sha DEPS.sha
15 new file mode 100644 16 new file mode 100644
16 --- /dev/null 17 --- /dev/null
17 +++ DEPS.sha 18 +++ DEPS.sha
18 @@ -0,0 +1 @@ 19 @@ -0,0 +1 @@
19 +%(deps_sha)s 20 +%(deps_sha)s
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 """This class abstracts an ongoing bisect (or n-sect) job.""" 69 """This class abstracts an ongoing bisect (or n-sect) job."""
69 70
70 def __init__(self, api, bisect_config, revision_class, init_revisions=True): 71 def __init__(self, api, bisect_config, revision_class, init_revisions=True):
71 """Initializes the state of a new bisect job from a dictionary. 72 """Initializes the state of a new bisect job from a dictionary.
72 73
73 Note that the initial good_rev and bad_rev MUST resolve to a commit position 74 Note that the initial good_rev and bad_rev MUST resolve to a commit position
74 in the chromium repo. 75 in the chromium repo.
75 """ 76 """
76 super(Bisector, self).__init__() 77 super(Bisector, self).__init__()
77 self._api = api 78 self._api = api
79 self.result_codes = set()
78 self.ensure_sync_master_branch() 80 self.ensure_sync_master_branch()
79 self.bisect_config = bisect_config 81 self.bisect_config = bisect_config
80 self.config_step() 82 self.config_step()
83 self._validate_config()
81 self.revision_class = revision_class 84 self.revision_class = revision_class
82 self.result_codes = set()
83 self.last_tested_revision = None 85 self.last_tested_revision = None
84 86
85 # Test-only properties. 87 # Test-only properties.
86 # TODO: Replace these with proper mod_test_data. 88 # TODO: Replace these with proper mod_test_data.
87 self.dummy_builds = bisect_config.get('dummy_builds', False) 89 self.dummy_builds = bisect_config.get('dummy_builds', False)
88 self.bypass_stats_check = bool(bisect_config.get('bypass_stats_check')) 90 self.bypass_stats_check = bool(bisect_config.get('bypass_stats_check'))
89 91
90 # Load configuration items. 92 # Load configuration items.
91 self.test_type = bisect_config.get('test_type', 'perf') 93 self.test_type = bisect_config.get('test_type', 'perf')
92 self.improvement_direction = int(bisect_config.get( 94 self.improvement_direction = int(bisect_config.get(
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 results = step_result.stdout 184 results = step_result.stdout
183 if results is None: 185 if results is None:
184 assert self.dummy_builds 186 assert self.dummy_builds
185 return True 187 return True
186 significantly_different = results['significantly_different'] 188 significantly_different = results['significantly_different']
187 step_result.presentation.logs[str(significantly_different)] = [ 189 step_result.presentation.logs[str(significantly_different)] = [
188 'See json.output for details'] 190 'See json.output for details']
189 return significantly_different 191 return significantly_different
190 192
191 def config_step(self): 193 def config_step(self):
192 """Yields a simple echo step that outputs the bisect config.""" 194 """Yields a step that prints the bisect config."""
193 api = self.api 195 api = self.api
196
194 # bisect_config may come as a FrozenDict (which is not serializable). 197 # bisect_config may come as a FrozenDict (which is not serializable).
195 bisect_config = dict(self.bisect_config) 198 bisect_config = dict(self.bisect_config)
196 199
197 def fix_windows_backslashes(s): 200 def fix_windows_backslashes(s):
198 backslash_regex = re.compile(r'(?<!\\)\\(?!\\)') 201 backslash_regex = re.compile(r'(?<!\\)\\(?!\\)')
199 return backslash_regex.sub(r'\\', s) 202 return backslash_regex.sub(r'\\', s)
200 203
201 for k, v in bisect_config.iteritems(): 204 for k, v in bisect_config.iteritems():
202 if isinstance(v, basestring): 205 if isinstance(v, basestring):
203 bisect_config[k] = fix_windows_backslashes(v) 206 bisect_config[k] = fix_windows_backslashes(v)
207
204 # We sort the keys to prevent problems with orders changing when 208 # We sort the keys to prevent problems with orders changing when
205 # recipe_simulation_test compares against expectation files. 209 # recipe_simulation_test compares against expectation files.
206 config_string = json.dumps(bisect_config, indent=2, sort_keys=True) 210 config_string = json.dumps(bisect_config, indent=2, sort_keys=True)
207 result = api.m.step('config', []) 211 step = api.m.step('config', [])
208 config_lines = config_string.splitlines() 212 config_lines = config_string.splitlines()
209 result.presentation.logs['Bisect job configuration'] = config_lines 213 step.presentation.logs['Bisect job configuration'] = config_lines
214
215 def _validate_config(self):
216 """Raises an error and halts the bisect job if the config is invalid."""
217 try:
218 config_validation.validate_bisect_config(self.bisect_config)
219 except config_validation.ValidationFail as error:
220 self.surface_result('BAD_CONFIG')
221 self.api.m.halt(error.message)
222 raise self.api.m.step.StepFailure(error.message)
210 223
211 @property 224 @property
212 def api(self): 225 def api(self):
213 return self._api 226 return self._api
214 227
215 def compute_relative_change(self): 228 def compute_relative_change(self):
216 old_value = float(self.good_rev.mean_value) 229 old_value = float(self.good_rev.mean_value)
217 new_value = float(self.bad_rev.mean_value) 230 new_value = float(self.bad_rev.mean_value)
218 231
219 if new_value and not old_value: # pragma: no cover 232 if new_value and not old_value: # pragma: no cover
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 }) 857 })
845 return revision_rows 858 return revision_rows
846 859
847 def _get_build_url(self): 860 def _get_build_url(self):
848 properties = self.api.m.properties 861 properties = self.api.m.properties
849 bot_url = properties.get('buildbotURL', 862 bot_url = properties.get('buildbotURL',
850 'http://build.chromium.org/p/chromium/') 863 'http://build.chromium.org/p/chromium/')
851 builder_name = urllib.quote(properties.get('buildername', '')) 864 builder_name = urllib.quote(properties.get('buildername', ''))
852 builder_number = str(properties.get('buildnumber', '')) 865 builder_number = str(properties.get('buildnumber', ''))
853 return '%sbuilders/%s/builds/%s' % (bot_url, builder_name, builder_number) 866 return '%sbuilders/%s/builds/%s' % (bot_url, builder_name, builder_number)
OLDNEW
« no previous file with comments | « no previous file | scripts/slave/recipe_modules/auto_bisect/config_validation.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698