Ejemplo n.º 1
0
    def testDoNotIndexFramesWithNoneCrashedGroup(self):
        """Tests ``IndexFramesWithCrashedGroup`` function."""
        frame = StackFrame(0, 'src/', 'func', '', '', [2], 'h://repo')
        stack = CallStack(0, frame_list=[frame])
        stack_trace = Stacktrace([stack], stack)
        deps = {'src/': Dependency('src/', 'h://repo', 'rev3')}

        indexed_frame_infos = crash_util.IndexFramesWithCrashedGroup(
            stack_trace, Factory, deps)
        self.assertEqual(indexed_frame_infos, {})
Ejemplo n.º 2
0
    def testIndexFramesWithCrashedGroupWhenFrameHasNoDepPath(self):
        """Tests a bug with ``IndexFramesWithCrashedGroup``.

    This function would crash when passed a frame with a ``None`` dep path.
    Instead it should ignore this frame.
    """
        frame = ProfilerStackFrame(0, 0.1, 0.5, True, dep_path=None)
        stack = CallStack(0, frame_list=[frame])
        stack_trace = Stacktrace([stack], stack)
        deps = {'src': Dependency('src', 'h://repo', 'rev3')}

        indexed_frame_infos = crash_util.IndexFramesWithCrashedGroup(
            stack_trace, Factory, deps)
        self.assertDictEqual(indexed_frame_infos, {})
Ejemplo n.º 3
0
    def __call__(self, report):
        """
    Args:
      report (CrashReport): the crash report being analyzed.

    Returns:
      A ``FeatureValue`` with name, log-domain value, reason and changed_files.
    """
        dep_to_grouped_frame_infos = crash_util.IndexFramesWithCrashedGroup(
            report.stacktrace, self.CrashedGroupFactory, report.dependencies)

        def FeatureValueGivenReport(suspect):
            """Compute ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.

      Returns:
        The ``FeatureValue`` of this feature.
      """
            grouped_frame_infos = dep_to_grouped_frame_infos.get(
                suspect.dep_path, {})
            matches = crash_util.MatchSuspectWithFrameInfos(
                suspect, grouped_frame_infos,
                self.GetMatchFunction(suspect.dep_path))

            if not matches:
                return FeatureValue(name=self.name,
                                    value=0.0,
                                    reason=None,
                                    changed_files=None)

            crashed_components = [component.value for component in matches]
            plural = len(crashed_components) > 1

            reason = [
                'Suspected changelist touched file(s) associated with the '
                'component%s %s, which we believe is related to this testcase based '
                'on information in OWNERS files.' %
                ('s' if plural else '', ', '.join(crashed_components))
            ]

            return FeatureValue(name=self.name,
                                value=1.0,
                                reason=reason,
                                changed_files=None)

        return FeatureValueGivenReport
Ejemplo n.º 4
0
    def __call__(self, report):
        """Returns a function mapping suspect to its ``MetaFeatureValue``.

    Args:
      report (CrashReportWithDependensies): the crash report being analyzed.

    Returns:
      A function from ``Suspect`` to ``MetaFeatureValue``, ``MetaFeatureValue``
      wraps ``FeatureValue`` of "MinDistance" (the minimum distance between the
      stacktrace and the suspect, as a log-domain ``float``), ``FeatureValue``
      of "TopFrameIndex" (the top frame index of the stack frame touched by
      the suspect, as a log-domain ``float``.) and ``FeatureValue`` of
      "TouchCrashedFileFeature" (whether this suspect touched file or not)
    """
        # Preprocessing stacktrace and dependencies to get crashed file information
        # about the frames and callstack priority of that crashed file in
        # stacktrace.
        dep_to_grouped_frame_infos = crash_util.IndexFramesWithCrashedGroup(
            report.stacktrace, self.CrashedGroupFactory, report.dependencies)
        features_given_report = {
            name: feature(report)
            for name, feature in self.iteritems()
        }

        def FeatureValueGivenReport(suspect):
            """Function mapping suspect related data to its FeatureValue.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.
        touched_file_to_stack_infos(dict): Dict mapping ``FileChangeInfo`` to
          a list of ``StackInfo``s representing all the frames that the suspect
          touched.

      Returns:
        The ``FeatureValue`` of this feature.
      """
            grouped_frame_infos = dep_to_grouped_frame_infos.get(
                suspect.dep_path, {})
            matches = crash_util.MatchSuspectWithFrameInfos(
                suspect, grouped_frame_infos, self.Match)

            return MetaFeatureValue(
                self.name, {
                    name: fx(suspect, matches)
                    for name, fx in features_given_report.iteritems()
                })

        return FeatureValueGivenReport
Ejemplo n.º 5
0
    def __call__(self, report):
        """
    Args:
      report (CrashReport): the crash report being analyzed.

    Returns:
      A ``FeatureValue`` with name, log-domain value, reason and changed_files.
    """
        dep_to_grouped_frame_infos = crash_util.IndexFramesWithCrashedGroup(
            report.stacktrace, self.CrashedGroupFactory, report.dependencies)

        def FeatureValueGivenReport(suspect):
            """Compute ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.

      Returns:
        The ``FeatureValue`` of this feature.
      """
            grouped_frame_infos = dep_to_grouped_frame_infos.get(
                suspect.dep_path, {})
            matches = crash_util.MatchSuspectWithFrameInfos(
                suspect, grouped_frame_infos, self.Match)

            if not matches:
                return FeatureValue(name=self.name,
                                    value=0.0,
                                    reason=None,
                                    changed_files=None)

            crashed_directories = [directory.value for directory in matches]
            plural = len(crashed_directories) > 1

            reason = [
                'Suspected changelist touched file(s) in the %s %s, which '
                'appear%s in the stack trace.' %
                ('directories' if plural else 'directory',
                 ', '.join(crashed_directories), '' if plural else 's')
            ]

            return FeatureValue(name=self.name,
                                value=1.0,
                                reason=reason,
                                changed_files=None)

        return FeatureValueGivenReport
Ejemplo n.º 6
0
    def __call__(self, report):
        """
    Args:
      report (CrashReport): the crash report being analyzed.

    Returns:
      A ``FeatureValue`` with name, log-domain value, reason and changed_files.
    """
        dep_to_grouped_frame_infos = crash_util.IndexFramesWithCrashedGroup(
            report.stacktrace, self.CrashedGroupFactory, report.dependencies)

        def FeatureValueGivenReport(suspect):
            """Compute ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.

      Returns:
        The ``FeatureValue`` of this feature.
      """
            grouped_frame_infos = dep_to_grouped_frame_infos.get(
                suspect.dep_path, {})
            matches = crash_util.MatchSuspectWithFrameInfos(
                suspect, grouped_frame_infos,
                self.GetMatchFunction(suspect.dep_path))

            if not matches:
                return FeatureValue(name=self.name,
                                    value=0.0,
                                    reason=None,
                                    changed_files=None)

            return FeatureValue(name=self.name,
                                value=1.0,
                                reason='\n'.join([
                                    str(match)
                                    for match in matches.itervalues()
                                ]),
                                changed_files=None)

        return FeatureValueGivenReport
Ejemplo n.º 7
0
    def testIndexFramesWithCrashedGroup(self):
        """Tests ``IndexFramesWithCrashedGroup`` function."""
        frame1 = StackFrame(0, 'src/', 'func', 'f.cc', 'src/f.cc', [2, 3],
                            'h://repo')
        frame2 = StackFrame(1, 'src/', 'func', 'a.cc', 'src/a.cc', [31, 32],
                            'h://repo')
        frame3 = StackFrame(1, 'src/dummy', 'func', 'a.cc', 'src/dummy/a.cc',
                            [131, 132], 'h://repo')
        stack = CallStack(0, frame_list=[frame1, frame2, frame3])
        stack_trace = Stacktrace([stack], stack)
        deps = {'src/': Dependency('src/', 'h://repo', 'rev3')}

        indexed_frame_infos = crash_util.IndexFramesWithCrashedGroup(
            stack_trace, Factory, deps)
        expected_frame_infos = {
            'src/': {
                MockCrashedGroup('src/f.cc'): [FrameInfo(frame1, 0)],
                MockCrashedGroup('src/a.cc'): [FrameInfo(frame2, 0)]
            }
        }
        self.assertEqual(indexed_frame_infos, expected_frame_infos)