Ejemplo n.º 1
0
 def validate_sums(self, count, code, message):
     if self.state._should_ignore(code):
         return
     if self.state.event_counter[code] != int(count):
         self.state.debug_required = True
         p_debug("Parsed results does not match "
                 "forcheck summary (%s)." % code)
         p_debug("  Found %d, summary states %s" %
                (self.state.event_counter[code], count))
Ejemplo n.º 2
0
    def _store_event(self, code, message, instance):
        if self._should_ignore(code):
            return
        self.event_instances[code].append(instance)
        self.event_counter[code] += 1

        if not code in self.event_message:
            self.event_message[code] = message
        else:
            if message != self.event_message[code]:
                self.debug_required = True
                p_debug("Seeing different messages for "
                                 "event code (%s).\n" % code)
Ejemplo n.º 3
0
    def _parse(self):
        p_info("\nParsing forcheck listfile")
        if self.state.ignore_list:
            p_info("(ignoring the following forcheck events: "
                   "%s)" % ", ".join(str(x) for x in self.state.ignore_list))

        stages = iter((
            {"name": "file events",
             "end_marker": "global program analysis:",
             "parser": FileEvent(self.state)},
            {"name": "global events",
             "end_marker": "program_units and procedures analysed:",
             "parser": GlobalEvent(self.state)},
            {"name": "program units",
             # "end_marker": "*END OF ANALYSIS*"  # no longer appear in >14.3
             "end_marker": "messages presented:",
             "parser": None},
            {"name": "forcheck summary",
             "end_marker": None,
             "parser": SummaryEvent(self.state)},
        ))

        lines = ("", "", "")  # (current, previous, previous-1)
        stage = stages.next()
        p_info(" - Parsing %s" % stage["name"])

        def forward_to_content(file_iterator):
            """
            Forwards file iterator the the actual content, then returns
            the source file addressed by forcheck output page
            """
            # each new page starts with a header
            line = next(file_iterator)
            assert line.startswith("FORCHECK"), "Unexpected listfile format"

            # this is followed by "(options...) target_file" if the output is
            # file specific
            line = next(file_iterator)
            if line.strip():
                target_file = line.rsplit(None, 1)[-1]
                line = next(file_iterator)  # following line should be blank
                assert not line.strip(), "Unexpected listfile format"
            else:
                target_file = None
            return target_file

        with open(self.listfile) as f:
            target_file = forward_to_content(f)
            for L in f:
                if L.startswith("\f"):  # new page. forward to content
                    target_file = forward_to_content(f)
                    continue
                lines = (L.strip(), lines[0], lines[1])  # shift
                if lines[0] == stage["end_marker"]:
                    stage = stages.next()
                    p_info(" - Parsing %s" % stage["name"])
                elif stage["parser"]:  # if event has a parser
                    stage["parser"].slurp(target_file, *lines)

        if self.state.debug_required:
            import shutil
            listfile_out = "forcheck_listfile.debug"
            shutil.copy(self.listfile, listfile_out)
            p_debug(
                "There appears to be a problem in the parsing. \n"
                " Forcheck results written to %s. \n"
                " Please send the file and the checkfort version info\n"
                "    to the checkfort devs for further investigation"
                % (listfile_out, ))
        else:
            p_verbose("Parse successful")