Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 'command': 'fake_command', | 107 'command': 'fake_command', |
| 108 'metric': 'fake/metric', | 108 'metric': 'fake/metric', |
| 109 'good_revision': 280000, | 109 'good_revision': 280000, |
| 110 'bad_revision': 280005, | 110 'bad_revision': 280005, |
| 111 } | 111 } |
| 112 | 112 |
| 113 # This global is a placeholder for a generator to be defined by the test cases | 113 # This global is a placeholder for a generator to be defined by the test cases |
| 114 # that use _MockRunTests. | 114 # that use _MockRunTests. |
| 115 _MockResultsGenerator = (x for x in []) | 115 _MockResultsGenerator = (x for x in []) |
| 116 | 116 |
| 117 def _MakeMockRunTests(bisect_mode_is_return_code=False): | |
| 118 def _MockRunTests(*args, **kwargs): # pylint: disable=unused-argument | |
|
qyearsley
2015/06/23 21:46:15
Nit: Since this is defined inside of another funct
| |
| 119 return _FakeTestResult( | |
| 120 _MockResultsGenerator.next(), bisect_mode_is_return_code) | |
| 117 | 121 |
| 118 def _MockRunTests(*args, **kwargs): # pylint: disable=unused-argument | 122 return _MockRunTests |
| 119 return _FakeTestResult(_MockResultsGenerator.next()) | |
| 120 | 123 |
| 121 | 124 |
| 122 def _FakeTestResult(values): | 125 def _FakeTestResult(values, bisect_mode_is_return_code): |
| 123 result_dict = {'mean': 0.0, 'std_err': 0.0, 'std_dev': 0.0, 'values': values} | 126 mean = 0.0 |
| 127 if bisect_mode_is_return_code: | |
| 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} | |
| 124 success_code = 0 | 130 success_code = 0 |
| 125 return (result_dict, success_code) | 131 return (result_dict, success_code) |
| 126 | 132 |
| 127 | 133 |
| 128 def _GetBisectPerformanceMetricsInstance(options_dict): | 134 def _GetBisectPerformanceMetricsInstance(options_dict): |
| 129 """Returns an instance of the BisectPerformanceMetrics class.""" | 135 """Returns an instance of the BisectPerformanceMetrics class.""" |
| 130 opts = bisect_perf_regression.BisectOptions.FromDict(options_dict) | 136 opts = bisect_perf_regression.BisectOptions.FromDict(options_dict) |
| 131 return bisect_perf_regression.BisectPerformanceMetrics(opts, os.getcwd()) | 137 return bisect_perf_regression.BisectPerformanceMetrics(opts, os.getcwd()) |
| 132 | 138 |
| 133 | 139 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 # Test result goes from 0 to -100 where higher is better | 374 # Test result goes from 0 to -100 where higher is better |
| 369 results = _GenericDryRun(_GetExtendedOptions(1, -100)) | 375 results = _GenericDryRun(_GetExtendedOptions(1, -100)) |
| 370 self.assertIsNone(results.error) | 376 self.assertIsNone(results.error) |
| 371 | 377 |
| 372 def _CheckAbortsEarly(self, results): | 378 def _CheckAbortsEarly(self, results): |
| 373 """Returns True if the bisect job would abort early.""" | 379 """Returns True if the bisect job would abort early.""" |
| 374 global _MockResultsGenerator | 380 global _MockResultsGenerator |
| 375 _MockResultsGenerator = (r for r in results) | 381 _MockResultsGenerator = (r for r in results) |
| 376 bisect_class = bisect_perf_regression.BisectPerformanceMetrics | 382 bisect_class = bisect_perf_regression.BisectPerformanceMetrics |
| 377 original_run_tests = bisect_class.RunPerformanceTestAndParseResults | 383 original_run_tests = bisect_class.RunPerformanceTestAndParseResults |
| 378 bisect_class.RunPerformanceTestAndParseResults = _MockRunTests | 384 bisect_class.RunPerformanceTestAndParseResults = _MakeMockRunTests() |
| 379 | 385 |
| 380 try: | 386 try: |
| 381 dry_run_results = _GenericDryRun(_GetExtendedOptions(0, 0, False)) | 387 dry_run_results = _GenericDryRun(_GetExtendedOptions(0, 0, False)) |
| 382 except StopIteration: | 388 except StopIteration: |
| 383 # If StopIteration was raised, that means that the next value after | 389 # If StopIteration was raised, that means that the next value after |
| 384 # the first two values was requested, so the job was not aborted. | 390 # the first two values was requested, so the job was not aborted. |
| 385 return False | 391 return False |
| 386 finally: | 392 finally: |
| 387 bisect_class.RunPerformanceTestAndParseResults = original_run_tests | 393 bisect_class.RunPerformanceTestAndParseResults = original_run_tests |
| 388 | 394 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 399 | 405 |
| 400 def testBisectNotAborted_ClearRegression(self): | 406 def testBisectNotAborted_ClearRegression(self): |
| 401 self.assertFalse(self._CheckAbortsEarly(CLEAR_REGRESSION)) | 407 self.assertFalse(self._CheckAbortsEarly(CLEAR_REGRESSION)) |
| 402 | 408 |
| 403 def testBisectNotAborted_BarelyRegression(self): | 409 def testBisectNotAborted_BarelyRegression(self): |
| 404 self.assertFalse(self._CheckAbortsEarly(BARELY_REGRESSION)) | 410 self.assertFalse(self._CheckAbortsEarly(BARELY_REGRESSION)) |
| 405 | 411 |
| 406 def testBisectNotAborted_MultipleValues(self): | 412 def testBisectNotAborted_MultipleValues(self): |
| 407 self.assertFalse(self._CheckAbortsEarly(MULTIPLE_VALUES)) | 413 self.assertFalse(self._CheckAbortsEarly(MULTIPLE_VALUES)) |
| 408 | 414 |
| 415 def _CheckAbortsEarlyForReturnCode(self, results): | |
| 416 """Returns True if the bisect job would abort early in return code mode.""" | |
| 417 global _MockResultsGenerator | |
| 418 _MockResultsGenerator = (r for r in results) | |
| 419 bisect_class = bisect_perf_regression.BisectPerformanceMetrics | |
| 420 original_run_tests = bisect_class.RunPerformanceTestAndParseResults | |
| 421 bisect_class.RunPerformanceTestAndParseResults = _MakeMockRunTests(True) | |
| 422 options = dict(DEFAULT_OPTIONS) | |
| 423 options.update({'bisect_mode': 'return_code'}) | |
| 424 try: | |
| 425 dry_run_results = _GenericDryRun(options) | |
| 426 except StopIteration: | |
| 427 # If StopIteration was raised, that means that the next value after | |
| 428 # the first two values was requested, so the job was not aborted. | |
| 429 return False | |
| 430 finally: | |
| 431 bisect_class.RunPerformanceTestAndParseResults = original_run_tests | |
| 432 | |
| 433 # If the job was aborted, there should be a warning about it. | |
| 434 if ('known good and known bad revisions returned same' in | |
| 435 dry_run_results.abort_reason): | |
| 436 return True | |
| 437 return False | |
| 438 | |
| 439 def testBisectAbortOn_SameReturnCode(self): | |
| 440 self.assertTrue(self._CheckAbortsEarlyForReturnCode([[0,0,0], [0,0,0]])) | |
| 441 | |
| 442 def testBisectNotAbortedOn_DifferentReturnCode(self): | |
| 443 self.assertFalse(self._CheckAbortsEarlyForReturnCode([[1,1,1], [0,0,0]])) | |
| 444 | |
| 409 def testGetCommitPosition(self): | 445 def testGetCommitPosition(self): |
| 410 cp_git_rev = '7017a81991de983e12ab50dfc071c70e06979531' | 446 cp_git_rev = '7017a81991de983e12ab50dfc071c70e06979531' |
| 411 self.assertEqual(291765, source_control.GetCommitPosition(cp_git_rev)) | 447 self.assertEqual(291765, source_control.GetCommitPosition(cp_git_rev)) |
| 412 | 448 |
| 413 svn_git_rev = 'e6db23a037cad47299a94b155b95eebd1ee61a58' | 449 svn_git_rev = 'e6db23a037cad47299a94b155b95eebd1ee61a58' |
| 414 self.assertEqual(291467, source_control.GetCommitPosition(svn_git_rev)) | 450 self.assertEqual(291467, source_control.GetCommitPosition(svn_git_rev)) |
| 415 | 451 |
| 416 def testGetCommitPositionForV8(self): | 452 def testGetCommitPositionForV8(self): |
| 417 bisect_instance = _GetBisectPerformanceMetricsInstance(DEFAULT_OPTIONS) | 453 bisect_instance = _GetBisectPerformanceMetricsInstance(DEFAULT_OPTIONS) |
| 418 v8_rev = '21d700eedcdd6570eff22ece724b63a5eefe78cb' | 454 v8_rev = '21d700eedcdd6570eff22ece724b63a5eefe78cb' |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 (None, 0)), | 743 (None, 0)), |
| 708 ] | 744 ] |
| 709 self._SetupRunGitMock(try_cmd) | 745 self._SetupRunGitMock(try_cmd) |
| 710 bisect_perf_regression._StartBuilderTryJob( | 746 bisect_perf_regression._StartBuilderTryJob( |
| 711 fetch_build.PERF_BUILDER, git_revision, bot_name, bisect_job_name, | 747 fetch_build.PERF_BUILDER, git_revision, bot_name, bisect_job_name, |
| 712 patch) | 748 patch) |
| 713 | 749 |
| 714 | 750 |
| 715 if __name__ == '__main__': | 751 if __name__ == '__main__': |
| 716 unittest.main() | 752 unittest.main() |
| OLD | NEW |