Example #1
0
    def testCrosVersionToChromeCommitFail(self):
        """Tests failure case of CrosVersionToChromeCommit()."""
        metadata_url = (
            'gs://chromeos-image-archive/%s-release/%s/partial-metadata.json' %
            (self.BOARD, self.GOOD_CROS_VERSION))
        gs_mock = self.StartPatcher(gs_unittest.GSContextMock())
        gs_mock.AddCmdResult(['cat', metadata_url], returncode=1)

        self.bisector.gs_ctx = gs.GSContext()
        self.assertIsNone(
            self.bisector.CrosVersionToChromeCommit(self.GOOD_CROS_VERSION))

        metadata_content = 'not_a_json'
        gs_mock.AddCmdResult(['cat', metadata_url], output=metadata_content)
        self.assertIsNone(
            self.bisector.CrosVersionToChromeCommit(self.GOOD_CROS_VERSION))

        metadata_content = '\n'.join([
            '{', '  "metadata-version": "2",',
            '  "toolchain-url": "2017/05/%(target)s-2017.05.25.101355.tar.xz",',
            '  "suite_scheduling": true,', '  "build_id": 1644146,',
            '  "version": {}', '}'
        ])
        gs_mock.AddCmdResult(['cat', metadata_url], output=metadata_content)
        self.assertIsNone(
            self.bisector.CrosVersionToChromeCommit(self.GOOD_CROS_VERSION))

        gs_mock.AddCmdResult(['cat', metadata_url],
                             output=self.GOOD_METADATA_CONTENT)
        git_mock = self.StartPatcher(
            git_bisector_unittest.GitMock(self.repo_dir))
        git_mock.AddRunGitResult(
            ['log', '--oneline', '-n', '2', '60.0.3112.53'], returncode=128)
        self.assertIsNone(
            self.bisector.CrosVersionToChromeCommit(self.GOOD_CROS_VERSION))
Example #2
0
    def testPrepareBisect(self):
        """Tests PrepareBisect()."""
        # Pass SanityCheck().
        git_mock = self.StartPatcher(
            git_bisector_unittest.GitMock(self.repo_dir))
        git_mock.AddRunGitResult(
            partial_mock.InOrder(['rev-list', self.GOOD_COMMIT_SHA1]))
        git_mock.AddRunGitResult(
            partial_mock.InOrder(['rev-list', self.BAD_COMMIT_SHA1]))
        git_mock.AddRunGitResult(partial_mock.InOrder(
            ['show', self.GOOD_COMMIT_SHA1]),
                                 output=str(self.GOOD_COMMIT_TIMESTAMP))
        git_mock.AddRunGitResult(partial_mock.InOrder(
            ['show', self.BAD_COMMIT_SHA1]),
                                 output=str(self.BAD_COMMIT_TIMESTAMP))

        # Inject score for both side.
        git_mock.AddRunGitResult(['checkout', self.GOOD_COMMIT_SHA1])
        git_mock.AddRunGitResult(['checkout', self.BAD_COMMIT_SHA1])
        build_deploy_eval_mock = self.PatchObject(
            chrome_on_cros_bisector.ChromeOnCrosBisector, 'BuildDeployEval')
        build_deploy_eval_mock.side_effect = [
            self.GOOD_COMMIT_SCORE, self.BAD_COMMIT_SCORE
        ]

        # Set auto_threshold.
        self.bisector.auto_threshold = True

        self.assertTrue(self.bisector.PrepareBisect())
Example #3
0
    def testObtainBisectBoundaryScoreImplCrosVersionFlashError(self):
        """Tests ObtainBisectBoundaryScoreImpl() with CrOS version."""
        self.SetUpBisectorWithCrosVersion()
        # Inject good_commit and bad_commit as if
        # bisector.ResolveChromeBisectRangeFromCrosVersion() being run.
        self.bisector.good_commit = self.GOOD_COMMIT_SHA1
        self.bisector.bad_commit = self.BAD_COMMIT_SHA1

        git_mock = self.StartPatcher(
            git_bisector_unittest.GitMock(self.repo_dir))
        git_mock.AddRunGitResult(['checkout', self.GOOD_COMMIT_SHA1])
        git_mock.AddRunGitResult(['checkout', self.BAD_COMMIT_SHA1])

        self.PatchObject(chrome_on_cros_bisector.ChromeOnCrosBisector,
                         'UpdateCurrentCommit')
        evaluate_mock = self.PatchObject(DummyEvaluator, 'Evaluate')

        # Mock FlashCrosImage() to verify that customize_build_deploy is assigned
        # as expected.
        flash_cros_image_mock = self.PatchObject(
            chrome_on_cros_bisector.ChromeOnCrosBisector, 'FlashCrosImage')
        flash_cros_image_mock.side_effect = flash.FlashError('Flash failed.')

        with self.assertRaises(flash.FlashError):
            self.bisector.ObtainBisectBoundaryScoreImpl(True)

        flash_cros_image_mock.assert_called_with(
            self.bisector.GetCrosXbuddyPath(self.GOOD_CROS_VERSION))
        evaluate_mock.assert_not_called()

        with self.assertRaises(flash.FlashError):
            self.bisector.ObtainBisectBoundaryScoreImpl(False)
        flash_cros_image_mock.assert_called_with(
            self.bisector.GetCrosXbuddyPath(self.BAD_CROS_VERSION))
        evaluate_mock.assert_not_called()
Example #4
0
    def testExchangeChromeSanityCheckFlashError(self):
        """Tests the flow of exchanging Chrome between good and bad CrOS."""
        self.SetUpBisectorWithCrosVersion()

        # Inject good_commit and bad_commit as if
        # bisector.ResolveChromeBisectRangeFromCrosVersion() has been run.
        self.bisector.good_commit = self.GOOD_COMMIT_SHA1
        self.bisector.bad_commit = self.BAD_COMMIT_SHA1

        # Inject commit_info and threshold as if
        # bisector.ObtainBisectBoundaryScore() and bisector.GetThresholdFromUser()
        # has been run.
        self.SetDefaultCommitInfo()
        self.bisector.threshold = self.THRESHOLD

        # Try bad Chrome first.
        git_mock = self.StartPatcher(
            git_bisector_unittest.GitMock(self.repo_dir))
        git_mock.AddRunGitResult(['checkout', self.BAD_COMMIT_SHA1])
        git_mock.AddRunGitResult(['checkout', self.GOOD_COMMIT_SHA1])

        self.PatchObject(chrome_on_cros_bisector.ChromeOnCrosBisector,
                         'UpdateCurrentCommit')

        evaluate_mock = self.PatchObject(DummyEvaluator, 'Evaluate')

        # Mock FlashCrosImage() to verify that customize_build_deploy is assigned
        # as expected.
        flash_cros_image_mock = self.PatchObject(
            chrome_on_cros_bisector.ChromeOnCrosBisector,
            'FlashCrosImage',
            side_effect=flash.FlashError('Flash failed.'))

        build_deploy_mock = self.PatchObject(
            chrome_on_cros_bisector.ChromeOnCrosBisector, 'BuildDeploy')

        with self.assertRaises(flash.FlashError):
            self.bisector.ExchangeChromeSanityCheck()

        evaluate_mock.assert_not_called()
        flash_cros_image_mock.assert_called()
        build_deploy_mock.assert_not_called()
Example #5
0
    def testObtainBisectBoundaryScoreImpl(self):
        """Tests ObtainBisectBoundaryScoreImpl()."""
        git_mock = self.StartPatcher(
            git_bisector_unittest.GitMock(self.repo_dir))
        git_mock.AddRunGitResult(['checkout', self.GOOD_COMMIT_SHA1])
        git_mock.AddRunGitResult(['checkout', self.BAD_COMMIT_SHA1])

        build_deploy_eval_mock = self.PatchObject(
            chrome_on_cros_bisector.ChromeOnCrosBisector, 'BuildDeployEval')
        build_deploy_eval_mock.side_effect = [
            self.GOOD_COMMIT_SCORE, self.BAD_COMMIT_SCORE
        ]

        self.assertEqual(self.GOOD_COMMIT_SCORE,
                         self.bisector.ObtainBisectBoundaryScoreImpl(True))
        self.assertEqual(self.BAD_COMMIT_SCORE,
                         self.bisector.ObtainBisectBoundaryScoreImpl(False))

        self.assertEqual([
            mock.call(customize_build_deploy=None, eval_label=None),
            mock.call(customize_build_deploy=None, eval_label=None)
        ], build_deploy_eval_mock.call_args_list)
Example #6
0
    def testCrosVersionToChromeCommit(self):
        """Tests CrosVersionToChromeCommit()."""
        metadata_url = (
            'gs://chromeos-image-archive/%s-release/%s/partial-metadata.json' %
            (self.BOARD, self.GOOD_CROS_VERSION))
        gs_mock = self.StartPatcher(gs_unittest.GSContextMock())
        gs_mock.AddCmdResult(['cat', metadata_url],
                             output=self.GOOD_METADATA_CONTENT)

        git_log_content = '\n'.join([
            '8967dd66ad72 (tag: 60.0.3112.53) Publish DEPS for Chromium '
            '60.0.3112.53', '27ed0cc0c2f4 Incrementing VERSION to 60.0.3112.53'
        ])
        git_mock = self.StartPatcher(
            git_bisector_unittest.GitMock(self.repo_dir))
        git_mock.AddRunGitResult(
            ['log', '--oneline', '-n', '2', '60.0.3112.53'],
            output=git_log_content)

        self.bisector.gs_ctx = gs.GSContext()
        self.assertEqual(
            '27ed0cc0c2f4',
            self.bisector.CrosVersionToChromeCommit(self.GOOD_CROS_VERSION))
Example #7
0
    def testExchangeChromeSanityCheck(self):
        """Tests the flow of exchanging Chrome between good and bad CrOS."""
        self.SetUpBisectorWithCrosVersion()

        # Inject good_commit and bad_commit as if
        # bisector.ResolveChromeBisectRangeFromCrosVersion() has been run.
        self.bisector.good_commit = self.GOOD_COMMIT_SHA1
        self.bisector.bad_commit = self.BAD_COMMIT_SHA1

        # Inject commit_info and threshold as if
        # bisector.ObtainBisectBoundaryScore() and bisector.GetThresholdFromUser()
        # has been run.
        self.SetDefaultCommitInfo()
        self.bisector.threshold = self.THRESHOLD

        # Try bad Chrome first.
        git_mock = self.StartPatcher(
            git_bisector_unittest.GitMock(self.repo_dir))
        git_mock.AddRunGitResult(['checkout', self.BAD_COMMIT_SHA1])
        git_mock.AddRunGitResult(['checkout', self.GOOD_COMMIT_SHA1])

        self.PatchObject(chrome_on_cros_bisector.ChromeOnCrosBisector,
                         'UpdateCurrentCommit')

        evaluate_mock = self.PatchObject(DummyEvaluator, 'Evaluate')
        expected_evaluate_calls = [
            mock.call(self.DUT, x, self.REPEAT) for x in [
                'cros_%s_cr_%s' %
                (self.GOOD_CROS_VERSION, self.BAD_COMMIT_SHA1),
                'cros_%s_cr_%s' %
                (self.BAD_CROS_VERSION, self.GOOD_COMMIT_SHA1)
            ]
        ]

        # Mock FlashCrosImage() to verify that customize_build_deploy is assigned
        # as expected.
        flash_cros_image_mock = self.PatchObject(
            chrome_on_cros_bisector.ChromeOnCrosBisector, 'FlashCrosImage')
        expected_flash_cros_calls = [
            mock.call(self.bisector.GetCrosXbuddyPath(self.GOOD_CROS_VERSION)),
            mock.call(self.bisector.GetCrosXbuddyPath(self.BAD_CROS_VERSION))
        ]

        # Make sure bisector.BuildDeploy() is also called.
        build_deploy_mock = self.PatchObject(
            chrome_on_cros_bisector.ChromeOnCrosBisector, 'BuildDeploy')

        # Assume culprit commit is in Chrome side, i.e. first score is bad.
        evaluate_mock.side_effect = [
            self.BAD_COMMIT_SCORE, self.GOOD_COMMIT_SCORE
        ]

        self.assertTrue(self.bisector.ExchangeChromeSanityCheck())
        flash_cros_image_mock.assert_has_calls(expected_flash_cros_calls)
        evaluate_mock.assert_has_calls(expected_evaluate_calls)
        self.assertEqual(2, build_deploy_mock.call_count)

        flash_cros_image_mock.reset_mock()
        evaluate_mock.reset_mock()
        build_deploy_mock.reset_mock()

        # Assume culprit commit is not in Chrome side, i.e. first score is good.
        evaluate_mock.side_effect = [
            self.GOOD_COMMIT_SCORE, self.BAD_COMMIT_SCORE
        ]

        self.assertFalse(self.bisector.ExchangeChromeSanityCheck())
        flash_cros_image_mock.assert_has_calls(expected_flash_cros_calls)
        evaluate_mock.assert_has_calls(expected_evaluate_calls)
        self.assertEqual(2, build_deploy_mock.call_count)