Пример #1
0
    def struct_maker():
        import esbmc
        alist = [esbmc.type.unsignedbv.make(x) for x in range(1, 5)]
        namelist = [esbmc.irep_idt(x) for x in ["a", "b", "c", "d"]]

        tlist = esbmc.type.type_vec()
        tlist.extend(alist)
        ilist = esbmc.irep_idt_vec()
        ilist.extend(namelist)

        # Pretty names = names
        struct = esbmc.type.struct.make(tlist, ilist, ilist, esbmc.irep_idt("fgasdf"))
        return struct
Пример #2
0
    def test_iter_detach(self):
        import esbmc
        # Build a nontrivial expr
        foo = self.make_int()
        ubv = self.make_unsigned()
        idt = esbmc.irep_idt("fgasfd")
        lev = esbmc.expr.symbol_renaming.level0
        sym = esbmc.expr.symbol.make(ubv, idt, lev, 0, 0, 0, 0)
        add = esbmc.expr.add.make(ubv, foo, sym)

        addclone = add.clone()
        it = iter(addclone)
        obj1 = next(it)
        self.assertTrue(obj1 == foo, "Object iterator obj1 not as expected")
        obj2 = next(it)
        self.assertTrue(obj2 == sym, "Object iterator obj2 not as expected")

        try:
            next(it)
            self.assertTrue(
                False, "Object iterator should not have completed 3rd time")
        except StopIteration:
            pass

        obj2 = esbmc.downcast_expr(obj2)
        self.assertTrue(esbmc.expr.expr_ids.symbol == obj2.expr_id,
                        "Downcasted symbol should be sym id'd")
        obj2.iknowwhatimdoing_level2_num = 1
        self.assertTrue(obj2.level2_num != sym.level2_num,
                        "Iterated object should have detached from original")
Пример #3
0
    def test_iter_detach(self):
        import esbmc
        # Build a nontrivial expr
        foo = self.make_int()
        ubv = self.make_unsigned()
        idt = esbmc.irep_idt("fgasfd")
        lev = esbmc.expr.symbol_renaming.level0
        sym = esbmc.expr.symbol.make(ubv, idt, lev, 0, 0, 0, 0)
        add = esbmc.expr.add.make(ubv, foo, sym)

        addclone = add.clone()
        it = iter(addclone)
        obj1 = next(it)
        self.assertTrue(obj1 == foo, "Object iterator obj1 not as expected")
        obj2 = next(it)
        self.assertTrue(obj2 == sym, "Object iterator obj2 not as expected")

        try:
            next(it)
            self.assertTrue(False, "Object iterator should not have completed 3rd time")
        except StopIteration:
            pass

        obj2 = esbmc.downcast_expr(obj2)
        self.assertTrue(esbmc.expr.expr_ids.symbol == obj2.expr_id, "Downcasted symbol should be sym id'd")
        obj2.iknowwhatimdoing_level2_num = 1
        self.assertTrue(obj2.level2_num != sym.level2_num, "Iterated object should have detached from original")
Пример #4
0
 def setUp(self):
     import esbmc
     # cwd = regression/python
     self.ns, self.opts, self.po = esbmc.init_esbmc_process(
         ['test_data/00_big_endian_01/main.c', '--big-endian', '--bv'])
     self.funcs = self.po.goto_functions
     self.main = self.funcs.function_map[esbmc.irep_idt('c::main')].body
Пример #5
0
 def setUp(self):
     import esbmc
     # cwd = regression/python
     self.ns, self.opts, self.po = esbmc.init_esbmc_process(['test_data/00_big_endian_01/main.c', '--big-endian', '--bv'])
     self.funcs = self.po.goto_functions
     self.main = self.funcs.function_map[esbmc.irep_idt('main')].body
     self.insns = self.main.get_instructions()
Пример #6
0
 def setUp(self):
     import esbmc
     # cwd = regression/python
     self.ns, self.opts, self.po = esbmc.init_esbmc_process(['test_data/00_big_endian_01/main.c', '--big-endian', '--bv'])
     self.funcs = self.po.goto_functions
     self.main = self.funcs.function_map[esbmc.irep_idt('main')].body
     self.eq = esbmc.symex.equation(self.ns)
     self.art = esbmc.symex.reachability_tree(self.po.goto_functions, self.ns, self.opts, self.eq, self.po.context, self.po.message_handler)
Пример #7
0
 def test_symbol(self):
     import esbmc
     u32 = self.make_unsigned()
     name = esbmc.irep_idt("fgasdf")
     sym = esbmc.expr.symbol.make(u32, name, esbmc.expr.symbol_renaming.level2, 1, 2, 3, 4)
     self.assertTrue(sym.type == u32, "Symbol has wrong type")
     self.assertTrue(sym.name == name, "Symbol has wrong name")
     self.assertTrue(sym.renamelev == esbmc.expr.symbol_renaming.level2, "Symbol has wrong renaming level")
     self.assertTrue(sym.level1_num == 1, "Symbol has wrong level1 num")
     self.assertTrue(sym.level2_num == 2, "Symbol has wrong level2 num")
     self.assertTrue(sym.thread_num == 3, "Symbol has wrong thread num")
     self.assertTrue(sym.node_num == 4, "Symbol has wrong node num")
Пример #8
0
 def setUp(self):
     import esbmc
     # cwd = regression/python
     self.ns, self.opts, self.po = esbmc.init_esbmc_process(['test_data/00_big_endian_01/main.c', '--big-endian', '--bv'])
     self.funcs = self.po.goto_functions
     self.main = self.funcs.function_map[esbmc.irep_idt('main')].body
     self.eq = esbmc.symex.equation(self.ns)
     self.art = esbmc.symex.reachability_tree(self.po.goto_functions, self.ns, self.opts, self.eq, self.po.context, self.po.message_handler)
     # Step that art once...
     self.art.setup_for_new_explore()
     self.art.get_cur_state().symex_step(self.art)
     self.curstate = self.art.get_cur_state()
Пример #9
0
 def setUp(self):
     import esbmc
     # cwd = regression/python
     self.ns, self.opts, self.po = esbmc.init_esbmc_process(
         ['test_data/00_big_endian_01/main.c', '--big-endian', '--bv'])
     self.funcs = self.po.goto_functions
     self.main = self.funcs.function_map[esbmc.irep_idt('c::main')].body
     self.eq = esbmc.symex.equation(self.ns)
     self.art = esbmc.symex.reachability_tree(self.po.goto_functions,
                                              self.ns, self.opts, self.eq,
                                              self.po.context,
                                              self.po.message_handler)
Пример #10
0
 def test_symbol(self):
     import esbmc
     u32 = self.make_unsigned()
     name = esbmc.irep_idt("fgasdf")
     sym = esbmc.expr.symbol.make(u32, name, esbmc.expr.symbol_renaming.level2, 1, 2, 3, 4)
     self.assertTrue(sym.type == u32, "Symbol has wrong type")
     self.assertTrue(sym.name == name, "Symbol has wrong name")
     self.assertTrue(sym.renamelev == esbmc.expr.symbol_renaming.level2, "Symbol has wrong renaming level")
     self.assertTrue(sym.level1_num == 1, "Symbol has wrong level1 num")
     self.assertTrue(sym.level2_num == 2, "Symbol has wrong level2 num")
     self.assertTrue(sym.thread_num == 3, "Symbol has wrong thread num")
     self.assertTrue(sym.node_num == 4, "Symbol has wrong node num")
Пример #11
0
 def setUp(self):
     import esbmc
     # cwd = regression/python
     self.ns, self.opts, self.po = esbmc.init_esbmc_process(
         ['test_data/00_big_endian_01/main.c', '--big-endian', '--bv'])
     self.funcs = self.po.goto_functions
     self.main = self.funcs.function_map[esbmc.irep_idt('c::main')].body
     self.eq = esbmc.symex.equation(self.ns)
     self.art = esbmc.symex.reachability_tree(self.po.goto_functions,
                                              self.ns, self.opts, self.eq,
                                              self.po.context,
                                              self.po.message_handler)
     # Step that art once...
     self.art.setup_for_new_explore()
     self.art.get_cur_state().symex_step(self.art)
     self.curstate = self.art.get_cur_state()
Пример #12
0
    def test_sym_compare(self):
        import esbmc
        # Build an expr we indirectly access and a symbol
        foo = self.make_int()
        ubv = self.make_unsigned()
        add = esbmc.expr.add.make(ubv, foo, foo)
        idt = esbmc.irep_idt("fgasfd")
        lev = esbmc.expr.symbol_renaming.level0
        sym = esbmc.expr.symbol.make(ubv, idt, lev, 0, 0, 0, 0)

        # Problem: when we downcast this b.p knows that 'sym' is a symbol2tc.
        # But it doesn't know for some reason that it can just cast that to
        # a expr2tc, via inheritance. Test for this -- __eq__ returns
        # NotImplemented when the operator== call construction fails.
        sym = esbmc.downcast_expr(sym)
        foo2 = add.side_1
        self.assertFalse(foo2.__eq__(sym) == NotImplemented, "Downcasted expr should be castable to expr2tc")
Пример #13
0
    def test_sym_compare(self):
        import esbmc
        # Build an expr we indirectly access and a symbol
        foo = self.make_int()
        ubv = self.make_unsigned()
        add = esbmc.expr.add.make(ubv, foo, foo)
        idt = esbmc.irep_idt("fgasfd")
        lev = esbmc.expr.symbol_renaming.level0
        sym = esbmc.expr.symbol.make(ubv, idt, lev, 0, 0, 0, 0)

        # Problem: when we downcast this b.p knows that 'sym' is a symbol2tc.
        # But it doesn't know for some reason that it can just cast that to
        # a expr2tc, via inheritance. Test for this -- __eq__ returns
        # NotImplemented when the operator== call construction fails.
        sym = esbmc.downcast_expr(sym)
        foo2 = add.side_1
        self.assertFalse(foo2.__eq__(sym) == NotImplemented, "Downcasted expr should be castable to expr2tc")
Пример #14
0
    def test_in(self):
        import esbmc
        # Build a nontrivial expr
        foo = self.make_int()
        ubv = self.make_unsigned()
        idt = esbmc.irep_idt("fgasfd")
        lev = esbmc.expr.symbol_renaming.level0
        sym = esbmc.expr.symbol.make(ubv, idt, lev, 0, 0, 0, 0)
        add = esbmc.expr.add.make(ubv, foo, sym)

        nonzero = self.make_int(value=1)

        # Assert that the sub expressions are "in" the composite
        self.assertTrue(foo in add, "Couldn't find subexpression 1 in expr")
        self.assertTrue(sym in add, "Couldn't find subexpression 1 in expr")
        self.assertFalse(nonzero in add, "Separate expr shouldn't be in main expr")
        self.assertTrue(add in add, "Couldn't find expr in itself")
Пример #15
0
    def test_in(self):
        import esbmc
        # Build a nontrivial expr
        foo = self.make_int()
        ubv = self.make_unsigned()
        idt = esbmc.irep_idt("fgasfd")
        lev = esbmc.expr.symbol_renaming.level0
        sym = esbmc.expr.symbol.make(ubv, idt, lev, 0, 0, 0, 0)
        add = esbmc.expr.add.make(ubv, foo, sym)

        nonzero = self.make_int(value=1)

        # Assert that the sub expressions are "in" the composite
        self.assertTrue(foo in add, "Couldn't find subexpression 1 in expr")
        self.assertTrue(sym in add, "Couldn't find subexpression 1 in expr")
        self.assertFalse(nonzero in add,
                         "Separate expr shouldn't be in main expr")
        self.assertTrue(add in add, "Couldn't find expr in itself")
Пример #16
0
    def test_iter(self):
        import esbmc
        # Build a nontrivial expr
        foo = self.make_int()
        ubv = self.make_unsigned()
        idt = esbmc.irep_idt("fgasfd")
        lev = esbmc.expr.symbol_renaming.level0
        sym = esbmc.expr.symbol.make(ubv, idt, lev, 0, 0, 0, 0)
        add = esbmc.expr.add.make(ubv, foo, sym)

        it = iter(add)
        obj1 = next(it)
        self.assertTrue(obj1 == foo, "Object iterator obj1 not as expected")
        obj2 = next(it)
        self.assertTrue(obj2 == sym, "Object iterator obj2 not as expected")
        try:
            next(it)
            self.assertTrue(False, "Object iterator should not have completed 3rd time")
        except StopIteration:
            pass
Пример #17
0
    def test_iter(self):
        import esbmc
        # Build a nontrivial expr
        foo = self.make_int()
        ubv = self.make_unsigned()
        idt = esbmc.irep_idt("fgasfd")
        lev = esbmc.expr.symbol_renaming.level0
        sym = esbmc.expr.symbol.make(ubv, idt, lev, 0, 0, 0, 0)
        add = esbmc.expr.add.make(ubv, foo, sym)

        it = iter(add)
        obj1 = next(it)
        self.assertTrue(obj1 == foo, "Object iterator obj1 not as expected")
        obj2 = next(it)
        self.assertTrue(obj2 == sym, "Object iterator obj2 not as expected")
        try:
            next(it)
            self.assertTrue(
                False, "Object iterator should not have completed 3rd time")
        except StopIteration:
            pass
Пример #18
0
 def test_empty2(self):
     import esbmc
     other_func = self.funcs.function_map[esbmc.irep_idt(
         'c::__ESBMC_atomic_begin')].body
     self.assertTrue(other_func.empty(), "Atomic begin should be empty")
Пример #19
0
 def test_add_function(self):
     import esbmc
     main = self.get_main()
     self.funcs.function_map[esbmc.irep_idt('coveredinbees_add_funcion_test')] = main
Пример #20
0
 def get_main(self):
     import esbmc
     return self.funcs.function_map[esbmc.irep_idt('c::main')]
Пример #21
0
 def test_add_function(self):
     import esbmc
     main = self.get_main()
     self.funcs.function_map[esbmc.irep_idt('coveredinbees_add_funcion_test')] = main
Пример #22
0
 def get_main(self):
     import esbmc
     return self.funcs.function_map[esbmc.irep_idt('main')]
Пример #23
0
 def test_empty2(self):
     import esbmc
     other_func = self.funcs.function_map[esbmc.irep_idt('__ESBMC_atomic_begin')].body
     self.assertTrue(other_func.empty(), "Atomic begin should be empty")