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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 self.assertEqual(self.registry.GetDepotDir('mock_depot'), '/mock/src/foo') | 408 self.assertEqual(self.registry.GetDepotDir('mock_depot'), '/mock/src/foo') |
409 | 409 |
410 def testChangedTheDirectory(self): | 410 def testChangedTheDirectory(self): |
411 self.registry.ChangeToDepotDir('mock_depot') | 411 self.registry.ChangeToDepotDir('mock_depot') |
412 self.assertEqual(self.cur_dir, '/mock/src/foo') | 412 self.assertEqual(self.cur_dir, '/mock/src/foo') |
413 | 413 |
414 | 414 |
415 # The tests below test private functions (W0212). | 415 # The tests below test private functions (W0212). |
416 # pylint: disable=W0212 | 416 # pylint: disable=W0212 |
417 class GitTryJobTestCases(unittest.TestCase): | 417 class GitTryJobTestCases(unittest.TestCase): |
| 418 |
418 """Test case for bisect try job.""" | 419 """Test case for bisect try job.""" |
419 def setUp(self): | 420 def setUp(self): |
420 bisect_utils_patcher = mock.patch('bisect_perf_regression.bisect_utils') | 421 bisect_utils_patcher = mock.patch('bisect_perf_regression.bisect_utils') |
421 self.mock_bisect_utils = bisect_utils_patcher.start() | 422 self.mock_bisect_utils = bisect_utils_patcher.start() |
422 self.addCleanup(bisect_utils_patcher.stop) | 423 self.addCleanup(bisect_utils_patcher.stop) |
423 | 424 |
424 def _SetupRunGitMock(self, git_cmds): | 425 def _SetupRunGitMock(self, git_cmds): |
425 """Setup RunGit mock with expected output for given git command.""" | 426 """Setup RunGit mock with expected output for given git command.""" |
426 def side_effect(git_cmd_args): | 427 def side_effect(git_cmd_args): |
427 for val in git_cmds: | 428 for val in git_cmds: |
428 if set(val[0]) == set(git_cmd_args): | 429 if set(val[0]) == set(git_cmd_args): |
429 return val[1] | 430 return val[1] |
430 self.mock_bisect_utils.RunGit = mock.Mock(side_effect=side_effect) | 431 self.mock_bisect_utils.RunGit = mock.Mock(side_effect=side_effect) |
431 | 432 |
432 def _AssertRunGitExceptions(self, git_cmds, func, *args): | 433 def _AssertRunGitExceptions(self, git_cmds, func, *args): |
433 """Setup RunGit mock and tests RunGitException. | 434 """Setup RunGit mock and tests RunGitException. |
434 | 435 |
435 Args: | 436 Args: |
436 git_cmds: List of tuples with git command and expected output. | 437 git_cmds: List of tuples with git command and expected output. |
437 func: Callback function to be executed. | 438 func: Callback function to be executed. |
438 args: List of arguments to be passed to the function. | 439 args: List of arguments to be passed to the function. |
439 """ | 440 """ |
440 self._SetupRunGitMock(git_cmds) | 441 self._SetupRunGitMock(git_cmds) |
441 self.assertRaises(bisect_perf_regression.RunGitError, | 442 self.assertRaises(bisect_perf_regression.RunGitError, |
442 func, | 443 func, |
443 *args) | 444 *args) |
444 | 445 |
445 def testNotGitRepo(self): | 446 def testNotGitRepo(self): |
446 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | 447 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH |
447 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | 448 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH |
448 cmds = [(['rev-parse', '--abbrev-ref', 'HEAD'], (None, 128))] | 449 cmds = [(['rev-parse', '--abbrev-ref', 'HEAD'], (None, 128))] |
449 self._AssertRunGitExceptions(cmds, | 450 self._AssertRunGitExceptions(cmds, |
450 bisect_perf_regression._PrepareBisectBranch, | 451 bisect_perf_regression._PrepareBisectBranch, |
451 parent_branch, new_branch) | 452 parent_branch, new_branch) |
452 | 453 |
453 def testFailedCheckoutMaster(self): | 454 def testFailedCheckoutMaster(self): |
454 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | 455 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH |
455 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | 456 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH |
456 cmds = [ | 457 cmds = [ |
457 (['rev-parse', '--abbrev-ref', 'HEAD'], (new_branch, 0)), | 458 (['rev-parse', '--abbrev-ref', 'HEAD'], (new_branch, 0)), |
458 (['checkout', '-f', parent_branch], ('Checkout Failed', 1))] | 459 (['checkout', '-f', parent_branch], ('Checkout Failed', 1)), |
| 460 ] |
459 self._AssertRunGitExceptions(cmds, | 461 self._AssertRunGitExceptions(cmds, |
460 bisect_perf_regression._PrepareBisectBranch, | 462 bisect_perf_regression._PrepareBisectBranch, |
461 parent_branch, new_branch) | 463 parent_branch, new_branch) |
462 | 464 |
463 def testDeleteBisectBranchIfExists(self): | 465 def testDeleteBisectBranchIfExists(self): |
464 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | 466 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH |
465 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | 467 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH |
466 cmds = [ | 468 cmds = [ |
467 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | 469 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), |
468 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | 470 (['branch', '--list'], ('bisect-tryjob\n*master\nsomebranch', 0)), |
469 (['branch', '-D', new_branch], ('Failed to delete branch', 128)) | 471 (['branch', '-D', new_branch], ('Failed to delete branch', 128)), |
470 ] | 472 ] |
471 self._AssertRunGitExceptions(cmds, | 473 self._AssertRunGitExceptions(cmds, |
472 bisect_perf_regression._PrepareBisectBranch, | 474 bisect_perf_regression._PrepareBisectBranch, |
473 parent_branch, new_branch) | 475 parent_branch, new_branch) |
474 | 476 |
475 def testCreatNewBranchFails(self): | 477 def testCreatNewBranchFails(self): |
476 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | 478 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH |
477 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | 479 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH |
478 cmds = [ | 480 cmds = [ |
479 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | 481 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), |
480 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | 482 (['branch', '--list'], ('bisect-tryjob\n*master\nsomebranch', 0)), |
481 (['branch', '-D', new_branch], ('None', 0)), | 483 (['branch', '-D', new_branch], ('None', 0)), |
482 (['update-index', '--refresh', '-q'], (None, 0)), | 484 (['update-index', '--refresh', '-q'], (None, 0)), |
483 (['diff-index', 'HEAD'], (None, 0)), | 485 (['diff-index', 'HEAD'], (None, 0)), |
484 (['checkout', '-b', new_branch], ('Failed to create branch', 128)) | 486 (['checkout', '-b', new_branch], ('Failed to create branch', 128)), |
485 ] | 487 ] |
486 | |
487 self._AssertRunGitExceptions(cmds, | 488 self._AssertRunGitExceptions(cmds, |
488 bisect_perf_regression._PrepareBisectBranch, | 489 bisect_perf_regression._PrepareBisectBranch, |
489 parent_branch, new_branch) | 490 parent_branch, new_branch) |
490 | 491 |
491 def testSetUpstreamToFails(self): | 492 def testSetUpstreamToFails(self): |
492 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | 493 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH |
493 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | 494 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH |
494 cmds = [ | 495 cmds = [ |
495 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | 496 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), |
496 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | 497 (['branch', '--list'], ('bisect-tryjob\n*master\nsomebranch', 0)), |
497 (['branch', '-D', new_branch], ('None', 0)), | 498 (['branch', '-D', new_branch], ('None', 0)), |
498 (['update-index', '--refresh', '-q'], (None, 0)), | 499 (['update-index', '--refresh', '-q'], (None, 0)), |
499 (['diff-index', 'HEAD'], (None, 0)), | 500 (['diff-index', 'HEAD'], (None, 0)), |
500 (['checkout', '-b', new_branch], ('None', 0)), | 501 (['checkout', '-b', new_branch], ('None', 0)), |
501 (['branch', '--set-upstream-to', parent_branch], | 502 (['branch', '--set-upstream-to', parent_branch], |
502 ('Setuptream fails', 1)) | 503 ('Setuptream fails', 1)), |
503 ] | 504 ] |
504 self._AssertRunGitExceptions(cmds, | 505 self._AssertRunGitExceptions(cmds, |
505 bisect_perf_regression._PrepareBisectBranch, | 506 bisect_perf_regression._PrepareBisectBranch, |
506 parent_branch, new_branch) | 507 parent_branch, new_branch) |
| 508 |
507 def testBuilderTryJobForException(self): | 509 def testBuilderTryJobForException(self): |
508 git_revision = 'ac4a9f31fe2610bd146857bbd55d7a260003a888' | 510 git_revision = 'ac4a9f31fe2610bd146857bbd55d7a260003a888' |
509 bot_name = 'linux_perf_bisect_builder' | 511 bot_name = 'linux_perf_bisect_builder' |
510 bisect_job_name = 'testBisectJobname' | 512 bisect_job_name = 'testBisectJobname' |
511 patch = None | 513 patch = None |
512 patch_content = '/dev/null' | 514 patch_content = '/dev/null' |
513 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | 515 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH |
514 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | 516 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH |
515 try_cmd = [ | 517 try_cmd = [ |
516 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | 518 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), |
517 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | 519 (['branch', '--list'], ('bisect-tryjob\n*master\nsomebranch', 0)), |
518 (['branch', '-D', new_branch], ('None', 0)), | 520 (['branch', '-D', new_branch], ('None', 0)), |
519 (['update-index', '--refresh', '-q'], (None, 0)), | 521 (['update-index', '--refresh', '-q'], (None, 0)), |
520 (['diff-index', 'HEAD'], (None, 0)), | 522 (['diff-index', 'HEAD'], (None, 0)), |
521 (['checkout', '-b', new_branch], ('None', 0)), | 523 (['checkout', '-b', new_branch], ('None', 0)), |
522 (['branch', '--set-upstream-to', parent_branch], | 524 (['branch', '--set-upstream-to', parent_branch], |
523 ('Setuptream fails', 0)), | 525 ('Setuptream fails', 0)), |
524 (['try', | 526 (['try', |
525 '-b', bot_name, | 527 '-b', bot_name, |
526 '-r', git_revision, | 528 '-r', git_revision, |
527 '-n', bisect_job_name, | 529 '-n', bisect_job_name, |
528 '--svn_repo=%s' % bisect_perf_regression.SVN_REPO_URL, | 530 '--svn_repo=%s' % bisect_perf_regression.SVN_REPO_URL, |
529 '--diff=%s' % patch_content | 531 '--diff=%s' % patch_content |
530 ], (None, 1)) | 532 ], (None, 1)), |
531 ] | 533 ] |
532 self._AssertRunGitExceptions(try_cmd, | 534 self._AssertRunGitExceptions(try_cmd, |
533 bisect_perf_regression._BuilderTryjob, | 535 bisect_perf_regression._BuilderTryjob, |
534 git_revision, bot_name, bisect_job_name, patch) | 536 git_revision, bot_name, bisect_job_name, patch) |
535 | 537 |
536 def testBuilderTryJob(self): | 538 def testBuilderTryJob(self): |
537 git_revision = 'ac4a9f31fe2610bd146857bbd55d7a260003a888' | 539 git_revision = 'ac4a9f31fe2610bd146857bbd55d7a260003a888' |
538 bot_name = 'linux_perf_bisect_builder' | 540 bot_name = 'linux_perf_bisect_builder' |
539 bisect_job_name = 'testBisectJobname' | 541 bisect_job_name = 'testBisectJobname' |
540 patch = None | 542 patch = None |
541 patch_content = '/dev/null' | 543 patch_content = '/dev/null' |
542 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | 544 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH |
543 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | 545 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH |
544 try_cmd = [ | 546 try_cmd = [ |
545 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | 547 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), |
546 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | 548 (['branch', '--list'], ('bisect-tryjob\n*master\nsomebranch', 0)), |
547 (['branch', '-D', new_branch], ('None', 0)), | 549 (['branch', '-D', new_branch], ('None', 0)), |
548 (['update-index', '--refresh', '-q'], (None, 0)), | 550 (['update-index', '--refresh', '-q'], (None, 0)), |
549 (['diff-index', 'HEAD'], (None, 0)), | 551 (['diff-index', 'HEAD'], (None, 0)), |
550 (['checkout', '-b', new_branch], ('None', 0)), | 552 (['checkout', '-b', new_branch], ('None', 0)), |
551 (['branch', '--set-upstream-to', parent_branch], | 553 (['branch', '--set-upstream-to', parent_branch], |
552 ('Setuptream fails', 0)), | 554 ('Setuptream fails', 0)), |
553 (['try', | 555 (['try', |
554 '-b', bot_name, | 556 '-b', bot_name, |
555 '-r', git_revision, | 557 '-r', git_revision, |
556 '-n', bisect_job_name, | 558 '-n', bisect_job_name, |
557 '--svn_repo=%s' % bisect_perf_regression.SVN_REPO_URL, | 559 '--svn_repo=%s' % bisect_perf_regression.SVN_REPO_URL, |
558 '--diff=%s' % patch_content | 560 '--diff=%s' % patch_content |
559 ], (None, 0)) | 561 ], (None, 0)), |
560 ] | 562 ] |
561 self._SetupRunGitMock(try_cmd) | 563 self._SetupRunGitMock(try_cmd) |
562 bisect_perf_regression._BuilderTryjob( | 564 bisect_perf_regression._BuilderTryjob( |
563 git_revision, bot_name, bisect_job_name, patch) | 565 git_revision, bot_name, bisect_job_name, patch) |
564 | 566 |
565 | 567 |
566 if __name__ == '__main__': | 568 if __name__ == '__main__': |
567 unittest.main() | 569 unittest.main() |
| 570 |
OLD | NEW |