| 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 unittest | 8 import unittest |
| 9 | 9 |
| 10 import bisect_perf_regression | 10 import bisect_perf_regression |
| 11 import bisect_results |
| 11 import source_control as source_control_module | 12 import source_control as source_control_module |
| 12 | 13 |
| 13 def _GetBisectPerformanceMetricsInstance(): | 14 def _GetBisectPerformanceMetricsInstance(): |
| 14 """Returns an instance of the BisectPerformanceMetrics class.""" | 15 """Returns an instance of the BisectPerformanceMetrics class.""" |
| 15 options_dict = { | 16 options_dict = { |
| 16 'debug_ignore_build': True, | 17 'debug_ignore_build': True, |
| 17 'debug_ignore_sync': True, | 18 'debug_ignore_sync': True, |
| 18 'debug_ignore_perf_test': True, | 19 'debug_ignore_perf_test': True, |
| 19 'command': 'fake_command', | 20 'command': 'fake_command', |
| 20 'metric': 'fake/metric', | 21 'metric': 'fake/metric', |
| 21 'good_revision': 280000, | 22 'good_revision': 280000, |
| 22 'bad_revision': 280005, | 23 'bad_revision': 280005, |
| 23 } | 24 } |
| 24 bisect_options = bisect_perf_regression.BisectOptions.FromDict(options_dict) | 25 bisect_options = bisect_perf_regression.BisectOptions.FromDict(options_dict) |
| 25 source_control = source_control_module.DetermineAndCreateSourceControl( | 26 source_control = source_control_module.DetermineAndCreateSourceControl( |
| 26 bisect_options) | 27 bisect_options) |
| 27 bisect_instance = bisect_perf_regression.BisectPerformanceMetrics( | 28 bisect_instance = bisect_perf_regression.BisectPerformanceMetrics( |
| 28 source_control, bisect_options) | 29 source_control, bisect_options) |
| 29 bisect_instance.src_cwd = os.path.abspath( | |
| 30 os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) | |
| 31 return bisect_instance | 30 return bisect_instance |
| 32 | 31 |
| 33 | 32 |
| 34 class BisectPerfRegressionTest(unittest.TestCase): | 33 class BisectPerfRegressionTest(unittest.TestCase): |
| 35 """Test case for other functions and classes in bisect-perf-regression.py.""" | 34 """Test case for other functions and classes in bisect-perf-regression.py.""" |
| 36 | 35 |
| 36 def setUp(self): |
| 37 self.cwd = os.getcwd() |
| 38 os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), |
| 39 os.path.pardir, os.path.pardir))) |
| 40 |
| 41 def tearDown(self): |
| 42 os.chdir(self.cwd) |
| 43 |
| 37 def _AssertConfidence(self, score, bad_values, good_values): | 44 def _AssertConfidence(self, score, bad_values, good_values): |
| 38 """Checks whether the given sets of values have a given confidence score. | 45 """Checks whether the given sets of values have a given confidence score. |
| 39 | 46 |
| 40 The score represents our confidence that the two sets of values wouldn't | 47 The score represents our confidence that the two sets of values wouldn't |
| 41 be as different as they are just by chance; that is, that some real change | 48 be as different as they are just by chance; that is, that some real change |
| 42 occurred between the two sets of values. | 49 occurred between the two sets of values. |
| 43 | 50 |
| 44 Args: | 51 Args: |
| 45 score: Expected confidence score. | 52 score: Expected confidence score. |
| 46 bad_values: First list of numbers. | 53 bad_values: First list of numbers. |
| 47 good_values: Second list of numbers. | 54 good_values: Second list of numbers. |
| 48 """ | 55 """ |
| 49 # ConfidenceScore takes a list of lists but these lists are flattened | 56 # ConfidenceScore takes a list of lists but these lists are flattened |
| 50 # inside the function. | 57 # inside the function. |
| 51 confidence = bisect_perf_regression.ConfidenceScore( | 58 confidence = bisect_results.ConfidenceScore( |
| 52 [[v] for v in bad_values], | 59 [[v] for v in bad_values], |
| 53 [[v] for v in good_values]) | 60 [[v] for v in good_values]) |
| 54 self.assertEqual(score, confidence) | 61 self.assertEqual(score, confidence) |
| 55 | 62 |
| 56 def testConfidenceScore_ZeroConfidence(self): | 63 def testConfidenceScore_ZeroConfidence(self): |
| 57 # The good and bad sets contain the same values, so the confidence that | 64 # The good and bad sets contain the same values, so the confidence that |
| 58 # they're different should be zero. | 65 # they're different should be zero. |
| 59 self._AssertConfidence(0.0, [4, 5, 7, 6, 8, 7], [8, 7, 6, 7, 5, 4]) | 66 self._AssertConfidence(0.0, [4, 5, 7, 6, 8, 7], [8, 7, 6, 7, 5, 4]) |
| 60 | 67 |
| 61 def testConfidenceScore_MediumConfidence(self): | 68 def testConfidenceScore_MediumConfidence(self): |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 deps_key = 'v8_revision' | 306 deps_key = 'v8_revision' |
| 300 depot = 'v8' | 307 depot = 'v8' |
| 301 git_revision = 'a12345789a23456789a123456789a123456789' | 308 git_revision = 'a12345789a23456789a123456789a123456789' |
| 302 updated_content = bisect_instance.UpdateDepsContents( | 309 updated_content = bisect_instance.UpdateDepsContents( |
| 303 deps_contents, depot, git_revision, deps_key) | 310 deps_contents, depot, git_revision, deps_key) |
| 304 self.assertIsNotNone(updated_content) | 311 self.assertIsNotNone(updated_content) |
| 305 ss = re.compile('["\']%s["\']: ["\']%s["\']' % (deps_key, git_revision)) | 312 ss = re.compile('["\']%s["\']: ["\']%s["\']' % (deps_key, git_revision)) |
| 306 self.assertIsNotNone(re.search(ss, updated_content)) | 313 self.assertIsNotNone(re.search(ss, updated_content)) |
| 307 | 314 |
| 308 | 315 |
| 316 class DepotDirectoryRegistryTest(unittest.TestCase): |
| 317 |
| 318 def setUp(self): |
| 319 self.old_chdir = os.chdir |
| 320 os.chdir = self.mockChdir |
| 321 self.old_depot_names = bisect_perf_regression.DEPOT_NAMES |
| 322 bisect_perf_regression.DEPOT_NAMES = ['mock_depot'] |
| 323 self.old_depot_deps_name = bisect_perf_regression.DEPOT_DEPS_NAME |
| 324 bisect_perf_regression.DEPOT_DEPS_NAME = {'mock_depot': {'src': 'src/foo'}} |
| 325 |
| 326 self.registry = bisect_perf_regression.DepotDirectoryRegistry('/mock/src') |
| 327 self.cur_dir = None |
| 328 |
| 329 def tearDown(self): |
| 330 os.chdir = self.old_chdir |
| 331 bisect_perf_regression.DEPOT_NAMES = self.old_depot_names |
| 332 bisect_perf_regression.DEPOT_DEPS_NAME = self.old_depot_deps_name |
| 333 |
| 334 def mockChdir(self, new_dir): |
| 335 self.cur_dir = new_dir |
| 336 |
| 337 def testReturnsCorrectResultForChrome(self): |
| 338 self.assertEqual(self.registry.GetDepotDir('chromium'), '/mock/src') |
| 339 |
| 340 def testReturnsCorrectResultForChromeOS(self): |
| 341 self.assertEqual(self.registry.GetDepotDir('cros'), '/mock/src/tools/cros') |
| 342 |
| 343 def testUsesDepotSpecToInitializeRegistry(self): |
| 344 self.assertEqual(self.registry.GetDepotDir('mock_depot'), '/mock/src/foo') |
| 345 |
| 346 def testChangedTheDirectory(self): |
| 347 self.registry.ChangeToDepotDir('mock_depot') |
| 348 self.assertEqual(self.cur_dir, '/mock/src/foo') |
| 349 |
| 350 |
| 309 if __name__ == '__main__': | 351 if __name__ == '__main__': |
| 310 unittest.main() | 352 unittest.main() |
| OLD | NEW |