示例#1
0
 def test_cfg(self):
     node = gtirb.CFG()
     node.add(
         gtirb.Edge(
             gtirb.CodeBlock(offset=1, size=2),
             gtirb.CodeBlock(offset=3, size=4),
             gtirb.Edge.Label(
                 type=gtirb.Edge.Type.Fallthrough,
                 conditional=True,
                 direct=False,
             ),
         )
     )
     node.add(
         gtirb.Edge(
             gtirb.CodeBlock(offset=5, size=6),
             gtirb.CodeBlock(offset=7, size=8),
             gtirb.Edge.Label(
                 type=gtirb.Edge.Type.Branch,
                 conditional=True,
                 direct=False,
             ),
         )
     )
     string = repr(node)
     new_node = eval(string)
     self.assertTrue(node.deep_eq(new_node))
示例#2
0
 def test_nx(self):
     b1, b2 = gtirb.ProxyBlock(), gtirb.ProxyBlock()
     cfg = gtirb.CFG(
         [gtirb.Edge(b1, b2, gtirb.Edge.Label(gtirb.Edge.Type.Call))])
     for n1, n2, lab in cfg.nx().edges(data="label"):
         self.assertEqual(n1, b1)
         self.assertEqual(n2, b2)
         self.assertEqual(lab, gtirb.Edge.Label(gtirb.Edge.Type.Call))
示例#3
0
 def test_add(self):
     b1, b2 = gtirb.ProxyBlock(), gtirb.ProxyBlock()
     cfg = gtirb.CFG()
     cfg.add(gtirb.Edge(b1, b2))
     cfg.add(gtirb.Edge(b1, b2))
     cfg.add(gtirb.Edge(b1, b2, gtirb.Edge.Label(gtirb.Edge.Type.Branch)))
     self.assertEqual(len(cfg), 2)
     self.assertTrue(gtirb.Edge(b1, b2) in cfg)
     self.assertTrue(
         gtirb.Edge(b1, b2, gtirb.Edge.Label(gtirb.Edge.Type.Branch)) in
         cfg)
示例#4
0
 def test_in_edges(self):
     b1, b2, b3 = gtirb.ProxyBlock(), gtirb.ProxyBlock(), gtirb.ProxyBlock()
     b4 = gtirb.CodeBlock(offset=0, size=1)
     cfg = gtirb.CFG([
         gtirb.Edge(b1, b2, gtirb.Edge.Label(gtirb.Edge.Type.Fallthrough)),
         gtirb.Edge(b3, b2, gtirb.Edge.Label(gtirb.Edge.Type.Branch)),
         gtirb.Edge(b1, b3),
     ])
     self.assertEqual(sum(1 for _ in cfg.in_edges(b1)), 0)
     self.assertEqual(sum(1 for _ in cfg.in_edges(b2)), 2)
     self.assertEqual(sum(1 for _ in cfg.in_edges(b3)), 1)
     self.assertEqual(sum(1 for _ in cfg.in_edges(b4)), 0)
示例#5
0
 def test_contains(self):
     b1, b2 = gtirb.ProxyBlock(), gtirb.ProxyBlock()
     cfg = gtirb.CFG(
         [gtirb.Edge(b1, b2, gtirb.Edge.Label(gtirb.Edge.Type.Branch))])
     self.assertFalse(
         gtirb.Edge(gtirb.ProxyBlock(), gtirb.ProxyBlock()) in cfg)
     self.assertFalse(
         gtirb.Edge(b1, b2, gtirb.Edge.Label(gtirb.Edge.Type.Fallthrough))
         in cfg)
     self.assertTrue(
         gtirb.Edge(b1, b2, gtirb.Edge.Label(gtirb.Edge.Type.Branch)) in
         cfg)
示例#6
0
    def test_clear(self):
        cfg = gtirb.CFG([
            gtirb.Edge(gtirb.ProxyBlock(), gtirb.ProxyBlock()),
            gtirb.Edge(
                gtirb.CodeBlock(offset=0, size=1),
                gtirb.CodeBlock(offset=1, size=2),
            ),
        ])
        self.assertEqual(len(cfg), 2)

        cfg.clear()
        self.assertEqual(len(cfg), 0)
示例#7
0
    def test_discard(self):
        b1, b2 = gtirb.ProxyBlock(), gtirb.CodeBlock(offset=0, size=1)
        cfg = gtirb.CFG([
            gtirb.Edge(b1, b2),
            gtirb.Edge(gtirb.ProxyBlock(), gtirb.CodeBlock(offset=1, size=2)),
        ])
        self.assertEqual(len(cfg), 2)

        cfg.discard(gtirb.Edge(b1, b2))
        self.assertEqual(len(cfg), 1)
        self.assertFalse(gtirb.Edge(b1, b2) in cfg)

        cfg.discard(gtirb.Edge(b1, b2))
        self.assertEqual(len(cfg), 1)
        self.assertFalse(gtirb.Edge(b1, b2) in cfg)
示例#8
0
    def test_cfg(self):
        id1 = uuid.uuid4()
        id2 = uuid.uuid4()

        e1 = gtirb.CFG(
            [
                gtirb.Edge(
                    gtirb.CodeBlock(size=1, uuid=id1),
                    gtirb.CodeBlock(size=2, uuid=id2),
                    gtirb.Edge.Label(
                        type=gtirb.Edge.Type.Branch,
                        conditional=True,
                        direct=False,
                    ),
                )
            ]
        )
        self.assertFalse(
            e1.deep_eq(
                [
                    gtirb.Edge(
                        gtirb.CodeBlock(size=1, uuid=id1),
                        gtirb.CodeBlock(size=2, uuid=id2),
                        gtirb.Edge.Label(
                            type=gtirb.Edge.Type.Branch,
                            conditional=True,
                            direct=False,
                        ),
                    )
                ]
            )
        )

        e2 = gtirb.CFG(
            [
                gtirb.Edge(
                    gtirb.CodeBlock(size=1, uuid=id1),
                    gtirb.CodeBlock(size=2, uuid=id2),
                    gtirb.Edge.Label(
                        type=gtirb.Edge.Type.Branch,
                        conditional=True,
                        direct=False,
                    ),
                )
            ]
        )
        self.assertTrue(e1.deep_eq(e2))

        e2 = gtirb.CFG(
            [
                gtirb.Edge(
                    gtirb.CodeBlock(size=3, uuid=id1),
                    gtirb.CodeBlock(size=2, uuid=id2),
                    gtirb.Edge.Label(
                        type=gtirb.Edge.Type.Branch,
                        conditional=True,
                        direct=False,
                    ),
                )
            ]
        )
        self.assertFalse(e1.deep_eq(e2))

        e2 = gtirb.CFG(
            [
                gtirb.Edge(
                    gtirb.CodeBlock(size=1, uuid=id1),
                    gtirb.CodeBlock(size=3, uuid=id2),
                    gtirb.Edge.Label(
                        type=gtirb.Edge.Type.Branch,
                        conditional=True,
                        direct=False,
                    ),
                )
            ]
        )
        self.assertFalse(e1.deep_eq(e2))

        e2 = gtirb.CFG(
            [
                gtirb.Edge(
                    gtirb.CodeBlock(size=1, uuid=id1),
                    gtirb.CodeBlock(size=2, uuid=id2),
                    gtirb.Edge.Label(
                        type=gtirb.Edge.Type.Fallthrough,
                        conditional=True,
                        direct=False,
                    ),
                )
            ]
        )
        self.assertFalse(e1.deep_eq(e2))

        e2 = gtirb.CFG(
            [
                gtirb.Edge(
                    gtirb.CodeBlock(size=1, uuid=id1),
                    gtirb.CodeBlock(size=2, uuid=id2),
                    gtirb.Edge.Label(
                        type=gtirb.Edge.Type.Branch,
                        conditional=False,
                        direct=False,
                    ),
                )
            ]
        )
        self.assertFalse(e1.deep_eq(e2))

        e2 = gtirb.CFG(
            [
                gtirb.Edge(
                    gtirb.CodeBlock(size=1, uuid=id1),
                    gtirb.CodeBlock(size=2, uuid=id2),
                    gtirb.Edge.Label(
                        type=gtirb.Edge.Type.Branch,
                        conditional=True,
                        direct=True,
                    ),
                )
            ]
        )
        self.assertFalse(e1.deep_eq(e2))