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 | 14 |
14 def _GetBisectPerformanceMetricsInstance(): | 15 def _GetBisectPerformanceMetricsInstance(): |
15 """Returns an instance of the BisectPerformanceMetrics class.""" | 16 """Returns an instance of the BisectPerformanceMetrics class.""" |
16 options_dict = { | 17 options_dict = { |
17 'debug_ignore_build': True, | 18 'debug_ignore_build': True, |
18 'debug_ignore_sync': True, | 19 'debug_ignore_sync': True, |
19 'debug_ignore_perf_test': True, | 20 'debug_ignore_perf_test': True, |
20 'command': 'fake_command', | 21 'command': 'fake_command', |
21 'metric': 'fake/metric', | 22 'metric': 'fake/metric', |
22 'good_revision': 280000, | 23 'good_revision': 280000, |
23 'bad_revision': 280005, | 24 'bad_revision': 280005, |
24 } | 25 } |
25 bisect_options = bisect_perf_regression.BisectOptions.FromDict(options_dict) | 26 bisect_options = bisect_perf_regression.BisectOptions.FromDict(options_dict) |
26 source_control = source_control_module.DetermineAndCreateSourceControl( | 27 source_control = source_control_module.DetermineAndCreateSourceControl( |
27 bisect_options) | 28 bisect_options) |
28 bisect_instance = bisect_perf_regression.BisectPerformanceMetrics( | 29 bisect_instance = bisect_perf_regression.BisectPerformanceMetrics( |
29 source_control, bisect_options) | 30 source_control, bisect_options) |
30 return bisect_instance | 31 return bisect_instance |
31 | 32 |
32 | 33 |
33 class BisectPerfRegressionTest(unittest.TestCase): | 34 class BisectPerfRegressionTest(unittest.TestCase): |
34 """Test case for other functions and classes in bisect-perf-regression.py.""" | 35 """Test case for other functions and classes in bisect-perf-regression.py.""" |
35 | 36 |
| 37 def setUp(self): |
| 38 self.cwd = os.getcwd() |
| 39 |
| 40 def tearDown(self): |
| 41 os.chdir(self.cwd) |
| 42 |
36 def _AssertConfidence(self, score, bad_values, good_values): | 43 def _AssertConfidence(self, score, bad_values, good_values): |
37 """Checks whether the given sets of values have a given confidence score. | 44 """Checks whether the given sets of values have a given confidence score. |
38 | 45 |
39 The score represents our confidence that the two sets of values wouldn't | 46 The score represents our confidence that the two sets of values wouldn't |
40 be as different as they are just by chance; that is, that some real change | 47 be as different as they are just by chance; that is, that some real change |
41 occurred between the two sets of values. | 48 occurred between the two sets of values. |
42 | 49 |
43 Args: | 50 Args: |
44 score: Expected confidence score. | 51 score: Expected confidence score. |
45 bad_values: First list of numbers. | 52 bad_values: First list of numbers. |
46 good_values: Second list of numbers. | 53 good_values: Second list of numbers. |
47 """ | 54 """ |
48 # ConfidenceScore takes a list of lists but these lists are flattened | 55 # ConfidenceScore takes a list of lists but these lists are flattened |
49 # inside the function. | 56 # inside the function. |
50 confidence = bisect_perf_regression.ConfidenceScore( | 57 confidence = bisect_results.ConfidenceScore( |
51 [[v] for v in bad_values], | 58 [[v] for v in bad_values], |
52 [[v] for v in good_values]) | 59 [[v] for v in good_values]) |
53 self.assertEqual(score, confidence) | 60 self.assertEqual(score, confidence) |
54 | 61 |
55 def testConfidenceScore_ZeroConfidence(self): | 62 def testConfidenceScore_ZeroConfidence(self): |
56 # The good and bad sets contain the same values, so the confidence that | 63 # The good and bad sets contain the same values, so the confidence that |
57 # they're different should be zero. | 64 # they're different should be zero. |
58 self._AssertConfidence(0.0, [4, 5, 7, 6, 8, 7], [8, 7, 6, 7, 5, 4]) | 65 self._AssertConfidence(0.0, [4, 5, 7, 6, 8, 7], [8, 7, 6, 7, 5, 4]) |
59 | 66 |
60 def testConfidenceScore_MediumConfidence(self): | 67 def testConfidenceScore_MediumConfidence(self): |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 bisect_instance = _GetBisectPerformanceMetricsInstance() | 289 bisect_instance = _GetBisectPerformanceMetricsInstance() |
283 wk_rev = 'a94d028e0f2c77f159b3dac95eb90c3b4cf48c61' | 290 wk_rev = 'a94d028e0f2c77f159b3dac95eb90c3b4cf48c61' |
284 depot_path = os.path.join(bisect_perf_regression.SRC_DIR, 'third_party', | 291 depot_path = os.path.join(bisect_perf_regression.SRC_DIR, 'third_party', |
285 'WebKit') | 292 'WebKit') |
286 self.assertEqual( | 293 self.assertEqual( |
287 181660, | 294 181660, |
288 bisect_instance.source_control.GetCommitPosition(wk_rev, depot_path)) | 295 bisect_instance.source_control.GetCommitPosition(wk_rev, depot_path)) |
289 | 296 |
290 def testUpdateDepsContent(self): | 297 def testUpdateDepsContent(self): |
291 bisect_instance = _GetBisectPerformanceMetricsInstance() | 298 bisect_instance = _GetBisectPerformanceMetricsInstance() |
292 deps_file = 'DEPS' | 299 deps_file = os.path.join(bisect_perf_regression.SRC_DIR, 'DEPS') |
293 # We are intentionally reading DEPS file contents instead of string literal | 300 # We are intentionally reading DEPS file contents instead of string literal |
294 # with few lines from DEPS because to check if the format we are expecting | 301 # with few lines from DEPS because to check if the format we are expecting |
295 # to search is not changed in DEPS content. | 302 # to search is not changed in DEPS content. |
296 # TODO (prasadv): Add a separate test to validate the DEPS contents with the | 303 # TODO (prasadv): Add a separate test to validate the DEPS contents with the |
297 # format that bisect script expects. | 304 # format that bisect script expects. |
298 deps_contents = bisect_perf_regression.ReadStringFromFile(deps_file) | 305 deps_contents = bisect_perf_regression.ReadStringFromFile(deps_file) |
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_src_dir = bisect_perf_regression.SRC_DIR |
| 320 bisect_perf_regression.SRC_DIR = '/mock/src' |
| 321 self.old_chdir = os.chdir |
| 322 os.chdir = self.mockChdir |
| 323 self.old_depot_names = bisect_perf_regression.DEPOT_NAMES |
| 324 bisect_perf_regression.DEPOT_NAMES = ['mock_depot'] |
| 325 self.old_depot_deps_name = bisect_perf_regression.DEPOT_DEPS_NAME |
| 326 bisect_perf_regression.DEPOT_DEPS_NAME = {'mock_depot': {'src': 'src/foo'}} |
| 327 |
| 328 self.registry = bisect_perf_regression.DepotDirectoryRegistry() |
| 329 self.cur_dir = None |
| 330 |
| 331 def tearDown(self): |
| 332 bisect_perf_regression.SRC_DIR = self.old_src_dir |
| 333 os.chdir = self.old_chdir |
| 334 bisect_perf_regression.DEPOT_NAMES = self.old_depot_names |
| 335 bisect_perf_regression.DEPOT_DEPS_NAME = self.old_depot_deps_name |
| 336 |
| 337 def mockChdir(self, new_dir): |
| 338 self.cur_dir = new_dir |
| 339 |
| 340 def testReturnsCorrectResultForChrome(self): |
| 341 self.assertEqual(self.registry.GetDepotDir('chromium'), '/mock/src') |
| 342 |
| 343 def testReturnsCorrectResultForChromeOS(self): |
| 344 self.assertEqual(self.registry.GetDepotDir('cros'), '/mock/src/tools/cros') |
| 345 |
| 346 def testUsesDepotSpecToInitializeRegistry(self): |
| 347 self.assertEqual(self.registry.GetDepotDir('mock_depot'), '/mock/src/foo') |
| 348 |
| 349 def testChangedTheDirectory(self): |
| 350 self.registry.ChangeToDepotDir('mock_depot') |
| 351 self.assertEqual(self.cur_dir, '/mock/src/foo') |
| 352 |
| 353 |
309 if __name__ == '__main__': | 354 if __name__ == '__main__': |
310 unittest.main() | 355 unittest.main() |
OLD | NEW |