Esempio n. 1
0
 def test_state_constraints(self):
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     
     self.assertEqual(p | q, fsm.state_constraints)
Esempio n. 2
0
 def test_init(self):
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     
     self.assertEqual(p & q, fsm.init)
Esempio n. 3
0
 def test_state_constraints(self):
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     
     self.assertEqual(p | q, fsm.state_constraints)
Esempio n. 4
0
 def test_init(self):
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     
     self.assertEqual(p & q, fsm.init)
Esempio n. 5
0
    def test_inputsMask(self):
        fsm = self.model()
        enc = fsm.bddEnc

        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        self.assertEqual(enc.inputsMask, a | ~a)
Esempio n. 6
0
    def test_statesMask(self):
        fsm = self.model()
        enc = fsm.bddEnc

        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        self.assertEqual(enc.statesMask, (p | ~p) & (q | ~q))
Esempio n. 7
0
 def test_reachable_states(self):
     fsm = self.model()
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     
     self.assertEqual(p | q, fsm.reachable_states)
     
     fsm.reachable_states = p & q
     self.assertEqual(p & q, fsm.reachable_states)
Esempio n. 8
0
 def test_statesMask(self):
     fsm = self.model()
     enc = fsm.bddEnc
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertEqual(enc.statesMask, (p | ~p) & (q | ~q))
Esempio n. 9
0
 def test_inputsMask(self):
     fsm = self.model()
     enc = fsm.bddEnc
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertEqual(enc.inputsMask, a | ~a)
Esempio n. 10
0
    def test_inputs_vars_cube(self):
        fsm = self.model()
        enc = fsm.bddEnc

        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        self.assertTrue(a <= enc.cube_for_inputs_vars({'a'}))
Esempio n. 11
0
 def test_inputs_vars_cube(self):
     fsm = self.model()
     enc = fsm.bddEnc
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertTrue(a <= enc.cube_for_inputs_vars({'a'}))
Esempio n. 12
0
 def test_pre(self): 
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertEqual(q, fsm.pre(~p & q))
     self.assertEqual(p & q, fsm.pre(~p & q, a))
Esempio n. 13
0
 def test_reachable_states(self):
     fsm = self.model()
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     
     self.assertEqual(p | q, fsm.reachable_states)
     
     fsm.reachable_states = p & q
     self.assertEqual(p & q, fsm.reachable_states)
Esempio n. 14
0
 def test_pre(self): 
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertEqual(q, fsm.pre(~p & q))
     self.assertEqual(p & q, fsm.pre(~p & q, a))
Esempio n. 15
0
    def test_inputsCube(self):
        fsm = self.model()
        enc = fsm.bddEnc

        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        self.assertTrue(a <= enc.inputsCube)
        self.assertFalse(p & q <= enc.inputsCube)
Esempio n. 16
0
 def test_inputsCube(self):
     fsm = self.model()
     enc = fsm.bddEnc
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertTrue(a <= enc.inputsCube)
     self.assertFalse(p & q <= enc.inputsCube)
Esempio n. 17
0
    def test_count_inputs_no_in_model(self):
        fsm = BddFsm.from_filename("tests/pynusmv/models/modules.smv")
        self.assertIsNotNone(fsm)

        ni = evalSexp(fsm, "n.inmod")
        mi = evalSexp(fsm, "m.inmod")
        top = evalSexp(fsm, "top")
        true = evalSexp(fsm, "TRUE")

        self.assertEqual(0, fsm.count_inputs(ni))
Esempio n. 18
0
 def test_weak_pre(self): 
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertTrue(p & ~q & a <= fsm.weak_pre(p & ~q))
     self.assertTrue(p & q & ~a <= fsm.weak_pre(p & ~q))
     self.assertEqual(p & (~q & a | q & ~a), fsm.weak_pre(p & ~q))
Esempio n. 19
0
    def test_count_inputs_no_in_model(self):
        fsm = BddFsm.from_filename("tests/pynusmv/models/modules.smv")
        self.assertIsNotNone(fsm)

        ni = evalSexp(fsm, "n.inmod")
        mi = evalSexp(fsm, "m.inmod")
        top = evalSexp(fsm, "top")
        true = evalSexp(fsm, "TRUE")

        self.assertEqual(0, fsm.count_inputs(ni))
Esempio n. 20
0
 def test_weak_pre(self): 
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertTrue(p & ~q & a <= fsm.weak_pre(p & ~q))
     self.assertTrue(p & q & ~a <= fsm.weak_pre(p & ~q))
     self.assertEqual(p & (~q & a | q & ~a), fsm.weak_pre(p & ~q))
Esempio n. 21
0
    def test_create_trans_counters_assign(self):

        fsm = self.model("tests/pynusmv/models/counters-assign.smv")

        c1c0bdd = evalSexp(fsm, "c1.c = 0")
        c2c0bdd = evalSexp(fsm, "c2.c = 0")
        c1c1bdd = evalSexp(fsm, "c1.c = 1")
        c2c1bdd = evalSexp(fsm, "c2.c = 1")

        self.assertEqual(c1c0bdd & c2c0bdd, fsm.init)
        self.assertEqual(c1c0bdd & c2c1bdd | c1c1bdd & c2c0bdd,
                         fsm.post(fsm.init))

        fsmbuilder = nscompile.Compile_get_global_fsm_builder()
        enc = nsenc.Enc_get_bdd_encoding()
        ddmanager = nsbddenc.BddEnc_get_dd_manager(enc)
        base_enc = nsbddenc.bddenc2baseenc(enc)
        symb_table = nsbaseenc.BaseEnc_get_symb_table(base_enc)

        propDb = glob.prop_database()
        master = propDb.master

        sexpfsm_ptr = nsprop.Prop_get_scalar_sexp_fsm(master._ptr)

        # Create a new expr trans
        c2c = self.get_variable_from_string(sexpfsm_ptr, "c2.c")
        self.assertIsNotNone(c2c)
        # trans = next(c2c) = (c2.c + 1) % 4
        nextc2c = nssexp.Expr_next(c2c, symb_table)
        one = nsnode.create_node(parser.NUMBER, None, None)
        one.left.nodetype = nsnode.int2node(1)
        self.assertEqual(nsnode.sprint_node(one), "1")
        four = nsnode.create_node(parser.NUMBER, None, None)
        four.left.nodetype = nsnode.int2node(4)
        self.assertEqual(nsnode.sprint_node(four), "4")
        c2cp1 = nssexp.Expr_plus(c2c, one)
        c2cp1m4 = nssexp.Expr_mod(c2cp1, four)
        trans = nssexp.Expr_equal(nextc2c, c2cp1m4, symb_table)

        clusters = nsfsm.FsmBuilder_clusterize_expr(fsmbuilder, enc, trans)
        cluster_options = nsbddtrans.ClusterOptions_create(
            nsopt.OptsHandler_get_instance())

        bddTrans = BddTrans(
            nsbddtrans.BddTrans_create(
                ddmanager, clusters, nsbddenc.BddEnc_get_state_vars_cube(enc),
                nsbddenc.BddEnc_get_input_vars_cube(enc),
                nsbddenc.BddEnc_get_next_state_vars_cube(enc),
                nsopt.get_partition_method(nsopt.OptsHandler_get_instance()),
                cluster_options))

        fsm.trans = bddTrans

        self.assertEqual(c1c0bdd & c2c0bdd, fsm.init)
        self.assertEqual(c2c1bdd, fsm.post(fsm.init))
Esempio n. 22
0
    def test_pick_no_inputs(self):
        fsm = BddFsm.from_filename("tests/pynusmv/models/modules.smv")
        self.assertIsNotNone(fsm)

        ni = evalSexp(fsm, "n.inmod")
        mi = evalSexp(fsm, "m.inmod")
        top = evalSexp(fsm, "top")
        true = evalSexp(fsm, "TRUE")

        with self.assertRaises(NuSMVBddPickingError):
            fsm.pick_all_inputs(ni)
Esempio n. 23
0
    def test_pick_no_inputs(self):
        fsm = BddFsm.from_filename("tests/pynusmv/models/modules.smv")
        self.assertIsNotNone(fsm)

        ni = evalSexp(fsm, "n.inmod")
        mi = evalSexp(fsm, "m.inmod")
        top = evalSexp(fsm, "top")
        true = evalSexp(fsm, "TRUE")

        with self.assertRaises(NuSMVBddPickingError):
            fsm.pick_all_inputs(ni)
Esempio n. 24
0
 def test_count_states_inputs(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertEqual(fsm.count_states_inputs(a), 4)
     self.assertEqual(fsm.count_states_inputs(p & ~a), 2)
     self.assertEqual(fsm.count_states_inputs(true), 8)
     self.assertEqual(fsm.count_states_inputs(false), 0)
Esempio n. 25
0
    def test_pick_states_inputs(self):
        fsm = self.model()

        false = BDD.false(fsm.bddEnc.DDmanager)
        true = BDD.true(fsm.bddEnc.DDmanager)
        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        pstates = fsm.pick_all_states_inputs(p & a)
        self.assertEqual(len(pstates), 2)
        for pstate in pstates:
            self.assertTrue(false < pstate < p)
Esempio n. 26
0
 def test_fairness(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters-fair.smv")
     self.assertIsNotNone(fsm)
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     rc1 = evalSexp(fsm, "run = rc1")
     rc2 = evalSexp(fsm, "run = rc2")
     
     fairBdds = fsm.fairness_constraints
     self.assertEqual(len(fairBdds), 2)
     for fair in fairBdds:
         self.assertTrue(fair == rc1 or fair == rc2)
Esempio n. 27
0
 def test_pick_states_inputs(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     pstates = fsm.pick_all_states_inputs(p & a)
     self.assertEqual(len(pstates), 2)
     for pstate in pstates:
         self.assertTrue(false < pstate < p)
Esempio n. 28
0
 def test_fairness(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters-fair.smv")
     self.assertIsNotNone(fsm)
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     rc1 = evalSexp(fsm, "run = rc1")
     rc2 = evalSexp(fsm, "run = rc2")
     
     fairBdds = fsm.fairness_constraints
     self.assertEqual(len(fairBdds), 2)
     for fair in fairBdds:
         self.assertTrue(fair == rc1 or fair == rc2)
Esempio n. 29
0
 def test_state_values(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     s = fsm.pick_one_state(p & q)
     self.assertEqual(s.get_str_values(),
                      s.get_str_values(layers={"model"}))
     self.assertEqual(s.get_str_values(),
                      {"p": "TRUE", "q": "TRUE"})
Esempio n. 30
0
 def test_count_inputs(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertEqual(fsm.count_inputs(a), 1)
     self.assertEqual(fsm.count_inputs(~a), 1)
     self.assertEqual(fsm.count_inputs(true), 2)
     self.assertEqual(fsm.count_inputs(false), 0)
     self.assertEqual(fsm.count_inputs(p & q & a), 0) # WHY ?
Esempio n. 31
0
 def test_post(self): 
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertEqual(~p & q, fsm.post(~p & q))
     self.assertEqual(p & ~q, fsm.post(p & q, ~a))
     
     self.assertEqual(1, fsm.count_states(fsm.post(~p & q)))
     self.assertEqual(2, fsm.count_states(fsm.post(p & q)))
     self.assertEqual(1, fsm.count_states(fsm.post(p & q, a)))
     self.assertEqual(0, fsm.count_states(fsm.post(p & ~q, ~a)))
Esempio n. 32
0
 def test_pick_one_state_random(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     s = fsm.pick_one_state_random(p)
     self.assertTrue(false < s < p < true)
     
     with self.assertRaises(NuSMVBddPickingError):
         fsm.pick_one_state_random(false)
Esempio n. 33
0
 def test_inputs_values(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     i = fsm.pick_one_inputs(a)
     self.assertEqual(i.get_str_values(),
                      i.get_str_values(layers={"model"}))
     self.assertEqual(i.get_str_values(),
                      {"a": "TRUE"})
Esempio n. 34
0
 def test_post(self): 
     fsm = self.model()
     
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     self.assertEqual(~p & q, fsm.post(~p & q))
     self.assertEqual(p & ~q, fsm.post(p & q, ~a))
     
     self.assertEqual(1, fsm.count_states(fsm.post(~p & q)))
     self.assertEqual(2, fsm.count_states(fsm.post(p & q)))
     self.assertEqual(1, fsm.count_states(fsm.post(p & q, a)))
     self.assertEqual(0, fsm.count_states(fsm.post(p & ~q, ~a)))
Esempio n. 35
0
    def test_pick_one_state_inputs(self):
        fsm = self.model()

        false = BDD.false(fsm.bddEnc.DDmanager)
        true = BDD.true(fsm.bddEnc.DDmanager)
        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        si = fsm.pick_one_state_inputs(a & p)
        self.assertTrue(false < si <= a & p < true)
        self.assertTrue(si.isnot_false())
        self.assertTrue((si == (a & p & q)) | (si == (a & p & ~q)))
        si = fsm.pick_one_state_inputs(true)
        self.assertTrue(false < si < true)
Esempio n. 36
0
 def test_pick_one_inputs_error(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     with self.assertRaises(NuSMVBddPickingError):
         i = fsm.pick_one_inputs(false)
         
     # This does not raise an error since "p" contains all the inputs
     # Thus "i" is any inputs
     i = fsm.pick_one_inputs(p)
Esempio n. 37
0
    def test_pick_one_state_inputs(self):
        fsm = self.model()

        false = BDD.false(fsm.bddEnc.DDmanager)
        true = BDD.true(fsm.bddEnc.DDmanager)
        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        si = fsm.pick_one_state_inputs(a & p)
        self.assertTrue(false < si <= a & p < true)
        self.assertTrue(si.isnot_false())
        self.assertTrue((si == (a & p & q)) | (si == (a & p & ~q)))
        si = fsm.pick_one_state_inputs(true)
        self.assertTrue(false < si < true)
Esempio n. 38
0
 def test_pick_one_inputs_error(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     with self.assertRaises(NuSMVBddPickingError):
         i = fsm.pick_one_inputs(false)
         
     # This does not raise an error since "p" contains all the inputs
     # Thus "i" is any inputs
     i = fsm.pick_one_inputs(p)
Esempio n. 39
0
    def test_bdd_dump_load_input_vars(self):
        fsm = self.model()

        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        bdds = {a, p & a, q & ~a}

        for bdd in bdds:
            with io.StringIO() as f:
                fsm.bddEnc.dump(bdd, f)
                f.seek(0)
                reconstructed = fsm.bddEnc.load(f)
                self.assertEqual(bdd, reconstructed)
Esempio n. 40
0
 def test_pick_one_inputs(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     ac = fsm.pick_one_inputs(a)
     self.assertTrue(false < ac <= a < true)
     self.assertTrue(ac == a)
     self.assertTrue(ac.isnot_false())
     ac = fsm.pick_one_inputs(true)
     self.assertTrue(false < ac < true)
     self.assertTrue(ac == a or ac == ~a)
Esempio n. 41
0
    def test_pick_one_state_inputs_random(self):
        fsm = self.model()

        false = BDD.false(fsm.bddEnc.DDmanager)
        true = BDD.true(fsm.bddEnc.DDmanager)
        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        si = fsm.pick_one_state_inputs_random(a & p)
        self.assertTrue(false < si <= a & p < true)
        self.assertTrue(si.isnot_false())
        self.assertTrue((si == (a & p & q)) | (si == (a & p & ~q)))
        
        with self.assertRaises(NuSMVBddPickingError):
            fsm.pick_one_state_inputs_random(false)
Esempio n. 42
0
 def test_pick_one_inputs(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     ac = fsm.pick_one_inputs(a)
     self.assertTrue(false < ac <= a < true)
     self.assertTrue(ac == a)
     self.assertTrue(ac.isnot_false())
     ac = fsm.pick_one_inputs(true)
     self.assertTrue(false < ac < true)
     self.assertTrue(ac == a or ac == ~a)
Esempio n. 43
0
 def test_pick_one_inputs_random(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     ac = fsm.pick_one_inputs_random(a)
     self.assertTrue(false < ac <= a < true)
     self.assertTrue(ac == a)
     self.assertTrue(ac.isnot_false())
     
     with self.assertRaises(NuSMVBddPickingError):
         fsm.pick_one_inputs_random(false)
Esempio n. 44
0
 def test_pick_one_state(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     s = fsm.pick_one_state(p)
     self.assertTrue(false < s < p < true)
     with self.assertRaises(NuSMVBddPickingError):
         s = fsm.pick_one_state(false)
     s = fsm.pick_one_state(true)
     self.assertTrue(s.isnot_false())
     self.assertTrue(false < s < p < true or false < s < ~p < true)
     self.assertTrue(false < s < q < true or false < s < ~q < true)
Esempio n. 45
0
 def test_pick_one_state(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     s = fsm.pick_one_state(p)
     self.assertTrue(false < s < p < true)
     with self.assertRaises(NuSMVBddPickingError):
         s = fsm.pick_one_state(false)
     s = fsm.pick_one_state(true)
     self.assertTrue(s.isnot_false())
     self.assertTrue(false < s < p < true or false < s < ~p < true)
     self.assertTrue(false < s < q < true or false < s < ~q < true)
Esempio n. 46
0
 def test_get_inputs(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     ac = fsm.get_inputs_between_states(p & q, p & ~q)
     self.assertTrue(ac == ~a)
     ac = fsm.get_inputs_between_states(p, p)
     self.assertTrue(ac == true)
     
     self.assertTrue(q == (p & q) | (~p & q))
     self.assertTrue(q.iff(~p) == (~p & q) | (p & ~q))
     ac = fsm.get_inputs_between_states(q, q.iff(~p))
     self.assertTrue(ac == true)
Esempio n. 47
0
 def test_get_inputs(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     ac = fsm.get_inputs_between_states(p & q, p & ~q)
     self.assertTrue(ac == ~a)
     ac = fsm.get_inputs_between_states(p, p)
     self.assertTrue(ac == true)
     
     self.assertTrue(q == (p & q) | (~p & q))
     self.assertTrue(q.iff(~p) == (~p & q) | (p & ~q))
     ac = fsm.get_inputs_between_states(q, q.iff(~p))
     self.assertTrue(ac == true)
Esempio n. 48
0
    def test_pick_inputs(self):
        fsm = self.model()

        false = BDD.false(fsm.bddEnc.DDmanager)
        true = BDD.true(fsm.bddEnc.DDmanager)
        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        ainputs = fsm.pick_all_inputs(a)
        self.assertEqual(len(ainputs), 1)
        for ainput in ainputs:
            self.assertTrue(false < ainput <= a)
            self.assertTrue(ainput == a)

        tinputs = fsm.pick_all_inputs(true)
        self.assertEqual(len(tinputs), 2)
        for tinput in tinputs:
            self.assertTrue(tinput == a or tinput == ~a)

        pinputs = fsm.pick_all_states(p)
        self.assertEqual(len(pinputs), 2)  # Contains all inputs
Esempio n. 49
0
 def test_pick_inputs(self):
     fsm = self.model()
     
     false = BDD.false(fsm.bddEnc.DDmanager)
     true = BDD.true(fsm.bddEnc.DDmanager)
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     a = evalSexp(fsm, "a")
     
     ainputs = fsm.pick_all_inputs(a)
     self.assertEqual(len(ainputs), 1)
     for ainput in ainputs:
         self.assertTrue(false < ainput <= a)
         self.assertTrue(ainput == a)
     
     tinputs = fsm.pick_all_inputs(true)
     self.assertEqual(len(tinputs), 2)
     for tinput in tinputs:
         self.assertTrue(tinput == a or tinput == ~a)
     
     pinputs = fsm.pick_all_states(p)
     self.assertEqual(len(pinputs), 2) # Contains all inputs
Esempio n. 50
0
    def test_var_cubes(self):
        fsm = self.model()
        enc = fsm.bddEnc

        p = evalSexp(fsm, "p")
        q = evalSexp(fsm, "q")
        a = evalSexp(fsm, "a")

        pq = fsm.pick_one_state(p & q)
        pnq = fsm.pick_one_state(p & ~q)

        pcube = enc.cube_for_state_vars({"p"})
        qcube = enc.cube_for_state_vars({"q"})
        false = BDD.false()

        self.assertEqual(pcube | qcube, pcube + qcube)
        self.assertTrue(pcube | qcube <= enc.statesCube)
        self.assertEqual(qcube & pcube, qcube * pcube)
        self.assertEqual(pcube - qcube, pcube)

        self.assertTrue(pcube & pq <= pcube)
        self.assertTrue(pcube | pq >= pcube)
        self.assertTrue(pcube - pq <= pcube)
Esempio n. 51
0
 def test_post_counters(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     self.assertIsNotNone(fsm)
     
     c1c0 = evalSexp(fsm, "c1.c = 0")
     c1c1 = evalSexp(fsm, "c1.c = 1")
     c2c0 = evalSexp(fsm, "c2.c = 0")
     c2c1 = evalSexp(fsm, "c2.c = 1")
     rc1 = evalSexp(fsm, "run = rc1")
     rc2 = evalSexp(fsm, "run = rc2")
     
     self.assertEqual(fsm.post(c1c0 & c2c0), (c1c1 & c2c0) | (c1c0 & c2c1))
Esempio n. 52
0
 def test_post_counters(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     self.assertIsNotNone(fsm)
     
     c1c0 = evalSexp(fsm, "c1.c = 0")
     c1c1 = evalSexp(fsm, "c1.c = 1")
     c2c0 = evalSexp(fsm, "c2.c = 0")
     c2c1 = evalSexp(fsm, "c2.c = 1")
     rc1 = evalSexp(fsm, "run = rc1")
     rc2 = evalSexp(fsm, "run = rc2")
     
     self.assertEqual(fsm.post(c1c0 & c2c0), (c1c1 & c2c0) | (c1c0 & c2c1))
Esempio n. 53
0
 def test_create_trans_counters_assign(self):    
     
     fsm = self.model("tests/pynusmv/models/counters-assign.smv")
     
     c1c0bdd = evalSexp(fsm, "c1.c = 0")
     c2c0bdd = evalSexp(fsm, "c2.c = 0")
     c1c1bdd = evalSexp(fsm, "c1.c = 1")
     c2c1bdd = evalSexp(fsm, "c2.c = 1")
     
     self.assertEqual(c1c0bdd & c2c0bdd, fsm.init)
     self.assertEqual(c1c0bdd & c2c1bdd | c1c1bdd & c2c0bdd,
                      fsm.post(fsm.init))
     
     fsmbuilder = nscompile.Compile_get_global_fsm_builder()
     enc = nsenc.Enc_get_bdd_encoding()
     ddmanager = nsbddenc.BddEnc_get_dd_manager(enc)
     base_enc = nsbddenc.bddenc2baseenc(enc)
     symb_table = nsbaseenc.BaseEnc_get_symb_table(base_enc)
     
     propDb = glob.prop_database()
     master = propDb.master
     
     sexpfsm_ptr = nsprop.Prop_get_scalar_sexp_fsm(master._ptr)
     
     
     # Create a new expr trans
     c2c = self.get_variable_from_string(sexpfsm_ptr, "c2.c")
     self.assertIsNotNone(c2c)
     # trans = next(c2c) = (c2.c + 1) % 4
     nextc2c = nssexp.Expr_next(c2c, symb_table)
     one = nsnode.create_node(parser.NUMBER, None, None)
     one.left.nodetype = nsnode.int2node(1)
     self.assertEqual(nsnode.sprint_node(one), "1")
     four = nsnode.create_node(parser.NUMBER, None, None)
     four.left.nodetype = nsnode.int2node(4)
     self.assertEqual(nsnode.sprint_node(four), "4")
     c2cp1 = nssexp.Expr_plus(c2c, one)
     c2cp1m4 = nssexp.Expr_mod(c2cp1, four)
     trans = nssexp.Expr_equal(nextc2c, c2cp1m4, symb_table)
     
     
     clusters = nsfsm.FsmBuilder_clusterize_expr(fsmbuilder, enc, trans)
     cluster_options = nsbddtrans.ClusterOptions_create(
                         nsopt.OptsHandler_get_instance())
                         
     bddTrans = BddTrans(
                 nsbddtrans.BddTrans_create(
                     ddmanager,
                     clusters,
                     nsbddenc.BddEnc_get_state_vars_cube(enc),
                     nsbddenc.BddEnc_get_input_vars_cube(enc),
                     nsbddenc.BddEnc_get_next_state_vars_cube(enc),
                     nsopt.get_partition_method(nsopt.OptsHandler_get_instance()),
                     cluster_options))
                     
     fsm.trans = bddTrans
     
     
     self.assertEqual(c1c0bdd & c2c0bdd, fsm.init)
     self.assertEqual(c2c1bdd, fsm.post(fsm.init))
     
Esempio n. 54
0
 def test_get_trans_counters_assign(self):    
     
     fsm = self.model("tests/pynusmv/models/counters-assign.smv")
     
     c1c0bdd = evalSexp(fsm, "c1.c = 0")
     c2c0bdd = evalSexp(fsm, "c2.c = 0")
     c1c1bdd = evalSexp(fsm, "c1.c = 1")
     c2c1bdd = evalSexp(fsm, "c2.c = 1")
     
     self.assertEqual(c1c0bdd & c2c0bdd, fsm.init)
     self.assertEqual(c1c0bdd & c2c1bdd | c1c1bdd & c2c0bdd,
                      fsm.post(fsm.init))
     
     fsmbuilder = nscompile.Compile_get_global_fsm_builder()
     enc = nsenc.Enc_get_bdd_encoding()
     ddmanager = nsbddenc.BddEnc_get_dd_manager(enc)
     
     propDb = glob.prop_database()
     master = propDb.master
     
     sexpfsm_ptr = nsprop.Prop_get_scalar_sexp_fsm(master._ptr)
     
     trans = self.trans_for_module(sexpfsm_ptr, "c2")
     
     
     # ANALYSE THE TRANS TO UNDERSTAND HOW TO CREATE NUMBERS
     #car = nsnode.car
     #cdr = nsnode.cdr
     #print("TRANS--------------------------------")
     #print(nsnode.sprint_node(cdr(trans)))
     #print("TRANS--------------------------------")
     # cdr(trans) = 
     #case
     #run = rc2 : case
     #c2.c + 1 >= stop : start;
     #c2.c + 1 < stop : c2.c + 1;
     #esac;
     #!(run = rc2) : c2.c;
     #esac
     
     # car(cdr(trans)) = 
     #run = rc2 : case
     #c2.c + 1 >= stop : start;
     #c2.c + 1 < stop : c2.c + 1;
     #esac;
     
     # cdr(car(cdr(trans))) = 
     #case
     #c2.c + 1 >= stop : start;
     #c2.c + 1 < stop : c2.c + 1;
     #esac
     
     # car(cdr(car(cdr(trans)))) = 
     #c2.c + 1 >= stop : start
     
     # car(car(cdr(car(cdr(trans))))) = 
     #c2.c + 1 >= stop
     
     # car(car(car(cdr(car(cdr(trans)))))) = 
     #c2.c + 1
     
     # car(car(car(car(cdr(car(cdr(trans))))))) = 
     #c2.c
     
     # car(car(car(car(car(cdr(car(cdr(trans)))))))) = 
     #c2
     
     # cdr(car(car(car(car(cdr(car(cdr(trans)))))))) = 
     #c
     
     # cdr(car(car(car(cdr(car(cdr(trans))))))) = 
     #1
     
     #print(cdr(cdr(car(car(car(car(cdr(car(cdr(trans))))))))))
     #print(nsnode.sprint_node(cdr(car(car(car(car(cdr(car(cdr(trans))))))))))
     
     
     
     
     clusters = nsfsm.FsmBuilder_clusterize_expr(fsmbuilder, enc, trans)
     cluster_options = nsbddtrans.ClusterOptions_create(
                         nsopt.OptsHandler_get_instance())
                         
     bddTrans = BddTrans(
                 nsbddtrans.BddTrans_create(
                     ddmanager,
                     clusters,
                     nsbddenc.BddEnc_get_state_vars_cube(enc),
                     nsbddenc.BddEnc_get_input_vars_cube(enc),
                     nsbddenc.BddEnc_get_next_state_vars_cube(enc),
                     nsopt.get_partition_method(nsopt.OptsHandler_get_instance()),
                     cluster_options))
                     
     fsm.trans = bddTrans
     
     
     self.assertEqual(c1c0bdd & c2c0bdd, fsm.init)
     self.assertEqual(c2c1bdd | c2c0bdd, fsm.post(fsm.init))
     
Esempio n. 55
0
 def test_deadlock_states_with_deadlock(self):
     fsm = self.deadlock_model()
     p = evalSexp(fsm, "p")
     q = evalSexp(fsm, "q")
     self.assertEqual(fsm.deadlock_states, ~p & q)