Exemple #1
0
    def testReadLines(self):
        """Asserts that lines are read correctly.

        Blocks must have correct references to the lines contained
        in the block.
        """
        self.stream = MockStream.concat_int(self.stream, 2)  #  block number
        self.stream = MockStream.concat_int(self.stream, 0)  #  dummy
        name = "src.c"
        name_length = int(
            math.ceil(1.0 * len(name) / MockStream.BYTES_PER_WORD)) + 1
        self.stream = MockStream.concat_string(self.stream, name)
        n_arcs = 5
        for i in range(1, n_arcs + 1):
            self.stream = MockStream.concat_int(self.stream, i)

        n_blocks = 5
        func = function_summary.FunctionSummary(0, "func", name, 1)
        func.blocks = [
            block_summary.BlockSummary(i, 3 * i) for i in range(n_blocks)
        ]
        parser = gcno_parser.GCNOParser(self.stream)
        parser.ReadLines(n_arcs + name_length + 3, func)
        self.assertEqual(len(func.blocks[2].lines), 5)
        self.assertEqual(func.blocks[2].lines, range(1, 6))
Exemple #2
0
    def testReadArcsNormal(self):
        """Asserts that arcs are correctly read from the stream.

        Does not test the use of flags. Validates that arcs are
        created in both blocks and the source/destination are
        correct for each.
        """
        n_blocks = 50
        func = function_summary.FunctionSummary(0, "func", "src.c", 1)
        func.blocks = [
            block_summary.BlockSummary(i, 3 * i) for i in range(n_blocks)
        ]
        src_block_index = 0
        skip = 2
        self.stream = MockStream.concat_int(self.stream, src_block_index)
        for i in range(src_block_index + 1, n_blocks, skip):
            self.stream = MockStream.concat_int(self.stream, i)
            self.stream = MockStream.concat_int(
                self.stream, 0)  #  no flag applied to the arc
        parser = gcno_parser.GCNOParser(self.stream)
        n_arcs = len(range(src_block_index + 1, n_blocks, skip))
        parser.ReadArcs(n_arcs * 2 + 1, func)
        j = 0
        for i in range(src_block_index + 1, n_blocks, skip):
            self.assertEqual(
                func.blocks[src_block_index].exit_arcs[j].src_block.index,
                src_block_index)
            self.assertEqual(
                func.blocks[src_block_index].exit_arcs[j].dst_block.index, i)
            self.assertEqual(func.blocks[i].entry_arcs[0].src_block.index,
                             src_block_index)
            self.assertEqual(func.blocks[i].entry_arcs[0].dst_block.index, i)
            j += 1
Exemple #3
0
    def testReadBlocks(self):
        """Asserts that blocks are correctly read from the stream.

        Tests correct values for flag and index.
        """
        n_blocks = 10
        func = function_summary.FunctionSummary(0, "func", "src.c", 1)
        for i in range(n_blocks):
            self.stream = MockStream.concat_int(self.stream, 3 * i)
        parser = gcno_parser.GCNOParser(self.stream)
        parser.ReadBlocks(n_blocks, func)
        self.assertEqual(len(func.blocks), n_blocks)
        for i in range(n_blocks):
            self.assertEqual(func.blocks[i].flag, 3 * i)
            self.assertEqual(func.blocks[i].index, i)
Exemple #4
0
 def testReadFunction(self):
     """Verifies that the correct function is read and returned.
     """
     ident = 100
     checksum = 0
     fs = file_summary.FileSummary()
     func = function_summary.FunctionSummary(ident, 'test', 'test.c', 0)
     fs.functions[ident] = func
     self.stream = MockStream.concat_int(self.stream, ident)
     self.stream = MockStream.concat_int(self.stream, 0)
     self.stream = MockStream.concat_int(self.stream, 0)
     self.stream = MockStream.concat_string(self.stream, 'test')
     length = 5
     parser = gcda_parser.GCDAParser(self.stream)
     parser.file_summary = fs
     func = parser.ReadFunction(5)
     assert (func.ident == ident)
Exemple #5
0
    def testReadArcFlags(self):
        """Asserts that arc flags are correctly interpreted.
        """
        n_blocks = 5
        func = function_summary.FunctionSummary(0, "func", "src.c", 1)
        func.blocks = [
            block_summary.BlockSummary(i, 3 * i) for i in range(n_blocks)
        ]
        self.stream = MockStream.concat_int(self.stream,
                                            0)  #  source block index

        self.stream = MockStream.concat_int(self.stream, 1)  #  normal arc
        self.stream = MockStream.concat_int(self.stream, 0)

        self.stream = MockStream.concat_int(self.stream, 2)  #  on-tree arc
        self.stream = MockStream.concat_int(
            self.stream, arc_summary.ArcSummary.GCOV_ARC_ON_TREE)

        self.stream = MockStream.concat_int(self.stream, 3)  #  fake arc
        self.stream = MockStream.concat_int(
            self.stream, arc_summary.ArcSummary.GCOV_ARC_FAKE)

        self.stream = MockStream.concat_int(self.stream, 4)  #  fallthrough arc
        self.stream = MockStream.concat_int(
            self.stream, arc_summary.ArcSummary.GCOV_ARC_FALLTHROUGH)

        parser = gcno_parser.GCNOParser(self.stream)
        parser.ReadArcs(4 * 2 + 1, func)

        self.assertFalse(func.blocks[0].exit_arcs[0].on_tree)
        self.assertFalse(func.blocks[0].exit_arcs[0].fake)
        self.assertFalse(func.blocks[0].exit_arcs[0].fallthrough)

        self.assertTrue(func.blocks[0].exit_arcs[1].on_tree)
        self.assertFalse(func.blocks[0].exit_arcs[1].fake)
        self.assertFalse(func.blocks[0].exit_arcs[1].fallthrough)

        self.assertFalse(func.blocks[0].exit_arcs[2].on_tree)
        self.assertTrue(func.blocks[0].exit_arcs[2].fake)
        self.assertFalse(func.blocks[0].exit_arcs[2].fallthrough)

        self.assertFalse(func.blocks[0].exit_arcs[3].on_tree)
        self.assertFalse(func.blocks[0].exit_arcs[3].fake)
        self.assertTrue(func.blocks[0].exit_arcs[3].fallthrough)
Exemple #6
0
    def setUp(self):
        """Creates a function summary and a chain of blocks.

        Creates an arc between adjacent blocks. All arcs are left with default
        values (unresolved, count of 0).
        """
        self.n = 10
        self.count = 5
        self.function_summary = function_summary.FunctionSummary(
            0, 'test', 'test.c', 0)
        self.function_summary.blocks = [
            block_summary.BlockSummary(i, 0) for i in range(self.n)
        ]
        self.arcs = []
        for i in range(1, self.n):
            arc = arc_summary.ArcSummary(self.function_summary.blocks[i - 1],
                                         self.function_summary.blocks[i], 0)
            self.function_summary.blocks[i - 1].exit_arcs.append(arc)
            self.function_summary.blocks[i].entry_arcs.append(arc)
            self.arcs.append(arc)
Exemple #7
0
    def testReadCountsNormal(self):
        """Verifies that counts are read correctly.

        Verifies that arcs are marked as resolved and count is correct.
        """
        n = 5
        fs = file_summary.FileSummary()
        func = function_summary.FunctionSummary(0, 'test', 'test.c', 0)
        blocks = [block_summary.BlockSummary(i, 0) for i in range(n)]
        func.blocks = blocks
        fs.functions[func.ident] = func
        for i in range(1, n):
            arc = arc_summary.ArcSummary(blocks[0], blocks[i], 0)
            blocks[0].exit_arcs.append(arc)
            blocks[i].entry_arcs.append(arc)
            self.stream = MockStream.concat_int64(self.stream, i)
        parser = gcda_parser.GCDAParser(self.stream)
        parser.file_summary = fs
        parser.ReadCounts(func)
        for i, arc in zip(range(1, n), blocks[0].exit_arcs):
            self.assertEqual(i, arc.count)
            self.assertTrue(arc.resolved)
    def ReadFunction(self):
        """Reads and returns a function from the stream.

        Reads information about a function from the gcno file stream and
        returns a summary object.

        Returns:
            FunctionSummary object containing the function name, source file,
            and first line number.

        Raises:
            parser.FileFormatError: Function could not be read.
        """
        ident = self.ReadInt()
        self.ReadInt()  #  line number checksum
        if int(self.version[1]) > 4:
            self.ReadInt()  #  configuration checksum
        name = self.ReadString()
        source_file_name = self.ReadString()
        first_line_number = self.ReadInt()
        return function_summary.FunctionSummary(ident, name, source_file_name,
                                                first_line_number)
Exemple #9
0
    def testReadCountsFakeOrOnTree(self):
        """Verifies that counts are read correctly when there are skipped arcs.

        Verifies that the fake arc and the arc on the tree are skipped while other
        arcs are read and resolved correctly.
        """
        n = 10
        fs = file_summary.FileSummary()
        func = function_summary.FunctionSummary(0, 'test', 'test.c', 0)
        blocks = [block_summary.BlockSummary(i, 0) for i in range(n)]
        func.blocks = blocks
        fs.functions[func.ident] = func

        arc = arc_summary.ArcSummary(blocks[0], blocks[1],
                                     arc_summary.ArcSummary.GCOV_ARC_FAKE)
        blocks[0].exit_arcs.append(arc)
        blocks[1].entry_arcs.append(arc)

        arc = arc_summary.ArcSummary(blocks[0], blocks[2],
                                     arc_summary.ArcSummary.GCOV_ARC_ON_TREE)
        blocks[0].exit_arcs.append(arc)
        blocks[2].entry_arcs.append(arc)

        for i in range(3, n):
            arc = arc_summary.ArcSummary(blocks[0], blocks[i], 0)
            blocks[0].exit_arcs.append(arc)
            blocks[i].entry_arcs.append(arc)
            self.stream = MockStream.concat_int64(self.stream, i)

        parser = gcda_parser.GCDAParser(self.stream)
        parser.file_summary = fs
        parser.ReadCounts(func)
        self.assertFalse(blocks[0].exit_arcs[0].resolved)
        self.assertFalse(blocks[0].exit_arcs[1].resolved)
        for i, arc in zip(range(3, n), blocks[0].exit_arcs[2:]):
            self.assertEqual(i, arc.count)
            self.assertTrue(arc.resolved)