def test_sym_expr(self): node = gtirb.SymAddrConst( offset=123, symbol=gtirb.Symbol(name="symbol", payload=gtirb.ProxyBlock()), ) string = repr(node) new_node = eval(string) self.assertEqual(node.offset, new_node.offset) self.assertTrue(node.symbol.deep_eq(new_node.symbol)) node = gtirb.SymStackConst( offset=123, symbol=gtirb.Symbol(name="symbol", payload=gtirb.ProxyBlock()), ) string = repr(node) new_node = eval(string) self.assertEqual(node.offset, new_node.offset) self.assertTrue(node.symbol.deep_eq(new_node.symbol)) node = gtirb.SymAddrAddr( offset=123, scale=2, symbol1=gtirb.Symbol(name="symbol1", payload=gtirb.ProxyBlock()), symbol2=gtirb.Symbol(name="symbol2", payload=gtirb.ProxyBlock()), ) string = repr(node) new_node = eval(string) self.assertEqual(node.offset, new_node.offset) self.assertEqual(node.scale, new_node.scale) self.assertTrue(node.symbol1.deep_eq(new_node.symbol1)) self.assertTrue(node.symbol2.deep_eq(new_node.symbol2))
def test_byte_intervals(self): s = gtirb.Symbol(name="test") se1 = gtirb.SymAddrConst(0, s) se3 = gtirb.SymAddrAddr(0, 1, s, s) bi = gtirb.ByteInterval(address=10, size=5, symbolic_expressions={ 0: se1, 4: se3 }) self.assertEqual(set(bi.symbolic_expressions_at(9)), set()) self.assertEqual(set(bi.symbolic_expressions_at(10)), {(bi, 0, se1)}) self.assertEqual(set(bi.symbolic_expressions_at(11)), set()) self.assertEqual(set(bi.symbolic_expressions_at(13)), set()) self.assertEqual(set(bi.symbolic_expressions_at(14)), {(bi, 4, se3)}) self.assertEqual(set(bi.symbolic_expressions_at(15)), set()) self.assertEqual(set(bi.symbolic_expressions_at(range(0, 9))), set()) self.assertEqual(set(bi.symbolic_expressions_at(range(11, 14))), set()) self.assertEqual(set(bi.symbolic_expressions_at(range(20, 90))), set()) self.assertEqual( set(bi.symbolic_expressions_at(range(0, 90))), {(bi, 0, se1), (bi, 4, se3)}, ) self.assertEqual( set(bi.symbolic_expressions_at(range(10, 15))), {(bi, 0, se1), (bi, 4, se3)}, ) self.assertEqual(set(bi.symbolic_expressions_at(range(11, 18))), {(bi, 4, se3)})
def test_sym_exprs(self): node = gtirb.SymAddrConst( offset=123, symbol=gtirb.Symbol(name="symbol", payload=gtirb.ProxyBlock()), ) self.assertEqual({x.name for x in node.symbols}, {"symbol"}) node = gtirb.SymAddrAddr( offset=123, scale=2, symbol1=gtirb.Symbol(name="symbol1", payload=gtirb.ProxyBlock()), symbol2=gtirb.Symbol(name="symbol2", payload=gtirb.ProxyBlock()), ) self.assertEqual({x.name for x in node.symbols}, {"symbol1", "symbol2"})
def test_sym_expr(self): node = gtirb.SymAddrConst( offset=123, symbol=gtirb.Symbol(name="symbol", payload=gtirb.ProxyBlock()), attributes=set(), ) string = repr(node) new_node = eval(string) self.assertTrue(node.deep_eq(new_node)) node = gtirb.SymAddrAddr( offset=123, scale=2, symbol1=gtirb.Symbol(name="symbol1", payload=gtirb.ProxyBlock()), symbol2=gtirb.Symbol(name="symbol2", payload=gtirb.ProxyBlock()), attributes={ gtirb.SymbolicExpression.Attribute.Adjusted, gtirb.SymbolicExpression.Attribute.Part0, }, ) string = repr(node) new_node = eval(string) self.assertTrue(node.deep_eq(new_node))
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))