def _GetDummyReport(self, deps=None, dep_rolls=None):
     crash_stack = CallStack(0, [
         StackFrame(0, 'src/', 'func', 'a.cc', 'a.cc', [2], 'https://repo')
     ])
     return CrashReport('rev', 'sig', 'win',
                        Stacktrace([crash_stack], crash_stack),
                        ('rev0', 'rev9'), deps, dep_rolls)
예제 #2
0
    def testCallWhenThereIsNoStacktrace(self):
        """Tests ``__call__`` when there is no stacktrace in crash_report."""
        crash_report = CrashReport(None, None, None, None, (None, None), None,
                                   None)

        file_path_extractor = FilePathExtractor()
        keywords = file_path_extractor(crash_report)
        self.assertEqual(keywords, {})
예제 #3
0
 def testDependenciesAndDependencyRollsIsFrozenDict(self):
     crash_report = CrashReport(
         'rev', 'sig', 'win', None, ('1', '3'),
         {'src/': Dependency('src/', 'http://repo', '5')},
         {'src/': DependencyRoll('src/', 'http://repo', '1', '3')})
     self.assertTrue(isinstance(crash_report.regression_range, tuple))
     self.assertTrue(isinstance(crash_report.dependencies, _FrozenDict))
     self.assertTrue(isinstance(crash_report.dependency_rolls, _FrozenDict))
    def setUp(self):
        super(TouchCrashedDirectoryBaseFeatureTest, self).setUp()
        frame1 = StackFrame(0, 'src/', 'func', 'p/f.cc', 'src/p/f.cc', [2, 3],
                            'h://repo')
        stack = CallStack(0, frame_list=[frame1])
        stack_trace = Stacktrace([stack], stack)
        deps = {'src/': Dependency('src/', 'h://repo', '8')}
        dep_rolls = {'src/': DependencyRoll('src/', 'h://repo', '2', '6')}

        self._report = CrashReport('8', 'sig', 'linux', stack_trace,
                                   ('2', '6'), deps, dep_rolls)
        self._feature = TouchCrashedDirectoryFeature()
 def testFeatureValueIsZeroWhenNoMatchedComponent(self):
     """Test that the feature returns 0 when there no matched component."""
     frame = StackFrame(0, 'src/', 'func', 'dir/f.cc', 'src/dir/f.cc',
                        [2, 3], 'h://repo')
     stack = CallStack(0, frame_list=[frame])
     stack_trace = Stacktrace([stack], stack)
     deps = {'src/': Dependency('src/', 'h://repo', '8')}
     dep_rolls = {'src/': DependencyRoll('src/', 'h://repo', '2', '6')}
     report = CrashReport('8', 'sig', 'linux', stack_trace, ('2', '6'),
                          deps, dep_rolls)
     suspect = Suspect(_DUMMY_CHANGELOG, 'src/')
     feature_value = self.feature(report)(suspect)
     self.assertEqual(0.0, feature_value.value)
예제 #6
0
    def testUpdateInvertedIndexForCrash(self):
        crash_report = CrashReport('50.0.1234.0', 'sig', 'win', None, None,
                                   None, None)
        keywords = _MockKeywrodExtractor(crash_report)
        UpdateInvertedIndexForCrash(
            crash_report,
            _MockKeywrodExtractor,
            inverted_index_model=ChromeCrashInvertedIndex)

        for keyword in keywords:
            inverted_index = ChromeCrashInvertedIndex.Get(keyword)
            self.assertIsNotNone(inverted_index)
            self.assertEqual(inverted_index.n_of_doc, 1)
 def testFeatureValueIsOneWhenThereIsMatchedComponent(self):
     """Test that feature value is 1 when there no matched component."""
     # One dummy component in config is ['src/comp1.*', '', 'Comp1>Dummy'].
     frame1 = StackFrame(0, 'src/', 'func', 'comp1/f.cc', 'src/comp1/f.cc',
                         [2, 3], 'h://repo')
     stack = CallStack(0, frame_list=[frame1])
     stack_trace = Stacktrace([stack], stack)
     deps = {'src/': Dependency('src/', 'h://repo', '8')}
     dep_rolls = {'src/': DependencyRoll('src/', 'h://repo', '2', '6')}
     report = CrashReport('8', 'sig', 'linux', stack_trace, ('2', '6'),
                          deps, dep_rolls)
     suspect = Suspect(_DUMMY_CHANGELOG, 'src/')
     feature_value = self.feature(report)(suspect)
     self.assertEqual(1.0, feature_value.value)
예제 #8
0
    def testLogNoRegressionRangeMessage(self):
        """Tests that ``__call__`` log messages if regression range is None."""
        report = CrashReport(None, None, None, None, None, None, None)
        self.changelist_classifier(report)
        self.assertIsNone(self.changelist_classifier._log)

        self.changelist_classifier.SetLog(self.GetMockLog())
        self.changelist_classifier(report)
        self.assertEqual(self.changelist_classifier._log.logs, [{
            'level':
            'warning',
            'name':
            'NoRegressionRange',
            'message': ('Can\'t find culprits due to unavailable '
                        'regression range.')
        }])
예제 #9
0
    def testLogFailedToParseStacktraceMessage(self, mock_generate_suspects):
        """Tests that ``__call__`` log messages if stacktrace is None."""
        suspect = Suspect(DUMMY_CHANGELOG1, 'src/')
        mock_generate_suspects.return_value = [suspect, suspect]
        report = CrashReport(None, None, None, None, (None, None), None, None)
        self.changelist_classifier(report)
        self.assertIsNone(self.changelist_classifier._log)

        self.changelist_classifier.SetLog(self.GetMockLog())
        self.changelist_classifier(report)
        self.assertEqual(self.changelist_classifier._log.logs, [{
            'level':
            'error',
            'name':
            'FailedToParseStacktrace',
            'message': ('Can\'t find culprits because Predator '
                        'failed to parse stacktrace.')
        }])
 def testFeatureValueIsOneWhenThereIsMatchedDirectory(self):
     """Test that feature value is 1 when there is matched directory."""
     frame1 = StackFrame(0, 'src/', 'func', 'p/f.cc', 'src/p/f.cc', [2, 3],
                         'h://repo')
     stack = CallStack(0, frame_list=[frame1])
     stack_trace = Stacktrace([stack], stack)
     deps = {'src/': Dependency('src/', 'h://repo', '8')}
     dep_rolls = {'src/': DependencyRoll('src/', 'h://repo', '2', '6')}
     report = CrashReport('8', 'sig', 'linux', stack_trace, ('2', '6'),
                          deps, dep_rolls)
     changelog = self.GetDummyChangeLog()._replace(touched_files=[
         FileChangeInfo.FromDict({
             'change_type': 'add',
             'new_path': 'p/a.cc',
             'old_path': None,
         })
     ])
     suspect = Suspect(changelog, 'src/')
     feature_value = self._feature(report)(suspect)
     self.assertEqual(1.0, feature_value.value)
예제 #11
0
    def testFilePathIdfFeatureCallForMatches(self):
        """Tests ``__call__`` of ``FilePathIdfFeature`` for non-empty matches."""
        report = CrashReport(None, None, None, None, None, None, None)
        frame1 = StackFrame(0, '', 'func', 'keyword1', 'src/keyword1', [2],
                            'http://repo')
        frame2 = StackFrame(0, '', 'func', 'keyword2', 'src/keyword2', [9],
                            'http://repo')
        matches = {
            CrashedFile('keyword1'):
            CrashMatch(CrashedFile('keyword1'), ['keyword1'],
                       [FrameInfo(frame1, 0)]),
            CrashedFile('keyword2'):
            CrashMatch(CrashedFile('keyword2'), ['keyword2'],
                       [FrameInfo(frame2, 0)])
        }

        feature_value = self.feature(report)(None, matches)
        self.assertEqual(
            feature_value.value,
            file_path_idf.LogRegressNomalize(math.log(9 / float(1 + 3))))
    def testIncludeRenamedPathsFlag(self):
        """Tests the ``include_renamed_paths`` flag."""
        feature_with_flag = TouchCrashedFileMetaFeature(
            [TouchCrashedFileFeature()], include_renamed_paths=True)
        feature_without_flag = TouchCrashedFileMetaFeature(
            [TouchCrashedFileFeature()], include_renamed_paths=False)

        deps = {'src/': Dependency('src/', 'https://repo', '6')}
        # Stack frame in old version of file before it was renamed:
        stackframe = CallStack(0, [
            StackFrame(0, 'src/', 'func', 'old_name.cc', 'old_name.cc', [4],
                       'https://repo')
        ])
        report = CrashReport('rev', 'sig', 'win',
                             Stacktrace([stackframe], stackframe),
                             ('rev0', 'rev9'), deps, None)

        feature_values = feature_with_flag(report)(self._GetMockSuspect())
        self.assertEqual(1.0, feature_values['TouchCrashedFile'].value)

        feature_values = feature_without_flag(report)(self._GetMockSuspect())
        self.assertEqual(0, feature_values['TouchCrashedFile'].value)
예제 #13
0
    def testCallWhenThereIsStacktrace(self):
        """Tests ``__call__`` when there is stacktrace in crash_report."""
        file_paths = set(['a.cc', 'b.cc', 'c.cc'])
        frames = []
        for index, file_path in enumerate(file_paths):
            frames.append(
                StackFrame(index, 'src/', 'func', file_path,
                           os.path.join('src/', file_path), [index],
                           'https://repo'))
        callstacks = [
            CallStack(0, frames, CallStackFormatType.DEFAULT, LanguageType.CPP)
        ]
        crash_report = CrashReport(None, None, None,
                                   Stacktrace(callstacks, callstacks[0]),
                                   (None, None), None, None)

        file_path_extractor = FilePathExtractor()
        keywords = file_path_extractor(crash_report)
        expected_keywords = [
            os.path.join('src/', file_path) for file_path in file_paths
        ]
        self.assertSetEqual(set(keywords.keys()), set(expected_keywords))
예제 #14
0
    def testLogFailedToFindSuspectedClsMessage(self, mock_generate_suspects,
                                               mock_find_suspects):
        """Tests logging messages if predator cannot find suspected cls."""
        suspect = Suspect(DUMMY_CHANGELOG1, 'src/')
        mock_generate_suspects.return_value = [suspect, suspect]
        mock_find_suspects.return_value = []
        report = CrashReport(None, None, None,
                             Stacktrace(DUMMY_CALLSTACKS, DUMMY_CALLSTACKS[0]),
                             (None, None), None, None)
        self.changelist_classifier(report)
        self.assertIsNone(self.changelist_classifier._log)

        self.changelist_classifier.SetLog(self.GetMockLog())
        self.changelist_classifier(report)
        self.assertEqual(self.changelist_classifier._log.logs, [{
            'level':
            'warning',
            'name':
            'FailedToFindSuspectedCls',
            'message': ('Cannot find any match between cls in '
                        'regression range and stacktrace')
        }])
예제 #15
0
    def testToCrashReport(self):
        """Tests converting ``CrashAnalysis`` to ``CrashReport``."""
        chrome_version = '50.2500.0.0'
        signature = 'signature/here'
        channel = 'canary'
        platform = 'mac'
        regression_range = ('50.2450.0.2', '50.2982.0.0')
        raw_crash_data = self.GetDummyChromeCrashData(
            client_id=CrashClient.FRACAS,
            channel=channel,
            platform=platform,
            signature=signature,
            version=chrome_version,
            regression_range=regression_range,
            process_type='renderer')
        findit = self.GetMockFindit(client_id=CrashClient.FRACAS)
        crash_data = findit.GetCrashData(raw_crash_data)
        analysis = CrashAnalysis()
        analysis.Initialize(crash_data)

        expected_crash_report = CrashReport(chrome_version, signature,
                                            platform, None, regression_range,
                                            {}, {})
        self.assertTupleEqual(analysis.ToCrashReport(), expected_crash_report)
예제 #16
0
    def testToCrashReport(self):
        """Tests converting ``CrashAnalysis`` to ``CrashReport``."""
        signature = 'signature/here'
        channel = 'canary'
        platform = 'mac'
        regression_range = ('50.2450.0.2', '50.2982.0.0')
        raw_crash_data = self.GetDummyChromeCrashData(
            client_id=CrashClient.FRACAS,
            channel=channel,
            platform=platform,
            signature=signature,
            version=None,
            regression_range=regression_range,
            process_type='renderer')
        predator = self.GetMockPredatorApp(client_id=CrashClient.FRACAS)
        crash_data = predator.GetCrashData(raw_crash_data)
        analysis = CrashAnalysis()
        analysis.Initialize(crash_data)

        expected_crash_report = CrashReport(None, signature, platform, None,
                                            regression_range, {}, {},
                                            CHROMIUM_REPO_URL,
                                            CHROMIUM_ROOT_PATH)
        self.assertTupleEqual(analysis.ToCrashReport(), expected_crash_report)
예제 #17
0
    'commit_url':
    'https://repo.test/+/3',
    'code_review_url':
    'https://codereview.chromium.org/3281',
    'revision':
    '3',
    'reverted_revision':
    '0'
})

DUMMY_CALLSTACKS = [
    CallStack(0, [], CallStackFormatType.DEFAULT, LanguageType.CPP),
    CallStack(1, [], CallStackFormatType.DEFAULT, LanguageType.CPP)
]
DUMMY_REPORT = CrashReport(None, None, None,
                           Stacktrace(DUMMY_CALLSTACKS, DUMMY_CALLSTACKS[0]),
                           (None, None), None, None)


class ChangelistClassifierTest(AppengineTestCase):
    """Tests ``ChangelistClassifier`` class."""
    def setUp(self):
        super(ChangelistClassifierTest, self).setUp()
        meta_weight = MetaWeight({
            'TouchCrashedFileMeta':
            MetaWeight({
                'MinDistance': Weight(1.),
                'TopFrameIndex': Weight(1.),
                'TouchCrashedFile': Weight(1.),
            })
        })
예제 #18
0
 def ToCrashReport(self):
   """Converts this model to ``CrashReport`` to give to Predator library."""
   return CrashReport(self.crashed_version, self.signature, self.platform,
                      self.stacktrace, self.regression_range,
                      self.dependencies, self.dependency_rolls,
                      self.root_repo_url, self.root_repo_path)
예제 #19
0
 def testFilePathIdfFeatureCallForNoneMatches(self):
     """Tests ``__call__`` of ``FilePathIdfFeature`` for None matches."""
     report = CrashReport(None, None, None, None, None, None, None)
     feature_value = self.feature(report)(None, None)
     self.assertEqual(feature_value.value, 0)