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 unittest | 7 import unittest |
7 | 8 |
8 from auto_bisect import source_control as source_control_module | 9 from auto_bisect import source_control as source_control_module |
9 | 10 |
10 # Special import necessary because filename contains dash characters. | 11 # Special import necessary because filename contains dash characters. |
11 bisect_perf_module = __import__('bisect-perf-regression') | 12 bisect_perf_module = __import__('bisect-perf-regression') |
12 | 13 |
| 14 def _GetBisectPerformanceMetricsInstance(): |
| 15 """Returns an instance of the BisectPerformanceMetrics class.""" |
| 16 options_dict = { |
| 17 'debug_ignore_build': True, |
| 18 'debug_ignore_sync': True, |
| 19 'debug_ignore_perf_test': True, |
| 20 'command': 'fake_command', |
| 21 'metric': 'fake/metric', |
| 22 'good_revision': 280000, |
| 23 'bad_revision': 280005, |
| 24 } |
| 25 bisect_options = bisect_perf_module.BisectOptions.FromDict(options_dict) |
| 26 source_control = source_control_module.DetermineAndCreateSourceControl( |
| 27 bisect_options) |
| 28 bisect_instance = bisect_perf_module.BisectPerformanceMetrics( |
| 29 source_control, bisect_options) |
| 30 bisect_instance.src_cwd = os.path.abspath( |
| 31 os.path.join(os.path.dirname(__file__), os.path.pardir)) |
| 32 return bisect_instance |
| 33 |
13 | 34 |
14 class BisectPerfRegressionTest(unittest.TestCase): | 35 class BisectPerfRegressionTest(unittest.TestCase): |
15 """Test case for other functions and classes in bisect-perf-regression.py.""" | 36 """Test case for other functions and classes in bisect-perf-regression.py.""" |
16 | 37 |
17 def _AssertConfidence(self, score, bad_values, good_values): | 38 def _AssertConfidence(self, score, bad_values, good_values): |
18 """Checks whether the given sets of values have a given confidence score. | 39 """Checks whether the given sets of values have a given confidence score. |
19 | 40 |
20 The score represents our confidence that the two sets of values wouldn't | 41 The score represents our confidence that the two sets of values wouldn't |
21 be as different as they are just by chance; that is, that some real change | 42 be as different as they are just by chance; that is, that some real change |
22 occurred between the two sets of values. | 43 occurred between the two sets of values. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 276628, 'chromium') | 241 276628, 'chromium') |
221 | 242 |
222 # This method doesn't reference self; it fails if an error is thrown. | 243 # This method doesn't reference self; it fails if an error is thrown. |
223 # pylint: disable=R0201 | 244 # pylint: disable=R0201 |
224 def testDryRun(self): | 245 def testDryRun(self): |
225 """Does a dry run of the bisect script. | 246 """Does a dry run of the bisect script. |
226 | 247 |
227 This serves as a smoke test to catch errors in the basic execution of the | 248 This serves as a smoke test to catch errors in the basic execution of the |
228 script. | 249 script. |
229 """ | 250 """ |
230 options_dict = { | 251 bisect_instance = _GetBisectPerformanceMetricsInstance() |
231 'debug_ignore_build': True, | 252 results = bisect_instance.Run(bisect_instance.opts.command, |
232 'debug_ignore_sync': True, | 253 bisect_instance.opts.bad_revision, |
233 'debug_ignore_perf_test': True, | 254 bisect_instance.opts.good_revision, |
234 'command': 'fake_command', | 255 bisect_instance.opts.metric) |
235 'metric': 'fake/metric', | |
236 'good_revision': 280000, | |
237 'bad_revision': 280005, | |
238 } | |
239 bisect_options = bisect_perf_module.BisectOptions.FromDict(options_dict) | |
240 source_control = source_control_module.DetermineAndCreateSourceControl( | |
241 bisect_options) | |
242 bisect_instance = bisect_perf_module.BisectPerformanceMetrics( | |
243 source_control, bisect_options) | |
244 bisect_instance.src_cwd = os.path.abspath( | |
245 os.path.join(os.path.dirname(__file__), '..')) | |
246 results = bisect_instance.Run(bisect_options.command, | |
247 bisect_options.bad_revision, | |
248 bisect_options.good_revision, | |
249 bisect_options.metric) | |
250 bisect_instance.FormatAndPrintResults(results) | 256 bisect_instance.FormatAndPrintResults(results) |
251 | 257 |
252 def testSVNFindRev(self): | 258 def testSVNFindRev(self): |
253 """Determine numerical SVN revision or Commit Position.""" | 259 """Determine numerical SVN revision or Commit Position.""" |
254 options_dict = { | 260 bisect_instance = _GetBisectPerformanceMetricsInstance() |
255 'debug_ignore_build': True, | |
256 'debug_ignore_sync': True, | |
257 'debug_ignore_perf_test': True, | |
258 'command': 'fake_command', | |
259 'metric': 'fake/metric', | |
260 'good_revision': 280000, | |
261 'bad_revision': 280005, | |
262 } | |
263 bisect_options = bisect_perf_module.BisectOptions.FromDict(options_dict) | |
264 source_control = source_control_module.DetermineAndCreateSourceControl( | |
265 bisect_options) | |
266 | |
267 cp_git_rev = '7017a81991de983e12ab50dfc071c70e06979531' | 261 cp_git_rev = '7017a81991de983e12ab50dfc071c70e06979531' |
268 self.assertEqual(291765, source_control.SVNFindRev(cp_git_rev)) | 262 self.assertEqual(291765, |
| 263 bisect_instance.source_control.SVNFindRev(cp_git_rev)) |
269 | 264 |
270 svn_git_rev = 'e6db23a037cad47299a94b155b95eebd1ee61a58' | 265 svn_git_rev = 'e6db23a037cad47299a94b155b95eebd1ee61a58' |
271 self.assertEqual(291467, source_control.SVNFindRev(svn_git_rev)) | 266 self.assertEqual(291467, |
| 267 bisect_instance.source_control.SVNFindRev(svn_git_rev)) |
| 268 |
| 269 def testUpdateDepsContent(self): |
| 270 bisect_instance = _GetBisectPerformanceMetricsInstance() |
| 271 deps_file = 'DEPS' |
| 272 # We are intentionally reading DEPS file contents instead of string literal |
| 273 # with few lines from DEPS because to check if the format we are expecting |
| 274 # to search is not changed in DEPS content. |
| 275 # TODO (prasadv): Add a separate test to validate the DEPS contents with the |
| 276 # format that bisect script expects. |
| 277 deps_contents = bisect_perf_module.ReadStringFromFile(deps_file) |
| 278 deps_key = 'v8_revision' |
| 279 depot = 'v8' |
| 280 git_revision = 'a12345789a23456789a123456789a123456789' |
| 281 updated_content = bisect_instance.UpdateDepsContents( |
| 282 deps_contents, depot, git_revision, deps_key) |
| 283 self.assertIsNotNone(updated_content) |
| 284 ss = re.compile('["\']%s["\']: ["\']%s["\']' % (deps_key, git_revision)) |
| 285 self.assertIsNotNone(re.search(ss, updated_content)) |
| 286 |
272 | 287 |
273 if __name__ == '__main__': | 288 if __name__ == '__main__': |
274 unittest.main() | 289 unittest.main() |
OLD | NEW |