Exemple #1
0
    def test_apply_inlining_for_incremental_algo(self):
        load_from_string("""
            MODULE main
            VAR     v : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            v = enc.by_name['v'].boolean_expression

            cond = v & v & v | v
            self.assertEqual(
                cond.inline(True),
                bmcutils.apply_inlining_for_incremental_algo(cond))

            cond = v | -v
            self.assertEqual(
                cond.inline(True),
                bmcutils.apply_inlining_for_incremental_algo(cond))

            cond = v & -v
            self.assertEqual(
                cond.inline(True),
                bmcutils.apply_inlining_for_incremental_algo(cond))
Exemple #2
0
    def test_fill_counter_example(self):
        load_from_string("""
            MODULE main
            VAR     v : boolean;
                    w : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
                    init(w) := FALSE;
                    next(w) := !w;
            """)
        with BmcSupport():
            bound = 2
            fsm = master_be_fsm()
            sexpfsm = master_bool_sexp_fsm()
            expr = Node.from_ptr(parse_ltl_spec("F ( w <-> v )"))

            pb = generate_ltl_problem(fsm, expr, bound=bound)
            cnf = pb.inline(True).to_cnf()

            solver = SatSolverFactory.create()
            solver += cnf
            solver.polarity(cnf, Polarity.POSITIVE)
            self.assertEqual(SatSolverResult.SATISFIABLE, solver.solve())

            trace = Trace.create("FILLED", TraceType.COUNTER_EXAMPLE,
                                 sexpfsm.symbol_table, sexpfsm.symbols_list,
                                 True)

            bmcutils.fill_counter_example(fsm, solver, bound, trace)
            self.assertIsNotNone(trace)
            self.assertEqual(2, len(trace))
            print(trace)
Exemple #3
0
 def test_make_negated_nnf_boolean_wff(self):
     load_from_string("""
         MODULE main
         VAR     v : boolean;
                 w : boolean;
         ASSIGN  init(v) := TRUE; 
                 next(v) := !v;
         """)
     with BmcSupport():
         expr = Node.from_ptr(parse_ltl_spec("F G ( w <-> v )"))
         wff = bmcutils.make_negated_nnf_boolean_wff(expr)
         self.assertEquals(" F ( G (w <-> v))", str(expr))
         # Via De Morgan Laws
         self.assertEquals(" G ( F ((v & !w) | (!v & w)))", str(wff))
Exemple #4
0
 def test_make_nnf_boolean_wff(self):
     load_from_string("""
         MODULE main
         VAR     v : boolean;
                 w : boolean;
         ASSIGN  init(v) := TRUE; 
                 next(v) := !v;
         """)
     with BmcSupport():
         expr = Node.from_ptr(parse_ltl_spec("F G ( w <-> v )"))
         wff = bmcutils.make_nnf_boolean_wff(expr)
         self.assertEquals(" F ( G (w <-> v))", str(expr))
         self.assertEquals(" F ( G ((!v | w) & (v | !w)))", str(wff))
         self.assertEquals(Wff, type(wff))
Exemple #5
0
 def test_dump_problem(self):
     load_from_string("""
         MODULE main
         VAR     v : boolean;
                 w : boolean;
         ASSIGN  init(v) := TRUE; 
                 next(v) := !v;
         LTLSPEC F G ( w <-> v )
         """)
     with BmcSupport():
         fsm = master_be_fsm()
         for prop in prop_database():
             pb = generate_ltl_problem(fsm, prop.expr)
             bmcutils.dump_problem(fsm.encoding, pb.to_cnf(), prop, 10, 0,
                                   bmcutils.DumpType.DIMACS, "dimacs_dump")
Exemple #6
0
 def test_booleanize(self):
     load_from_string("""
         MODULE main
         VAR
             -- requires two bits
             i : 0..3;
             -- requires no transformation
             b : boolean;
         """)
     with BmcSupport():
         # fails for non existing symbols
         with self.assertRaises(ValueError):
             bmcutils.booleanize("c")
         # works as expected for existing vars
         self.assertEqual("[i.1, i.0]", str(bmcutils.booleanize("i")))
         self.assertEqual("[b]", str(bmcutils.booleanize("b")))
Exemple #7
0
 def test_get_symbol(self):
     load_from_string("""
         MODULE main
         VAR       w : boolean;
         IVAR      x : boolean;
         FROZENVAR y : boolean;
         DEFINE  z := (x & w);
         """)
     with BmcSupport():
         # fails when not found
         with self.assertRaises(ValueError):
             bmcutils.get_symbol("a")
         # works for all types of vars
         self.assertEqual("w", str(bmcutils.get_symbol("w")))
         self.assertEqual("x", str(bmcutils.get_symbol("x")))
         self.assertEqual("y", str(bmcutils.get_symbol("y")))
         self.assertEqual("z", str(bmcutils.get_symbol("z")))
Exemple #8
0
    def test_loop_condition_single_var(self):
        # test case 1: model with one single var
        load_from_string("""
            MODULE main
            VAR     v : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            cond = bmcutils.loop_condition(enc, 3, 1)

            v3 = enc.by_name['v'].at_time[3].boolean_expression
            v1 = enc.by_name['v'].at_time[1].boolean_expression

            cond2 = v1.iff(v3)

            self.assertEqual(cond, cond2)
Exemple #9
0
 def test_loop_condition_consistent_values(self):
     # test case 3: only the state variables are considered
     load_from_string("""
         MODULE main
         IVAR    i : boolean;
         VAR     v : boolean;
                 w : boolean;
         ASSIGN  init(v) := TRUE; 
                 next(v) := !v;
         """)
     with BmcSupport():
         mdl = bmcutils.BmcModel()
         enc = mdl._fsm.encoding
         # loop and bound must be consistent (bound >= 0)
         with self.assertRaises(ValueError):
             bmcutils.loop_condition(enc, -5, 1)
         # loop and bound must be consistent (loop <= bound)
         with self.assertRaises(ValueError):
             bmcutils.loop_condition(enc, 2, 5)
Exemple #10
0
    def test_apply_inlining(self):
        load_from_string("""
            MODULE main
            VAR     v : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            mgr = enc.manager
            v = enc.by_name['v'].boolean_expression

            cond = v & v & v | v
            self.assertEqual(v, bmcutils.apply_inlining(cond))

            cond = v | -v
            self.assertEqual(Be.true(mgr), bmcutils.apply_inlining(cond))

            cond = v & -v
            self.assertEqual(Be.false(mgr), bmcutils.apply_inlining(cond))
Exemple #11
0
    def test_loop_condition_two_var(self):
        # test case 1: model with one more variables
        load_from_string("""
            MODULE main
            VAR     v : boolean;
                    w : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            cond = bmcutils.loop_condition(enc, 3, 1)

            v = enc.by_name['v']
            w = enc.by_name['w']

            cond2 = (v.at_time[1].boolean_expression.iff(
                v.at_time[3].boolean_expression)
                     & w.at_time[1].boolean_expression.iff(
                         w.at_time[3].boolean_expression))

            self.assertEqual(cond, cond2)
Exemple #12
0
    def test_loop_condition_not_only_state(self):
        # test case 3: only the state variables are considered
        load_from_string("""
            MODULE main
            IVAR    i : boolean;
            VAR     v : boolean;
                    w : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            cond = bmcutils.loop_condition(enc, 3, 1)

            v = enc.by_name['v']
            w = enc.by_name['w']

            cond2 = (v.at_time[1].boolean_expression.iff(
                v.at_time[3].boolean_expression)
                     & w.at_time[1].boolean_expression.iff(
                         w.at_time[3].boolean_expression))

            self.assertEqual(cond, cond2)