Beispiel #1
0
  def __init__(self, get_repository,
               max_line_distance=DEFAULT_MAX_LINE_DISTANCE,
               max_frame_index=DEFAULT_MAX_FRAME_INDEX):
    """
    Args:
      get_repository (callable): a function from DEP urls to ``Repository``
        objects, so we can get changelogs and blame for each dep. Notably,
        to keep the code here generic, we make no assumptions about
        which subclass of ``Repository`` this function returns. Thus,
        it is up to the caller to decide what class to return and handle
        any other arguments that class may require (e.g., an http client
        for ``GitilesRepository``).
        This factory is needed because the ``MinDistanceFeature`` in this meta
        feature needs to get blame for files touched by suspect.
      max_line_distance (int): An upper bound on the min_distance to
        consider. This argument is optional and defaults to
        ``DEFAULT_MAX_LINE_DISTANCE``.
      max_frame_index (int): An upper bound on the minimum frame index
        to consider. This argument is optional and defaults to
        ``DEFAULT_MAX_FRAME_INDEX``.
    """
    min_distance_feature = MinDistanceFeature(get_repository, max_line_distance)
    top_frame_index_feature = TopFrameIndexFeature(max_frame_index)
    touch_crashed_file_feature = TouchCrashedFileFeature()

    super(TouchCrashedFileMetaFeature, self).__init__({
        min_distance_feature.name: min_distance_feature,
        top_frame_index_feature.name: top_frame_index_feature,
        touch_crashed_file_feature.name: touch_crashed_file_feature
    })
Beispiel #2
0
    def __init__(self, get_repository, config):
        """Set the paramaters of the model - i.e. the weights and features.

    For some explanation of why the paramaters were set this way see these docs:
      https://docs.google.com/a/google.com/document/d/1TdDEDlUJX81-5yvB9IfdJFq5-kJBb_DwAgDH9cGfNao/edit?usp=sharing
      https://docs.google.com/a/google.com/document/d/1FHaghBX_FANjtiUP7D1pihZGxzEYdXA3Y7t0rSA4bWU/edit?usp=sharing
    As well as the following CLs:
      https://chromium-review.googlesource.com/c/599071
      https://chromium-review.googlesource.com/c/585784
    """
        super(PredatorForUMASamplingProfiler,
              self).__init__(get_repository, config)
        meta_weight = MetaWeight({
            'TouchCrashedFileMeta':
            MetaWeight({
                'MinDistance': Weight(2.),
                'TopFrameIndex': Weight(0.),
                'TouchCrashedFile': Weight(1.),
            })
        })

        min_distance_feature = MinDistanceFeature(get_repository)
        top_frame_index_feature = TopFrameIndexFeature()
        touch_crashed_file_feature = TouchCrashedFileFeature()
        meta_feature = WrapperMetaFeature([
            TouchCrashedFileMetaFeature([
                min_distance_feature, top_frame_index_feature,
                touch_crashed_file_feature
            ],
                                        include_renamed_paths=True)
        ])

        self._predator = Predator(
            ChangelistClassifier(get_repository, meta_feature, meta_weight),
            self._component_classifier, self._project_classifier)
Beispiel #3
0
    def RedefineClassifierIfLargeRegressionRange(self, analysis):
        """Disable features for revisions in regression range > 100 commits.

    For crash with big regression range, it's easy to get false positives if we
    enable TouchCrashedComponentFeature and TouchCrashedDirectoryFeature,
    Because it has a big chance to hit these features and cause false positives.
    So we should disable these 2 features.
    """
        if (analysis.commit_count_in_regression_range <
                _BIG_REGRESSION_RANGE_COMMITS_THRESHOLD):
            return

        get_repository = self._predator.changelist_classifier._get_repository
        meta_weight = MetaWeight({
            'TouchCrashedFileMeta':
            MetaWeight({
                'MinDistance': Weight(1.),
                'TopFrameIndex': Weight(1.),
                'TouchCrashedFile': Weight(1.),
            }),
        })

        meta_feature = WrapperMetaFeature([
            TouchCrashedFileMetaFeature([
                MinDistanceFeature(get_repository),
                TopFrameIndexFeature(),
                TouchCrashedFileFeature()
            ])
        ])

        self._predator.changelist_classifier = ChangelistClassifier(
            get_repository, meta_feature, meta_weight)
 def setUp(self):
     super(TouchCrashedFileMetaFeatureTest, self).setUp()
     get_repository = GitilesRepository.Factory(self.GetMockHttpClient())
     min_distance_feature = MinDistanceFeature(get_repository)
     top_frame_index_feature = TopFrameIndexFeature()
     touch_crashed_file_feature = TouchCrashedFileFeature()
     self._feature = TouchCrashedFileMetaFeature([
         min_distance_feature, top_frame_index_feature,
         touch_crashed_file_feature
     ])
    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)
    def testFilePathMatchAfterReplacePath(self):
        """Tests the feature can match old file with new file after file move."""
        feature = TouchCrashedFileMetaFeature(
            [TouchCrashedFileFeature()],
            options={'replace_path': {
                'old/dir': 'new/dir'
            }})

        self.assertTrue(
            feature.Match(
                CrashedFile('new/dir/a/file.cc'),
                FileChangeInfo(ChangeType.MODIFY, 'old/dir/a/file.cc',
                               'old/dir/a/file.cc')))
    def testFilePathMatchAfterChangeFileExtension(self):
        """Tests feature can match old file with new file after extension change."""
        feature = TouchCrashedFileMetaFeature(
            [TouchCrashedFileFeature()],
            options={'change_file_extension': {
                'dir/a': {
                    'cpp': 'cc'
                }
            }})

        self.assertTrue(
            feature.Match(
                CrashedFile('dir/a/file_name.cc'),
                FileChangeInfo(ChangeType.MODIFY, 'dir/a/file_name.cpp',
                               'dir/a/file_name.cpp')))
    def testFilePathMatchAfterChangeNamingConvention(self):
        """Tests the feature can match old file with new file after file name."""
        feature = TouchCrashedFileMetaFeature([TouchCrashedFileFeature()],
                                              options={
                                                  'change_naming_convention': {
                                                      'dir/a':
                                                      'capital_to_underscore'
                                                  }
                                              })

        self.assertTrue(
            feature.Match(
                CrashedFile('dir/a/file_name.cc'),
                FileChangeInfo(ChangeType.MODIFY, 'dir/a/FileName.cc',
                               'dir/a/FileName.cc')))
    def testIsLogOneWhenThereIsMatchedFiles(self):
        """Test that the feature returns log(1) when there is matched file."""
        report = self._GetDummyReport()
        suspect = self._GetMockSuspect()
        frame = StackFrame(index=0,
                           dep_path=suspect.dep_path,
                           function='func',
                           file_path='a.cc',
                           raw_file_path='a.cc',
                           crashed_line_numbers=[7])

        crashed = CrashedFile(frame)
        matches = {
            crashed:
            CrashMatch(crashed,
                       [FileChangeInfo(ChangeType.MODIFY, 'a.cc', 'a.cc')],
                       [FrameInfo(frame=frame, priority=0)])
        }
        self.assertEqual(
            1.0,
            TouchCrashedFileFeature()(report)(suspect, matches).value)
Beispiel #10
0
    def __init__(self, get_repository, config):
        super(PredatorForClusterfuzz, self).__init__(get_repository, config)
        meta_weight = MetaWeight({
            'TouchCrashedFileMeta':
            MetaWeight({
                'MinDistance': Weight(2.),
                'TopFrameIndex': Weight(1.),
                'TouchCrashedFile': Weight(1.),
            }),
            'TouchCrashedDirectory':
            Weight(1.),
            'TouchCrashedComponent':
            Weight(1.),
            'NumberOfTouchedFiles':
            Weight(0.5),
        })

        min_distance_feature = MinDistanceFeature(get_repository)
        top_frame_index_feature = TopFrameIndexFeature()
        touch_crashed_file_feature = TouchCrashedFileFeature()

        meta_feature = WrapperMetaFeature([
            TouchCrashedFileMetaFeature([
                min_distance_feature, top_frame_index_feature,
                touch_crashed_file_feature
            ],
                                        options=config.feature_options.get(
                                            'TouchCrashedFileMetaFeature')),
            TouchCrashedDirectoryFeature(
                options=config.feature_options['TouchCrashedDirectory']),
            TouchCrashedComponentFeature(
                self._component_classifier,
                options=config.feature_options['TouchCrashedComponent']),
            NumberOfTouchedFilesFeature()
        ])

        self._predator = Predator(
            ChangelistClassifier(get_repository, meta_feature, meta_weight),
            self._component_classifier, self._project_classifier)
Beispiel #11
0
    def setUp(self):
        super(ChangelistClassifierTest, self).setUp()
        meta_weight = MetaWeight({
            'TouchCrashedFileMeta':
            MetaWeight({
                'MinDistance': Weight(1.),
                'TopFrameIndex': Weight(1.),
                'TouchCrashedFile': Weight(1.),
            })
        })
        get_repository = GitilesRepository.Factory(self.GetMockHttpClient())
        min_distance_feature = MinDistanceFeature(get_repository)
        top_frame_index_feature = TopFrameIndexFeature()
        touch_crashed_file_feature = TouchCrashedFileFeature()

        meta_feature = WrapperMetaFeature([
            TouchCrashedFileMetaFeature([
                min_distance_feature, top_frame_index_feature,
                touch_crashed_file_feature
            ])
        ])

        self.changelist_classifier = ChangelistClassifier(
            get_repository, meta_feature, meta_weight)
 def testIsLogZeroWhenThereIsNoMatchedFiles(self):
     """Test that the feature returns log(0) when there is no matched file."""
     report = self._GetDummyReport()
     suspect = self._GetMockSuspect()
     self.assertEqual(0.0,
                      TouchCrashedFileFeature()(report)(suspect, {}).value)