示例#1
0
    def test_sym_exprs(self):
        id1 = uuid.uuid4()
        id2 = uuid.uuid4()

        # SymAddrConst
        s1 = gtirb.SymAddrConst(offset=1,
                                symbol=gtirb.Symbol(name="name",
                                                    payload=None,
                                                    uuid=id1))
        s2 = gtirb.SymAddrConst(offset=1,
                                symbol=gtirb.Symbol(name="name",
                                                    payload=None,
                                                    uuid=id1))
        self.assertTrue(s1.deep_eq(s2))

        s1 = gtirb.SymAddrConst(offset=1,
                                symbol=gtirb.Symbol(name="name",
                                                    payload=None,
                                                    uuid=id1))
        s2 = gtirb.SymAddrConst(offset=2,
                                symbol=gtirb.Symbol(name="name",
                                                    payload=None,
                                                    uuid=id1))
        self.assertFalse(s1.deep_eq(s2))

        s1 = gtirb.SymAddrConst(offset=1,
                                symbol=gtirb.Symbol(name="name1",
                                                    payload=None,
                                                    uuid=id1))
        s2 = gtirb.SymAddrConst(offset=1,
                                symbol=gtirb.Symbol(name="name2",
                                                    payload=None,
                                                    uuid=id1))
        self.assertFalse(s1.deep_eq(s2))

        # SymStackConst
        s1 = gtirb.SymStackConst(offset=1,
                                 symbol=gtirb.Symbol(name="name",
                                                     payload=None,
                                                     uuid=id1))
        s2 = gtirb.SymStackConst(offset=1,
                                 symbol=gtirb.Symbol(name="name",
                                                     payload=None,
                                                     uuid=id1))
        self.assertTrue(s1.deep_eq(s2))

        s1 = gtirb.SymStackConst(offset=1,
                                 symbol=gtirb.Symbol(name="name",
                                                     payload=None,
                                                     uuid=id1))
        s2 = gtirb.SymStackConst(offset=2,
                                 symbol=gtirb.Symbol(name="name",
                                                     payload=None,
                                                     uuid=id1))
        self.assertFalse(s1.deep_eq(s2))

        s1 = gtirb.SymStackConst(offset=1,
                                 symbol=gtirb.Symbol(name="name1",
                                                     payload=None,
                                                     uuid=id1))
        s2 = gtirb.SymStackConst(offset=1,
                                 symbol=gtirb.Symbol(name="name2",
                                                     payload=None,
                                                     uuid=id1))
        self.assertFalse(s1.deep_eq(s2))

        # SymAddrAddr
        s1 = gtirb.SymAddrAddr(
            offset=1,
            scale=2,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        s2 = gtirb.SymAddrAddr(
            offset=1,
            scale=2,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        self.assertTrue(s1.deep_eq(s2))

        s1 = gtirb.SymAddrAddr(
            offset=1,
            scale=2,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        s2 = gtirb.SymAddrAddr(
            offset=2,
            scale=2,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        self.assertFalse(s1.deep_eq(s2))

        s1 = gtirb.SymAddrAddr(
            offset=1,
            scale=2,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        s2 = gtirb.SymAddrAddr(
            offset=1,
            scale=4,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        self.assertFalse(s1.deep_eq(s2))

        s1 = gtirb.SymAddrAddr(
            offset=1,
            scale=2,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        s2 = gtirb.SymAddrAddr(
            offset=1,
            scale=2,
            symbol1=gtirb.Symbol(name="name3", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        self.assertFalse(s1.deep_eq(s2))

        s1 = gtirb.SymAddrAddr(
            offset=1,
            scale=2,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name2", payload=None, uuid=id2),
        )
        s2 = gtirb.SymAddrAddr(
            offset=1,
            scale=2,
            symbol1=gtirb.Symbol(name="name1", payload=None, uuid=id1),
            symbol2=gtirb.Symbol(name="name3", payload=None, uuid=id2),
        )
        self.assertFalse(s1.deep_eq(s2))
示例#2
0
    def test_module(self):
        id1 = uuid.uuid4()
        id2 = uuid.uuid4()
        id3 = uuid.uuid4()
        id4 = uuid.uuid4()
        id5 = uuid.uuid4()
        id6 = uuid.uuid4()
        id7 = uuid.uuid4()
        id8 = uuid.uuid4()

        m1 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertTrue(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("other_value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertTrue(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="other_binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.PE,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.ARM,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="other_name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=5,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=5,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=2, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id4), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id4), ),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym11", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(gtirb.Symbol(name="sym1", uuid=id5), ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect22", uuid=id8),
            ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(gtirb.Section(name="sect2", uuid=id8), ),
            uuid=id1,
        )
        self.assertFalse(m1.deep_eq(m2))

        m2 = gtirb.Module(
            aux_data={"key": gtirb.AuxData("value", "string")},
            binary_path="binary_path",
            file_format=gtirb.Module.FileFormat.ELF,
            isa=gtirb.Module.ISA.X64,
            name="name",
            preferred_addr=1,
            rebase_delta=2,
            entry_point=gtirb.CodeBlock(size=1, uuid=id2),
            proxies=(gtirb.ProxyBlock(uuid=id3), gtirb.ProxyBlock(uuid=id4)),
            symbols=(
                gtirb.Symbol(name="sym1", uuid=id5),
                gtirb.Symbol(name="sym2", uuid=id6),
            ),
            sections=(
                gtirb.Section(name="sect1", uuid=id7),
                gtirb.Section(name="sect2", uuid=id8),
            ),
            uuid=id2,
        )
        self.assertFalse(m1.deep_eq(m2))
示例#3
0
    def test_byte_intervals(self):
        id1 = uuid.uuid4()
        id2 = uuid.uuid4()
        id3 = uuid.uuid4()
        id4 = uuid.uuid4()
        id5 = uuid.uuid4()
        id6 = uuid.uuid4()

        b1 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertTrue(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=None,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"1234",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=8,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=0,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=5, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(gtirb.CodeBlock(size=1, decode_mode=2, offset=3,
                                    uuid=id3), ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    6, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4))
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                7:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                8:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id1,
        )
        self.assertFalse(b1.deep_eq(b2))

        b2 = gtirb.ByteInterval(
            address=1,
            contents=b"abcd",
            size=4,
            initialized_size=4,
            blocks=(
                gtirb.DataBlock(size=1, offset=3, uuid=id2),
                gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id3),
            ),
            symbolic_expressions={
                2:
                gtirb.SymAddrConst(
                    3, gtirb.Symbol(name="name1", payload=4, uuid=id4)),
                3:
                gtirb.SymStackConst(
                    4, gtirb.Symbol(name="name2", payload=8, uuid=id5)),
            },
            uuid=id6,
        )
        self.assertFalse(b1.deep_eq(b2))
示例#4
0
    def test_symbol(self):
        id1 = uuid.uuid4()
        id2 = uuid.uuid4()

        s1 = gtirb.Symbol(name="name", payload=None, uuid=id1)
        s2 = gtirb.Symbol(name="name", payload=None, uuid=id1)
        self.assertTrue(s1.deep_eq(s2))

        s1 = gtirb.Symbol(name="name", payload=5, uuid=id1)
        s2 = gtirb.Symbol(name="name", payload=5, uuid=id1)
        self.assertTrue(s1.deep_eq(s2))

        s1 = gtirb.Symbol(
            name="name",
            payload=gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id1),
            uuid=id1,
        )
        s2 = gtirb.Symbol(
            name="name",
            payload=gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id1),
            uuid=id1,
        )
        self.assertTrue(s1.deep_eq(s2))

        s1 = gtirb.Symbol(name="name1", payload=None, uuid=id1)
        s2 = gtirb.Symbol(name="name2", payload=None, uuid=id1)
        self.assertFalse(s1.deep_eq(s2))

        s1 = gtirb.Symbol(name="name", payload=None, uuid=id1)
        s2 = gtirb.Symbol(name="name", payload=5, uuid=id1)
        self.assertFalse(s1.deep_eq(s2))

        s1 = gtirb.Symbol(
            name="name",
            payload=gtirb.CodeBlock(size=1, decode_mode=2, offset=3, uuid=id1),
            uuid=id1,
        )
        s2 = gtirb.Symbol(
            name="name",
            payload=gtirb.CodeBlock(size=2, decode_mode=2, offset=3, uuid=id1),
            uuid=id1,
        )
        self.assertFalse(s1.deep_eq(s2))

        s1 = gtirb.Symbol(name="name", payload=None, uuid=id1)
        s2 = gtirb.Symbol(name="name", payload=None, uuid=id2)
        self.assertFalse(s1.deep_eq(s2))
示例#5
0
    def test_get_by_uuid(self):
        ir1 = gtirb.IR()
        ir2 = gtirb.IR()

        # test nodes from one IR don't pollute the cache of other IRs
        self.assertIsNone(ir1.get_by_uuid(ir2.uuid))
        self.assertIsNone(ir2.get_by_uuid(ir1.uuid))
        self.assertEqual(ir1.get_by_uuid(ir1.uuid), ir1)
        self.assertEqual(ir2.get_by_uuid(ir2.uuid), ir2)

        m = gtirb.Module(name="M")
        m.ir = ir1
        s = gtirb.Section()
        s.module = m
        bi = gtirb.ByteInterval()
        bi.section = s
        b = gtirb.CodeBlock()
        b.byte_interval = bi
        sym = gtirb.Symbol("test")
        sym.module = m

        # test all nodes are lookupable by any other node type
        self.assertEqual(ir1.get_by_uuid(m.uuid), m)
        self.assertEqual(ir1.get_by_uuid(s.uuid), s)
        self.assertEqual(ir1.get_by_uuid(bi.uuid), bi)
        self.assertEqual(ir1.get_by_uuid(b.uuid), b)
        self.assertEqual(ir1.get_by_uuid(sym.uuid), sym)

        self.assertEqual(m.ir.get_by_uuid(m.uuid), m)
        self.assertEqual(m.ir.get_by_uuid(s.uuid), s)
        self.assertEqual(m.ir.get_by_uuid(bi.uuid), bi)
        self.assertEqual(m.ir.get_by_uuid(b.uuid), b)
        self.assertEqual(m.ir.get_by_uuid(sym.uuid), sym)

        self.assertEqual(s.ir.get_by_uuid(m.uuid), m)
        self.assertEqual(s.ir.get_by_uuid(s.uuid), s)
        self.assertEqual(s.ir.get_by_uuid(bi.uuid), bi)
        self.assertEqual(s.ir.get_by_uuid(b.uuid), b)
        self.assertEqual(s.ir.get_by_uuid(sym.uuid), sym)

        self.assertEqual(bi.ir.get_by_uuid(m.uuid), m)
        self.assertEqual(bi.ir.get_by_uuid(s.uuid), s)
        self.assertEqual(bi.ir.get_by_uuid(bi.uuid), bi)
        self.assertEqual(bi.ir.get_by_uuid(b.uuid), b)
        self.assertEqual(bi.ir.get_by_uuid(sym.uuid), sym)

        self.assertEqual(b.ir.get_by_uuid(m.uuid), m)
        self.assertEqual(b.ir.get_by_uuid(s.uuid), s)
        self.assertEqual(b.ir.get_by_uuid(bi.uuid), bi)
        self.assertEqual(b.ir.get_by_uuid(b.uuid), b)
        self.assertEqual(b.ir.get_by_uuid(sym.uuid), sym)

        self.assertEqual(sym.ir.get_by_uuid(m.uuid), m)
        self.assertEqual(sym.ir.get_by_uuid(s.uuid), s)
        self.assertEqual(sym.ir.get_by_uuid(bi.uuid), bi)
        self.assertEqual(sym.ir.get_by_uuid(b.uuid), b)
        self.assertEqual(sym.ir.get_by_uuid(sym.uuid), sym)

        # test removing a node removes all children as well
        bi.section = None

        self.assertEqual(ir1.get_by_uuid(m.uuid), m)
        self.assertEqual(ir1.get_by_uuid(s.uuid), s)
        self.assertIsNone(ir1.get_by_uuid(bi.uuid))
        self.assertIsNone(ir1.get_by_uuid(b.uuid))
        self.assertEqual(ir1.get_by_uuid(sym.uuid), sym)

        bi.section = s

        self.assertEqual(ir1.get_by_uuid(m.uuid), m)
        self.assertEqual(ir1.get_by_uuid(s.uuid), s)
        self.assertEqual(ir1.get_by_uuid(bi.uuid), bi)
        self.assertEqual(ir1.get_by_uuid(b.uuid), b)
        self.assertEqual(ir1.get_by_uuid(sym.uuid), sym)