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

Side by Side Diff: tools/auto_bisect/bisect_perf_regression_test.py

Issue 1625573004: Update legacy bisect to post results to perf dashboard. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_import_path
Patch Set: update doc Created 4 years, 11 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
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 os 5 import os
6 import re 6 import re
7 import shutil 7 import shutil
8 import sys 8 import sys
9 import unittest 9 import unittest
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 def _FakeTestResult(values, bisect_mode_is_return_code): 125 def _FakeTestResult(values, bisect_mode_is_return_code):
126 mean = 0.0 126 mean = 0.0
127 if bisect_mode_is_return_code: 127 if bisect_mode_is_return_code:
128 mean = 0 if (all(v == 0 for v in values)) else 1 128 mean = 0 if (all(v == 0 for v in values)) else 1
129 result_dict = {'mean': mean, 'std_err': 0.0, 'std_dev': 0.0, 'values': values} 129 result_dict = {'mean': mean, 'std_err': 0.0, 'std_dev': 0.0, 'values': values}
130 success_code = 0 130 success_code = 0
131 return (result_dict, success_code) 131 return (result_dict, success_code)
132 132
133 133
134 def _GetMockCallArg(function_mock, call_index):
135 """Gets the list of called arguements for call at "call_index".
qyearsley 2016/01/26 18:08:01 arguements -> arguments "call_index" -> |call_ind
chrisphan 2016/02/10 02:23:38 Done.
136
137 Args:
138 function_mock: A Mock object.
139 call_index: The index at which the mocked function was called.
qyearsley 2016/01/26 18:08:00 Is this the index in the sequence of calls? e.g. 0
chrisphan 2016/02/10 02:23:38 That's correct.
140
141 Returns:
142 The called argument list.
143 """
144 call_args_list = function_mock.call_args_list
145 if not call_args_list or len(call_args_list) <= call_index:
146 return None
147 args, _ = call_args_list[call_index]
148 return args
149
150
134 def _GetBisectPerformanceMetricsInstance(options_dict): 151 def _GetBisectPerformanceMetricsInstance(options_dict):
135 """Returns an instance of the BisectPerformanceMetrics class.""" 152 """Returns an instance of the BisectPerformanceMetrics class."""
136 opts = bisect_perf_regression.BisectOptions.FromDict(options_dict) 153 opts = bisect_perf_regression.BisectOptions.FromDict(options_dict)
137 return bisect_perf_regression.BisectPerformanceMetrics(opts, os.getcwd()) 154 return bisect_perf_regression.BisectPerformanceMetrics(opts, os.getcwd())
138 155
139 156
140 def _GetExtendedOptions(improvement_dir, fake_first, ignore_confidence=True, 157 def _GetExtendedOptions(improvement_dir, fake_first, ignore_confidence=True,
141 **extra_opts): 158 **extra_opts):
142 """Returns the a copy of the default options dict plus some options.""" 159 """Returns the a copy of the default options dict plus some options."""
143 result = dict(DEFAULT_OPTIONS) 160 result = dict(DEFAULT_OPTIONS)
144 result.update({ 161 result.update({
145 'improvement_direction': improvement_dir, 162 'improvement_direction': improvement_dir,
146 'debug_fake_first_test_mean': fake_first, 163 'debug_fake_first_test_mean': fake_first,
147 'debug_ignore_regression_confidence': ignore_confidence 164 'debug_ignore_regression_confidence': ignore_confidence
148 }) 165 })
149 result.update(extra_opts) 166 result.update(extra_opts)
150 return result 167 return result
151 168
152 169
153 def _GenericDryRun(options, print_results=False): 170 def _GenericDryRun(options, print_results=False):
154 """Performs a dry run of the bisector. 171 """Performs a dry run of the bisector.
155 172
156 Args: 173 Args:
157 options: Dictionary containing the options for the bisect instance. 174 options: Dictionary containing the options for the bisect instance.
158 print_results: Boolean telling whether to call FormatAndPrintResults. 175 print_results: Boolean telling whether to call FormatAndPrintResults.
159 176
160 Returns: 177 Returns:
161 The results dictionary as returned by the bisect Run method. 178 The results dictionary as returned by the bisect Run method.
162 """ 179 """
163 _AbortIfThereAreStagedChanges() 180 #_AbortIfThereAreStagedChanges()
qyearsley 2016/01/26 18:08:00 Uncomment
chrisphan 2016/02/10 02:23:38 Done.
164 # Disable rmtree to avoid deleting local trees. 181 # Disable rmtree to avoid deleting local trees.
165 old_rmtree = shutil.rmtree 182 old_rmtree = shutil.rmtree
166 shutil.rmtree = lambda path, on_error: None 183 shutil.rmtree = lambda path, on_error: None
167 # git reset HEAD may be run during the dry run, which removes staged changes. 184 # git reset HEAD may be run during the dry run, which removes staged changes.
168 try: 185 try:
169 bisect_instance = _GetBisectPerformanceMetricsInstance(options) 186 bisect_instance = _GetBisectPerformanceMetricsInstance(options)
170 results = bisect_instance.Run( 187 results = bisect_instance.Run(
171 bisect_instance.opts.command, bisect_instance.opts.bad_revision, 188 bisect_instance.opts.command, bisect_instance.opts.bad_revision,
172 bisect_instance.opts.good_revision, bisect_instance.opts.metric) 189 bisect_instance.opts.good_revision, bisect_instance.opts.metric)
173 190
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 329
313 def testBisectImprovementDirectionSucceeds(self): 330 def testBisectImprovementDirectionSucceeds(self):
314 """Bisects with improvement direction matching regression range.""" 331 """Bisects with improvement direction matching regression range."""
315 # Test result goes from 0 to 100 where lower is better 332 # Test result goes from 0 to 100 where lower is better
316 results = _GenericDryRun(_GetExtendedOptions(-1, 100)) 333 results = _GenericDryRun(_GetExtendedOptions(-1, 100))
317 self.assertIsNone(results.error) 334 self.assertIsNone(results.error)
318 # Test result goes from 0 to -100 where higher is better 335 # Test result goes from 0 to -100 where higher is better
319 results = _GenericDryRun(_GetExtendedOptions(1, -100)) 336 results = _GenericDryRun(_GetExtendedOptions(1, -100))
320 self.assertIsNone(results.error) 337 self.assertIsNone(results.error)
321 338
339 @mock.patch('urllib2.urlopen')
340 def testBisectResultsPosted(self, mock_urlopen):
341 """Bisects with improvement direction matching regression range."""
qyearsley 2016/01/26 18:08:00 Docstring should be deleted or updated.
chrisphan 2016/02/10 02:23:38 Done.
342 # Test result goes from 0 to 100 where lower is better
qyearsley 2016/01/26 18:08:01 This comment appears to be unrelated.
chrisphan 2016/02/10 02:23:38 Done.
343 options_dict = dict(DEFAULT_OPTIONS)
344 options_dict.update({
345 'bisect_mode': bisect_utils.BISECT_MODE_MEAN,
346 'try_job_id': 1234,
347 })
348 opts = bisect_perf_regression.BisectOptions.FromDict(options_dict)
349 results = _GenericDryRun(options_dict, True)
350 bisect_perf_regression._PostBisectResults(results, opts, os.getcwd())
qyearsley 2016/01/26 18:08:00 Optional: Because the purpose of this test method
chrisphan 2016/02/10 02:23:38 Done.
351
352 call_args = _GetMockCallArg(mock_urlopen, 0)
353 self.assertIsNotNone(call_args)
354 self.assertIn('"try_job_id": 1234', call_args[1])
355
322 def _CheckAbortsEarly(self, results, **extra_opts): 356 def _CheckAbortsEarly(self, results, **extra_opts):
323 """Returns True if the bisect job would abort early.""" 357 """Returns True if the bisect job would abort early."""
324 global _MockResultsGenerator 358 global _MockResultsGenerator
325 _MockResultsGenerator = (r for r in results) 359 _MockResultsGenerator = (r for r in results)
326 bisect_class = bisect_perf_regression.BisectPerformanceMetrics 360 bisect_class = bisect_perf_regression.BisectPerformanceMetrics
327 original_run_tests = bisect_class.RunPerformanceTestAndParseResults 361 original_run_tests = bisect_class.RunPerformanceTestAndParseResults
328 bisect_class.RunPerformanceTestAndParseResults = _MakeMockRunTests() 362 bisect_class.RunPerformanceTestAndParseResults = _MakeMockRunTests()
329 363
330 try: 364 try:
331 dry_run_results = _GenericDryRun(_GetExtendedOptions( 365 dry_run_results = _GenericDryRun(_GetExtendedOptions(
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 (None, 0)), 721 (None, 0)),
688 ] 722 ]
689 self._SetupRunGitMock(try_cmd) 723 self._SetupRunGitMock(try_cmd)
690 bisect_perf_regression._StartBuilderTryJob( 724 bisect_perf_regression._StartBuilderTryJob(
691 fetch_build.PERF_BUILDER, git_revision, bot_name, bisect_job_name, 725 fetch_build.PERF_BUILDER, git_revision, bot_name, bisect_job_name,
692 patch) 726 patch)
693 727
694 728
695 if __name__ == '__main__': 729 if __name__ == '__main__':
696 unittest.main() 730 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698