示例#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))
示例#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
示例#3
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)
    def ReadBlocks(self, length, func):
        """Reads the basic block information from the stream.

        Reads information about the basic blocks from the gcno file
        stream and updates the specified function.

        Args:
            length: number of blocks to read
            func: FunctionSummary object for the blocks' parent function

        Raises:
            parser.FileFormatError: Blocks could not be read. Corrupt file.
        """

        blocks = []
        for _ in range(length):
            block_flag = self.ReadInt()
            block = block_summary.BlockSummary(len(blocks), block_flag)
            blocks.append(block)
        func.blocks.extend(blocks)
示例#5
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)
示例#6
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)
示例#7
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)