Esempio n. 1
0
 def test_constraint_context_sigma(self):
     fsm   = master_be_fsm()
     
     _true = Node.from_ptr(parse_ltl_spec("TRUE"))
     _true = bmcutils.make_nnf_boolean_wff(_true)
     _truen= _true.to_node()
     
     cond  = Wff(parse_ltl_spec("G !(mouse = hover)"))\
                 .to_boolean_wff()\
                 .to_negation_normal_form()
     off_1 = 0
     off_2 = 2
     length= 1
      
     # sigma1
     problem = diagnosability.generate_sat_problem([], (_truen, _truen), length, _true, cond.to_node(), _truen)
     tm_cond = ltlspec.bounded_semantics_at_offset(fsm, cond.to_node(), length, off_1)
     
     canonical_p = tests.canonical_cnf(problem)
     canonical_f = tests.canonical_cnf(tm_cond)
     
     self.assertTrue(all(clause in canonical_p for clause in canonical_f))
     
     # sigma2
     problem = diagnosability.generate_sat_problem([], (_truen, _truen), length, _true, _truen, cond.to_node())
     tm_cond = ltlspec.bounded_semantics_at_offset(fsm, cond.to_node(), length, off_2)
     
     canonical_p = tests.canonical_cnf(problem)
     canonical_f = tests.canonical_cnf(tm_cond)
     
     self.assertTrue(all(clause in canonical_p for clause in canonical_f))
     
Esempio n. 2
0
 def test_until_with_loop(self):
     with tests.Configure(self, __file__, "/example.smv"):
         enc  = self.enc
         i,k,l= 0,2,0
         a    = ast.Proposition("a")
         b    = ast.Proposition("b")
 
         expr = ast.Until(a, b)
         tool = expr.semantic_with_loop(enc, i,k,l)
         
         manual = b.semantic_with_loop(enc, i, k, l) | \
                     (a.semantic_with_loop(enc, i, k, l) & b.semantic_with_loop(enc, i+1, k, l))
         
         
         spec  = Node.from_ptr(parse_ltl_spec("a U b"))
         nusmv = ltlspec.bounded_semantics(self.befsm, spec, bound=k, loop=l)
         
         tool   &= bmcutils.loop_condition(enc, k, l)
         manual &= bmcutils.loop_condition(enc, k, l)
         
         # normalized string representation of the BE's (make them comparable)
         s_tool  = tests.canonical_cnf(tool)
         s_nusmv = tests.canonical_cnf(nusmv)
         s_manual= tests.canonical_cnf(manual)
         
         self.assertEqual(s_tool, s_manual)
         self.assertEqual(s_tool, s_nusmv)
    def test_until_with_loop(self):
        with tests.Configure(self, __file__, "/example.smv"):
            enc = self.enc
            i, k, l = 0, 2, 0
            a = ast.Proposition("a")
            b = ast.Proposition("b")

            expr = ast.Until(a, b)
            tool = expr.semantic_with_loop(enc, i, k, l)

            manual = b.semantic_with_loop(enc, i, k, l) | \
                        (a.semantic_with_loop(enc, i, k, l) & b.semantic_with_loop(enc, i+1, k, l))

            spec = Node.from_ptr(parse_ltl_spec("a U b"))
            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              spec,
                                              bound=k,
                                              loop=l)

            tool &= bmcutils.loop_condition(enc, k, l)
            manual &= bmcutils.loop_condition(enc, k, l)

            # normalized string representation of the BE's (make them comparable)
            s_tool = tests.canonical_cnf(tool)
            s_nusmv = tests.canonical_cnf(nusmv)
            s_manual = tests.canonical_cnf(manual)

            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)
    def test_weak_until_noloop(self):
        with tests.Configure(self, __file__, "/example.smv"):
            enc = self.enc
            a = ast.Proposition("a")
            b = ast.Proposition("b")

            expr = ast.WeakUntil(a, b)
            tool = expr.semantic_no_loop(enc, 0, 2)

            manual = (b.semantic_no_loop(enc, 0, 2)
                      | (a.semantic_no_loop(enc, 0, 2) &
                         (b.semantic_no_loop(enc, 1, 2)
                          | (a.semantic_no_loop(enc, 1, 2) &
                             (b.semantic_no_loop(enc, 2, 2))))))

            spec = Node.from_ptr(parse_ltl_spec("a U b"))
            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              spec,
                                              bound=2,
                                              loop=bmcutils.no_loopback())

            # normalized string representation of the BE's (make them comparable)
            s_tool = tests.canonical_cnf(tool)
            s_nusmv = tests.canonical_cnf(nusmv)
            s_manual = tests.canonical_cnf(manual)

            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)
Esempio n. 5
0
    def test_releases(self):
        with Configure(self, __file__, "/models/flipflops.smv"):
            fsm     = self.befsm
            formula = self.nnf("(a V b)")
            
            # bound 0
            offset  = 0
            bound   = 0
            
            ref_expr= ltlspec.bounded_semantics(fsm, formula, bound)
            expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
            self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
            
            # bound 1
            offset  = 0
            bound   = 1
             
            ref_expr= ltlspec.bounded_semantics(fsm, formula, bound)
            expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
#             VERIFIED manually, complains only about the CNF clauses literals and that's OK.
#             self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
            
            # ---- other offset ----             
            #  bound 2
            offset  = 2
            bound   = 1
           
            # because of the way the loop condition is encoded !
            ref_expr= ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, bound, offset)\
                    | ( ltlspec.bounded_semantics_with_loop_at_offset(fsm, formula, 0, bound, 0, offset) 
                      & bmcutils.loop_condition(self.enc, offset+bound, offset+0))
                      
            expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
    def test_eventually_with_loop(self):
        with tests.Configure(self, __file__, "/example.smv"):
            i, k, l = 0, 2, 0
            enc = self.enc
            a = ast.Proposition("a")
            formula = ast.Eventually(a)

            tool = formula.semantic_with_loop(enc, i, k, l)

            manual  = a.semantic_with_loop(enc, i+1, k, l) |\
                      a.semantic_with_loop(enc, i  , k, l)

            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              Node.from_ptr(
                                                  parse_ltl_spec("F a")),
                                              bound=k,
                                              loop=l)

            # normalized string representation of the BE's (make them comparable)
            loop_cond = bmcutils.loop_condition(enc, k, l)
            s_tool = tests.canonical_cnf(tool & loop_cond)
            s_manual = tests.canonical_cnf(manual & loop_cond)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_nusmv, s_tool)
            self.assertEqual(s_manual, s_tool)
Esempio n. 7
0
 def test_eventually_with_loop(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("F (a <-> !b)")
         
         # bound 1
         offset  = 0
         bound   = 1
         loop    = 0
         
         # remember: the NuSMV std apis incorporate the loop condition !
         ref_expr= ltlspec.bounded_semantics_single_loop(fsm, formula, bound, loop)
         expr    = ltlspec.bounded_semantics_with_loop_at_offset(fsm, formula, 0, bound, loop, offset) \
                 & bmcutils.loop_condition(self.enc, bound, loop)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # ---- other offset ----             
         #  bound 2
         offset  = 1
         bound   = 2
         loop    = 0
     
         car     = Wff.decorate(ltlspec.car(formula)).to_be(fsm.encoding)
         # because of the way the loop condition is encoded !
         ref_expr= self.enc.shift_to_time(car, offset)  \
                 | self.enc.shift_to_time(car, offset+1)
         expr    = ltlspec.bounded_semantics_with_loop_at_offset(fsm, formula, 0, bound, loop, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
Esempio n. 8
0
 def test_eventually_with_loop(self):
     with tests.Configure(self, __file__, "/example.smv"):
         i,k,l   = 0,2,0
         enc     = self.enc
         a       = ast.Proposition("a")
         formula = ast.Eventually(a)
         
         tool    = formula.semantic_with_loop(enc, i, k, l)
         
         manual  = a.semantic_with_loop(enc, i+1, k, l) |\
                   a.semantic_with_loop(enc, i  , k, l) 
         
         nusmv   = ltlspec.bounded_semantics(
                     self.befsm, Node.from_ptr(parse_ltl_spec("F a")), 
                     bound = k, 
                     loop  = l)
         
         # normalized string representation of the BE's (make them comparable)
         loop_cond = bmcutils.loop_condition(enc, k, l)
         s_tool  = tests.canonical_cnf(tool   & loop_cond)
         s_manual= tests.canonical_cnf(manual & loop_cond)
         s_nusmv = tests.canonical_cnf(nusmv)
         
         self.assertEqual(s_nusmv,  s_tool)
         self.assertEqual(s_manual, s_tool)
    def test_next_with_loop(self):
        with tests.Configure(self, __file__, "/example.smv"):
            i, k, l = 0, 2, 0
            enc = self.enc

            # One step
            a = ast.Proposition("a")
            formula = ast.Next(a)
            tool = formula.semantic_with_loop(enc, i, k, l)
            manual = a.semantic_with_loop(enc, 1, k, l)
            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              Node.from_ptr(
                                                  parse_ltl_spec("X a")),
                                              bound=k,
                                              loop=l)

            loop_cond = bmcutils.loop_condition(enc, k, l)
            s_tool = tests.canonical_cnf(tool & loop_cond)
            s_manual = tests.canonical_cnf(manual & loop_cond)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_nusmv)
            self.assertEqual(s_tool, s_manual)

            # two steps
            formula = ast.Next(ast.Next(a))
            tool = formula.semantic_with_loop(enc, i, k, l)
            manual = a.semantic_with_loop(enc, 0, k, l)
            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              Node.from_ptr(
                                                  parse_ltl_spec("X X a")),
                                              bound=k,
                                              loop=l)

            loop_cond = bmcutils.loop_condition(enc, k, l)
            s_tool = tests.canonical_cnf(tool & loop_cond)
            s_manual = tests.canonical_cnf(manual & loop_cond)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_nusmv)
            self.assertEqual(s_tool, s_manual)

            # Three steps (getting over k)
            formula = ast.Next(ast.Next(ast.Next(a)))
            tool = formula.semantic_with_loop(enc, i, k, l)
            manual = a.semantic_with_loop(enc, 1, k, l)
            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              Node.from_ptr(
                                                  parse_ltl_spec("X X X a")),
                                              bound=k,
                                              loop=l)

            loop_cond = bmcutils.loop_condition(enc, k, l)
            s_tool = tests.canonical_cnf(tool & loop_cond)
            s_manual = tests.canonical_cnf(manual & loop_cond)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_nusmv)
            self.assertEqual(s_tool, s_manual)
Esempio n. 10
0
 def verify_invariants_constraint(self, bound):
     model  = bmcutils.BmcModel() 
         
     manual = Be.true(self.mgr) 
     for i in range(bound+1):
         manual &= model.invar[i]
     
     tool = gen.invariants_constraint(self.befsm, bound)
     
     self.assertEqual(tests.canonical_cnf(tool), 
                      tests.canonical_cnf(manual))
Esempio n. 11
0
    def verify_invariants_constraint(self, bound):
        model = bmcutils.BmcModel()

        manual = Be.true(self.mgr)
        for i in range(bound + 1):
            manual &= model.invar[i]

        tool = gen.invariants_constraint(self.befsm, bound)

        self.assertEqual(tests.canonical_cnf(tool),
                         tests.canonical_cnf(manual))
Esempio n. 12
0
 def validate_bounded_semantics(self, bound, custom_text, nusmv_text):
     fsm     = self.befsm
     # formulae
     formula = parseLTL(custom_text)
     fml_node= Node.from_ptr(parse_ltl_spec(nusmv_text))
     
     tool = formula.bounded_semantics(fsm, bound)
     smv  = ltlspec.bounded_semantics(fsm, fml_node, bound)
     # canonical forms        
     s_tool  = tests.canonical_cnf(tool)
     s_smv   = tests.canonical_cnf(smv)
      
     self.assertEqual(s_tool, s_smv)
    def validate_bounded_semantics(self, bound, custom_text, nusmv_text):
        fsm = self.befsm
        # formulae
        formula = parseLTL(custom_text)
        fml_node = Node.from_ptr(parse_ltl_spec(nusmv_text))

        tool = formula.bounded_semantics(fsm, bound)
        smv = ltlspec.bounded_semantics(fsm, fml_node, bound)
        # canonical forms
        s_tool = tests.canonical_cnf(tool)
        s_smv = tests.canonical_cnf(smv)

        self.assertEqual(s_tool, s_smv)
Esempio n. 14
0
 def test_next_with_loop(self):
     with tests.Configure(self, __file__, "/example.smv"):
         i,k,l   = 0,2,0
         enc     = self.enc
         
         # One step
         a       = ast.Proposition("a")
         formula = ast.Next(a)
         tool    = formula.semantic_with_loop(enc, i, k, l)
         manual  = a.semantic_with_loop(enc, 1, k, l)
         nusmv   = ltlspec.bounded_semantics(self.befsm, 
                                             Node.from_ptr(parse_ltl_spec("X a")),
                                             bound = k, 
                                             loop  = l)
         
         loop_cond = bmcutils.loop_condition(enc, k, l)
         s_tool  = tests.canonical_cnf(tool   & loop_cond)
         s_manual= tests.canonical_cnf(manual & loop_cond)
         s_nusmv = tests.canonical_cnf(nusmv)
         
         self.assertEqual(s_tool, s_nusmv)
         self.assertEqual(s_tool, s_manual)
         
         # two steps
         formula = ast.Next(ast.Next(a))
         tool    = formula.semantic_with_loop(enc, i, k, l)
         manual  = a.semantic_with_loop(enc, 0, k, l)
         nusmv   = ltlspec.bounded_semantics(self.befsm, 
                                             Node.from_ptr(parse_ltl_spec("X X a")),
                                             bound = k, 
                                             loop  = l)
         
         loop_cond = bmcutils.loop_condition(enc, k, l)
         s_tool  = tests.canonical_cnf(tool   & loop_cond)
         s_manual= tests.canonical_cnf(manual & loop_cond)
         s_nusmv = tests.canonical_cnf(nusmv)
         
         self.assertEqual(s_tool, s_nusmv)
         self.assertEqual(s_tool, s_manual)
          
         # Three steps (getting over k)
         formula = ast.Next(ast.Next(ast.Next(a)))
         tool    = formula.semantic_with_loop(enc, i, k, l)
         manual  = a.semantic_with_loop(enc, 1, k, l)
         nusmv   = ltlspec.bounded_semantics(self.befsm, 
                                             Node.from_ptr(parse_ltl_spec("X X X a")),
                                             bound = k, 
                                             loop  = l)
         
         loop_cond = bmcutils.loop_condition(enc, k, l)
         s_tool  = tests.canonical_cnf(tool   & loop_cond)
         s_manual= tests.canonical_cnf(manual & loop_cond)
         s_nusmv = tests.canonical_cnf(nusmv)
         
         self.assertEqual(s_tool, s_nusmv)
         self.assertEqual(s_tool, s_manual)
Esempio n. 15
0
 def test_next_no_loop(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("X (a <-> !b)")
         
         #  bound 0
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 0)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 1)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # ---- other offset ----
         #  bound 0
         offset  = 1
         ref_expr= Be.false(fsm.encoding.manager)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         #  bound 1
         offset  = 1
         ref_expr= Wff.decorate(ltlspec.car(formula)).to_be(fsm.encoding)
         ref_expr= fsm.encoding.shift_to_time(ref_expr, offset+1)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
Esempio n. 16
0
 def test_globally_no_loop(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("G (a <-> !b)")
         
         #  bound 0
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 0)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 1)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # ---- other offset ----
         #  bound 0
         offset  = 1
         ref_expr= Be.false(fsm.encoding.manager)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         #  bound 1
         offset  = 1
         ref_expr= Be.false(fsm.encoding.manager)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
    def test_next_noloop(self):
        with tests.Configure(self, __file__, "/example.smv"):
            i, k = 0, 2
            enc = self.enc
            # One step
            a = ast.Proposition("a")
            formula = ast.Next(a)
            tool = formula.semantic_no_loop(enc, i, k)
            manual = a.semantic_no_loop(enc, 1, k)
            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              Node.from_ptr(
                                                  parse_ltl_spec("X a")),
                                              bound=k,
                                              loop=bmcutils.no_loopback())

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_nusmv)
            self.assertEqual(s_tool, s_manual)

            # two steps
            formula = ast.Next(ast.Next(a))
            tool = formula.semantic_no_loop(enc, i, k)
            manual = a.semantic_no_loop(enc, 2, k)
            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              Node.from_ptr(
                                                  parse_ltl_spec("X X a")),
                                              bound=k,
                                              loop=bmcutils.no_loopback())

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_nusmv)
            self.assertEqual(s_tool, s_manual)

            # Three steps (getting over k)
            formula = ast.Next(ast.Next(ast.Next(a)))
            tool = formula.semantic_no_loop(enc, i, k)
            manual = Be.false(enc.manager)
            nusmv = ltlspec.bounded_semantics(self.befsm,
                                              Node.from_ptr(
                                                  parse_ltl_spec("X X X a")),
                                              bound=k,
                                              loop=bmcutils.no_loopback())

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_nusmv)
            self.assertEqual(s_tool, s_manual)
Esempio n. 18
0
 def test_next_noloop(self):
     with tests.Configure(self, __file__, "/example.smv"):
         i,k     = 0,2
         enc     = self.enc
         # One step
         a       = ast.Proposition("a")
         formula = ast.Next(a)
         tool    = formula.semantic_no_loop(enc, i, k)
         manual  = a.semantic_no_loop(enc, 1, k)
         nusmv   = ltlspec.bounded_semantics(self.befsm, 
                                             Node.from_ptr(parse_ltl_spec("X a")),
                                             bound = k, 
                                             loop  = bmcutils.no_loopback())
         
         s_tool   = tests.canonical_cnf(tool)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
         
         self.assertEqual(s_tool, s_nusmv)
         self.assertEqual(s_tool, s_manual)
         
         # two steps
         formula = ast.Next(ast.Next(a))
         tool    = formula.semantic_no_loop(enc, i, k)
         manual  = a.semantic_no_loop(enc, 2, k)
         nusmv   = ltlspec.bounded_semantics(self.befsm, 
                                             Node.from_ptr(parse_ltl_spec("X X a")),
                                             bound = k, 
                                             loop  = bmcutils.no_loopback())
         
         s_tool   = tests.canonical_cnf(tool)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
         
         self.assertEqual(s_tool, s_nusmv)
         self.assertEqual(s_tool, s_manual)
         
         # Three steps (getting over k)
         formula = ast.Next(ast.Next(ast.Next(a)))
         tool    = formula.semantic_no_loop(enc, i, k)
         manual  = Be.false(enc.manager)
         nusmv   = ltlspec.bounded_semantics(self.befsm, 
                                             Node.from_ptr(parse_ltl_spec("X X X a")),
                                             bound = k, 
                                             loop  = bmcutils.no_loopback())
         
         s_tool   = tests.canonical_cnf(tool)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
         
         self.assertEqual(s_tool, s_nusmv)
         self.assertEqual(s_tool, s_manual)
Esempio n. 19
0
    def test_model_problem(self):
        with tests.Configure(self, __file__, "/example.smv"):
            enc = self.enc
            # no step taken
            bound = 0

            tool = gen.model_problem(self.befsm, bound)
            manual = enc.shift_to_time(self.befsm.init, 0)

            nusmv = bmcutils.BmcModel().path(bound, with_init=True)

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_nusmv)
            self.assertEqual(s_tool, s_manual)

            # one step taken
            bound = 1

            tool = gen.model_problem(self.befsm, bound)
            manual= enc.shift_to_time(self.befsm.trans,0) &\
                    enc.shift_to_time(self.befsm.init, 0)

            nusmv = bmcutils.BmcModel().path(bound, with_init=True)

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)

            # two steps
            bound = 2

            tool = gen.model_problem(self.befsm, bound)
            manual= enc.shift_to_time(self.befsm.init, 0) &\
                    enc.shift_to_time(self.befsm.trans,0) &\
                    enc.shift_to_time(self.befsm.trans,1)

            nusmv = bmcutils.BmcModel().path(bound, with_init=True)

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)
Esempio n. 20
0
 def test_model_problem(self):
     with tests.Configure(self, __file__, "/example.smv"):
         enc = self.enc
         # no step taken
         bound = 0
          
         tool  = gen.model_problem(self.befsm, bound)
         manual= enc.shift_to_time(self.befsm.init, 0)
          
         nusmv = bmcutils.BmcModel().path(bound, with_init=True)
          
         s_tool   = tests.canonical_cnf(tool)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
          
         self.assertEqual(s_tool, s_nusmv)
         self.assertEqual(s_tool, s_manual)
          
         # one step taken
         bound = 1
          
         tool  = gen.model_problem(self.befsm, bound)
         manual= enc.shift_to_time(self.befsm.trans,0) &\
                 enc.shift_to_time(self.befsm.init, 0)
          
         nusmv = bmcutils.BmcModel().path(bound, with_init=True)
          
         s_tool   = tests.canonical_cnf(tool)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
          
         self.assertEqual(s_tool, s_manual)
         self.assertEqual(s_tool, s_nusmv)
          
         # two steps
         bound = 2
          
         tool  = gen.model_problem(self.befsm, bound)
         manual= enc.shift_to_time(self.befsm.init, 0) &\
                 enc.shift_to_time(self.befsm.trans,0) &\
                 enc.shift_to_time(self.befsm.trans,1)
          
         nusmv = bmcutils.BmcModel().path(bound, with_init=True)
          
         s_tool   = tests.canonical_cnf(tool)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
          
         self.assertEqual(s_tool, s_manual)
         self.assertEqual(s_tool, s_nusmv)
Esempio n. 21
0
 def test_releases_no_loop(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("(a V b)")
         
         #  bound 0
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 0)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 1)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 2 -- verification must be done by hand because the different 
         #           cnf literals mess the comparison
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 2)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 2, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # ---- other offset ----
         #  bound 0
         offset  = 1
         bound   = 0
         
         left    = Wff.decorate(ltlspec.car(formula)).to_be(fsm.encoding)
         right   = Wff.decorate(ltlspec.cdr(formula)).to_be(fsm.encoding)
         ref_expr= self.enc.shift_to_time(right, offset) & self.enc.shift_to_time(left, offset)
           
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
           
         #  bound 1
         offset  = 1
         bound   = 1
         
         left    = Wff.decorate(ltlspec.car(formula)).to_be(fsm.encoding)
         right   = Wff.decorate(ltlspec.cdr(formula)).to_be(fsm.encoding)
         ref_expr= self.enc.shift_to_time(right, offset) & ( self.enc.shift_to_time(left, offset) \
                   | (self.enc.shift_to_time(right, 1+offset) & self.enc.shift_to_time(left, 1+offset)))
           
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
Esempio n. 22
0
 def test_loop_condition(self):
     with tests.Configure(self, __file__, "/example.smv"):
         enc   = self.enc
         a     = enc.by_name['a']
         b     = enc.by_name['b']
         
         # self looping on zero
         _,k,l = 0,0,0
         loop_cond = ast.loop_condition(enc, k, l)
         # note: frozen and ivar are not taken into account
         manual    = a.at_time[0].boolean_expression.iff(a.at_time[0].boolean_expression) &\
                     b.at_time[0].boolean_expression.iff(b.at_time[0].boolean_expression)
         nusmv     = bmcutils.loop_condition(enc, k, l)
                 
         s_tool   = tests.canonical_cnf(loop_cond)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
         self.assertEqual(s_tool, s_manual)
         self.assertEqual(s_tool, s_nusmv)
         
         # simple k-l loop 5 - 0
         _,k,l = 0,5,0
         loop_cond = ast.loop_condition(enc, k, l)
         
         manual    = a.at_time[5].boolean_expression.iff(a.at_time[0].boolean_expression) &\
                     b.at_time[5].boolean_expression.iff(b.at_time[0].boolean_expression)
         nusmv     = bmcutils.loop_condition(enc, k, l)
                 
         s_tool   = tests.canonical_cnf(loop_cond)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
         self.assertEqual(s_tool, s_manual)
         self.assertEqual(s_tool, s_nusmv)
         
         # simple k-l loop 5 - 0
         _,k,l = 0,5,2
         loop_cond = ast.loop_condition(enc, k, l)
         
         manual    = a.at_time[5].boolean_expression.iff(a.at_time[2].boolean_expression) &\
                     b.at_time[5].boolean_expression.iff(b.at_time[2].boolean_expression)
         nusmv     = bmcutils.loop_condition(enc, k, l)
                 
         s_tool   = tests.canonical_cnf(loop_cond)
         s_manual = tests.canonical_cnf(manual)
         s_nusmv  = tests.canonical_cnf(nusmv)
         self.assertEqual(s_tool, s_manual)
         self.assertEqual(s_tool, s_nusmv)
    def test_loop_condition(self):
        with tests.Configure(self, __file__, "/example.smv"):
            enc = self.enc
            a = enc.by_name['a']
            b = enc.by_name['b']

            # self looping on zero
            _, k, l = 0, 0, 0
            loop_cond = ast.loop_condition(enc, k, l)
            # note: frozen and ivar are not taken into account
            manual    = a.at_time[0].boolean_expression.iff(a.at_time[0].boolean_expression) &\
                        b.at_time[0].boolean_expression.iff(b.at_time[0].boolean_expression)
            nusmv = bmcutils.loop_condition(enc, k, l)

            s_tool = tests.canonical_cnf(loop_cond)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)
            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)

            # simple k-l loop 5 - 0
            _, k, l = 0, 5, 0
            loop_cond = ast.loop_condition(enc, k, l)

            manual    = a.at_time[5].boolean_expression.iff(a.at_time[0].boolean_expression) &\
                        b.at_time[5].boolean_expression.iff(b.at_time[0].boolean_expression)
            nusmv = bmcutils.loop_condition(enc, k, l)

            s_tool = tests.canonical_cnf(loop_cond)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)
            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)

            # simple k-l loop 5 - 0
            _, k, l = 0, 5, 2
            loop_cond = ast.loop_condition(enc, k, l)

            manual    = a.at_time[5].boolean_expression.iff(a.at_time[2].boolean_expression) &\
                        b.at_time[5].boolean_expression.iff(b.at_time[2].boolean_expression)
            nusmv = bmcutils.loop_condition(enc, k, l)

            s_tool = tests.canonical_cnf(loop_cond)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)
            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)
Esempio n. 24
0
 def test_next(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("X (a <-> !b)")
         
         # bound 0
         offset  = 0
         bound   = 0
         
         ref_expr= ltlspec.bounded_semantics(fsm, formula, bound)
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         offset  = 0
         bound   = 1
         
         # done this way to avoid the depth 1 optimisation
         car     = Wff.decorate(ltlspec.car(formula)).to_be(fsm.encoding)
         ref_expr= self.enc.shift_to_time(car, offset+1) \
                 | (self.enc.shift_to_time(car, offset) & bmcutils.loop_condition(self.enc, bound, 0))
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
    def test_weak_until_with_loop(self):
        with tests.Configure(self, __file__, "/example.smv"):
            enc = self.enc
            mgr = enc.manager
            i, k, l = 0, 2, 0
            a = ast.Proposition("a")
            b = ast.Proposition("b")

            expr = ast.WeakUntil(a, b)
            tool = expr.semantic_with_loop(enc, i, k, l)

            manual = b.semantic_with_loop(enc, i, k, l) | \
                        (a.semantic_with_loop(enc, i, k, l) & \
                            (b.semantic_with_loop(enc, i+1, k, l) | \
                                a.semantic_with_loop(enc, i+1, k, l) & Be.true(mgr)
                            )
                         )

            # normalized string representation of the BE's (make them comparable)
            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)

            self.assertEqual(s_tool, s_manual)
Esempio n. 26
0
 def test_weak_until_with_loop(self):
     with tests.Configure(self, __file__, "/example.smv"):
         enc  = self.enc
         mgr  = enc.manager
         i,k,l= 0,2,0
         a    = ast.Proposition("a")
         b    = ast.Proposition("b")
 
         expr = ast.WeakUntil(a, b)
         tool = expr.semantic_with_loop(enc, i,k,l)
         
         manual = b.semantic_with_loop(enc, i, k, l) | \
                     (a.semantic_with_loop(enc, i, k, l) & \
                         (b.semantic_with_loop(enc, i+1, k, l) | \
                             a.semantic_with_loop(enc, i+1, k, l) & Be.true(mgr)
                         )
                      )
         
         # normalized string representation of the BE's (make them comparable)
         s_tool  = tests.canonical_cnf(tool)
         s_manual= tests.canonical_cnf(manual)
         
         self.assertEqual(s_tool, s_manual)
    def test_constraint_context_sigma(self):
        fsm = master_be_fsm()

        _true = Node.from_ptr(parse_ltl_spec("TRUE"))
        _true = bmcutils.make_nnf_boolean_wff(_true)
        _truen = _true.to_node()

        cond  = Wff(parse_ltl_spec("G !(mouse = hover)"))\
                    .to_boolean_wff()\
                    .to_negation_normal_form()
        off_1 = 0
        off_2 = 2
        length = 1

        # sigma1
        problem = diagnosability.generate_sat_problem([], (_truen, _truen),
                                                      length, _true,
                                                      cond.to_node(), _truen)
        tm_cond = ltlspec.bounded_semantics_at_offset(fsm, cond.to_node(),
                                                      length, off_1)

        canonical_p = tests.canonical_cnf(problem)
        canonical_f = tests.canonical_cnf(tm_cond)

        self.assertTrue(all(clause in canonical_p for clause in canonical_f))

        # sigma2
        problem = diagnosability.generate_sat_problem([], (_truen, _truen),
                                                      length, _true, _truen,
                                                      cond.to_node())
        tm_cond = ltlspec.bounded_semantics_at_offset(fsm, cond.to_node(),
                                                      length, off_2)

        canonical_p = tests.canonical_cnf(problem)
        canonical_f = tests.canonical_cnf(tm_cond)

        self.assertTrue(all(clause in canonical_p for clause in canonical_f))
Esempio n. 28
0
 def test_weak_until_noloop(self):
     with tests.Configure(self, __file__, "/example.smv"):
         enc  = self.enc
         a    = ast.Proposition("a")
         b    = ast.Proposition("b")
 
         expr = ast.WeakUntil(a, b)
         tool = expr.semantic_no_loop(enc, 0, 2)
         
         manual = ( b.semantic_no_loop(enc, 0, 2) 
                | (a.semantic_no_loop(enc, 0, 2) & (b.semantic_no_loop(enc, 1, 2)
                | (a.semantic_no_loop(enc, 1, 2) & (b.semantic_no_loop(enc, 2, 2))))))
         
         
         spec  = Node.from_ptr(parse_ltl_spec("a U b"))
         nusmv = ltlspec.bounded_semantics(self.befsm, spec, bound=2, loop=bmcutils.no_loopback())
         
         # normalized string representation of the BE's (make them comparable)
         s_tool  = tests.canonical_cnf(tool)
         s_nusmv = tests.canonical_cnf(nusmv)
         s_manual= tests.canonical_cnf(manual)
         
         self.assertEqual(s_tool, s_manual)
         self.assertEqual(s_tool, s_nusmv)
Esempio n. 29
0
 def test_until(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("(a U !b)")
         
         # bound 0
         offset  = 0
         bound   = 0
         
         ref_expr= ltlspec.bounded_semantics(fsm, formula, bound)
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         offset  = 0
         bound   = 1
         
         ref_expr= ltlspec.bounded_semantics(fsm, formula, bound)
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         
         # ---- other offset ----             
         #  bound 0
         offset  = 2
         bound   = 0
     
         cdr     = Wff.decorate(ltlspec.cdr(formula)).to_be(fsm.encoding)
         
         ref_expr= self.enc.shift_to_time(cdr, 0+offset)
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         #  bound 1
         offset  = 2
         bound   = 1
          
         car     = Wff.decorate(ltlspec.car(formula)).to_be(fsm.encoding)
         cdr     = Wff.decorate(ltlspec.cdr(formula)).to_be(fsm.encoding)
         
         ref_expr= self.enc.shift_to_time(cdr, 0+offset) \
                 | (self.enc.shift_to_time(car, 0+offset) & self.enc.shift_to_time(cdr, 1+offset))
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
Esempio n. 30
0
 def test_globally(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("G (a <-> !b)")
         
         # bound 0
         offset  = 0
         bound   = 0
         
         ref_expr= ltlspec.bounded_semantics(fsm, formula, bound)
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         offset  = 0
         bound   = 1
         
         ref_expr= ltlspec.bounded_semantics(fsm, formula, bound)
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         
         # ---- other offset ----             
         #  bound 0
         offset  = 2
         bound   = 0
         
         ref_expr= Be.false(self.enc.manager)
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         #  bound 1
         offset  = 2
         bound   = 1
         
         ref_expr= ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, bound, offset) \
                 |( ltlspec.bounded_semantics_with_loop_at_offset(fsm, formula, 0, bound, 0, offset) \
                 & bmcutils.loop_condition(self.enc, bound+offset, offset))
                 
         expr    = ltlspec.bounded_semantics_at_offset(fsm, formula, bound, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
Esempio n. 31
0
 def test_until_no_loop(self):
     with Configure(self, __file__, "/models/flipflops.smv"):
         fsm     = self.befsm
         formula = self.nnf("(a U b)")
         
         #  bound 0
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 0)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 1
         ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 1)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, 0)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # bound 2 -- verification must be done by hand because the different 
         #           cnf literals mess the comparison
         # ref_expr= ltlspec.bounded_semantics_without_loop(fsm, formula, 2)
         # expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 2, 0)
         # self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
         
         # ---- other offset ----
         #  bound 0
         offset  = 1
         ref_expr= Wff.decorate(ltlspec.cdr(formula)).to_be(fsm.encoding)
         ref_expr= fsm.encoding.shift_to_time(ref_expr, offset)
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 0, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))
          
         #  bound 1
         offset  = 1
         cdr = Wff.decorate(ltlspec.cdr(formula)).to_be(fsm.encoding)
         car = Wff.decorate(ltlspec.car(formula)).to_be(fsm.encoding)
         
         ref_expr= fsm.encoding.shift_to_time(cdr, offset)   \
                 | ( fsm.encoding.shift_to_time(car, offset) \
                   & fsm.encoding.shift_to_time(cdr, offset+1))
                 
         expr    = ltlspec.bounded_semantics_without_loop_at_offset(fsm, formula, 0, 1, offset)
         self.assertEqual(canonical_cnf(expr), canonical_cnf(ref_expr))