Ejemplo n.º 1
0
 def test_explain(self):
     fsm = self.init_model()
     
     initState = fsm.pick_one_state(fsm.init)
     adminNone = eval_ctl_spec(fsm, atom("admin = none"))
     adminAlice = eval_ctl_spec(fsm, atom("admin = alice"))
     egAlice = eval_ctl_spec(fsm, eg(atom("admin = alice")))
     euNoneUAlice = eval_ctl_spec(fsm, eu(atom("admin = none"),
                                          atom("admin = alice")))
     
     spec = Spec(parse_ctl_spec("EX admin = none"))
     path = explain(fsm, initState, spec)
     self.assertEqual(initState, path[0])
     self.assertTrue(path[2] <= adminNone)
     
     state = fsm.pick_one_state(egAlice)
     spec = Spec(parse_ctl_spec("EG admin = alice"))
     path = explain(fsm, state, spec)
     self.assertEqual(state, path[0])
     self.assertIn(path[-1], path[:-1])
     for i in range(0,len(path), 2):
         self.assertTrue(path[i] <= adminAlice)
     self.assertTrue(path[-1] <= adminAlice)
     self.assertTrue(initState <= euNoneUAlice)
     
     spec = Spec(parse_ctl_spec("E[admin = none U admin = alice]"))
     path = explain(fsm, initState, spec)
     self.assertEqual(initState, path[0])
     for i in range(2,len(path)-2,2):
         self.assertTrue(path[i] <= adminNone)
     self.assertTrue(path[-1] <= adminAlice)
Ejemplo n.º 2
0
 def test_explain_ex(self):
     fsm = self.init_model()
     manager = fsm.bddEnc.DDmanager
     init = fsm.init
     
     initState = fsm.pick_one_state(init)
     
     adminNone = eval_ctl_spec(fsm, atom("admin = none"))
     exAdminNone = eval_ctl_spec(fsm, ex(atom("admin = none")))
     self.assertTrue(initState <= exAdminNone)
     
     path = explainEX(fsm, initState, adminNone)
     self.assertEqual(initState, path[0])
     self.assertTrue(path[2] <= adminNone)
Ejemplo n.º 3
0
 def test_namecheR1(self):
     # activate bdd dynamic reordering
     nsopt.set_dynamic_reorder(nsopt.OptsHandler_get_instance())
     
     fsm = self.nameche_model()
     
     # AG (T_04BM.st = o & TRP_CM.krc = s -> AX (!R1.L_CS))
     to = prop.atom("T_04BM.st = o")
     trps = prop.atom("TRP_CM.krc = s")
     nr1lcs = prop.atom("!R1.L_CS")
     p = prop.imply(to & trps, prop.ax(nr1lcs))
     self.assertTrue(fsm.reachable_states <= eval_ctl(fsm, p))
     
     # AG (EF R1.L_CS)
     r1lcs = prop.atom("R1.L_CS")
     p = prop.ef(r1lcs)
     self.assertTrue(fsm.reachable_states <= eval_ctl(fsm, p))
Ejemplo n.º 4
0
    def test_explain_eg_first_state(self):
        fsm = self.inputs_model()
        manager = fsm.bddEnc.DDmanager
        init = fsm.init

        p = eval_ctl_spec(fsm, atom("p"))
        egp = eval_ctl_spec(fsm, eg(atom("p")))
        self.assertTrue(egp <= p)

        state = fsm.pick_one_state(egp)
        path, (inloop, loop) = explainEG(fsm, state, p)
        self.assertEqual(state, path[0])
        self.assertIn(loop, path)
        self.assertEqual(len(path), 1)
        for i in range(0, len(path), 2):
            self.assertTrue(path[i] <= p)
        self.assertTrue(path[-1] <= p)
Ejemplo n.º 5
0
    def test_namecheR1(self):
        # activate bdd dynamic reordering
        nsopt.set_dynamic_reorder(nsopt.OptsHandler_get_instance())

        fsm = self.nameche_model()

        # AG (T_04BM.st = o & TRP_CM.krc = s -> AX (!R1.L_CS))
        to = prop.atom("T_04BM.st = o")
        trps = prop.atom("TRP_CM.krc = s")
        nr1lcs = prop.atom("!R1.L_CS")
        p = prop.imply(to & trps, prop.ax(nr1lcs))
        self.assertTrue(fsm.reachable_states <= eval_ctl(fsm, p))

        # AG (EF R1.L_CS)
        r1lcs = prop.atom("R1.L_CS")
        p = prop.ef(r1lcs)
        self.assertTrue(fsm.reachable_states <= eval_ctl(fsm, p))
Ejemplo n.º 6
0
 def test_explain_eu(self):
     fsm = self.init_model()
     manager = fsm.bddEnc.DDmanager
     init = fsm.init
     
     initState = fsm.pick_one_state(init)
     
     adminNone = eval_ctl_spec(fsm, atom("admin = none"))
     adminAlice = eval_ctl_spec(fsm, atom("admin = alice"))
     euNoneUAlice = eval_ctl_spec(fsm, eu(atom("admin = none"),
                                          atom("admin = alice")))
     self.assertTrue(initState <= euNoneUAlice)
     
     path = explainEU(fsm, initState, adminNone, adminAlice)
     self.assertEqual(initState, path[0])
     for i in range(2,len(path)-2,2):
         self.assertTrue(path[i] <= adminNone)
     self.assertTrue(path[-1] <= adminAlice)
Ejemplo n.º 7
0
 def test_eval_atom(self):
     fsm = self.init_model()
     manager = fsm.bddEnc.DDmanager
     init = fsm.init
     
     initState = fsm.pick_one_state(init)
     
     adminNone = eval_ctl_spec(fsm, atom("admin = none"))
     self.assertTrue((initState & adminNone).isnot_false())
     self.assertTrue(init <= adminNone)
Ejemplo n.º 8
0
 def test_explain_eg(self):
     fsm = self.init_model()
     manager = fsm.bddEnc.DDmanager
     init = fsm.init
     
     adminAlice = eval_ctl_spec(fsm, atom("admin = alice"))
     egAlice = eval_ctl_spec(fsm, eg(atom("admin = alice")))
     self.assertTrue(egAlice <= adminAlice)
     
     state = fsm.pick_one_state(egAlice)
     self.assertTrue(BDD.false(manager) < state <= adminAlice)
     self.assertTrue(state <= egAlice)
     
     path, (inloop, loop) = explainEG(fsm, state, adminAlice)
     self.assertEqual(state, path[0])
     self.assertIn(loop, path)
     for i in range(0,len(path), 2):
         self.assertTrue(path[i] <= adminAlice)
     self.assertTrue(path[-1] <= adminAlice)
Ejemplo n.º 9
0
    def test_car_cdr(self):
        spec = au(atom("s", type_checking=False), atom("t",
                                                       type_checking=False))
        self.assertEqual(spec.car, spec.car)
        self.assertNotEqual(spec.car, spec.cdr)

        parsed_spec = parse_ctl_spec("A [s U s]")
        spec = Spec(parsed_spec)
        self.assertNotEqual(spec.car, spec.cdr)
        self.assertEqual(spec.car, spec.car)

        newspec = au(spec.car, spec.cdr)
        self.assertEqual(spec.car, newspec.car)
        self.assertEqual(spec.cdr, newspec.cdr)
        self.assertNotEqual(spec, newspec)

        newspec2 = au(spec.car, spec.cdr)
        self.assertEqual(newspec, newspec2)

        s = {spec.car, spec.car, spec.cdr}
        self.assertEqual(len(s), 2)
Ejemplo n.º 10
0
 def test_car_cdr(self):
     spec = au(atom("s", type_checking=False),
               atom("t", type_checking=False))
     self.assertEqual(spec.car, spec.car)
     self.assertNotEqual(spec.car, spec.cdr)
     
     parsed_spec = parse_ctl_spec("A [s U s]")
     spec = Spec(parsed_spec)
     self.assertNotEqual(spec.car, spec.cdr)
     self.assertEqual(spec.car, spec.car)
     
     newspec = au(spec.car, spec.cdr)
     self.assertEqual(spec.car, newspec.car)
     self.assertEqual(spec.cdr, newspec.cdr)
     self.assertNotEqual(spec, newspec)
     
     newspec2 = au(spec.car, spec.cdr)
     self.assertEqual(newspec, newspec2)
     
     s = {spec.car, spec.car, spec.cdr}
     self.assertEqual(len(s), 2)
Ejemplo n.º 11
0
 def test_wrong_type(self):
     fsm, _, _ = self.init_model()
     spec = atom("admin = starting")
     specbdd = eval_ctl_spec(fsm, spec)
     self.assertTrue(specbdd.is_false())
Ejemplo n.º 12
0
 def test_unknown(self):    
     fsm, _, _ = self.init_model()
     with self.assertRaises(NuSMVTypeCheckingError):
         spec = atom("admin = folded")
Ejemplo n.º 13
0
def ast_to_spec(ast):
    """
    Return a PyNuSMV specification representing `ast`.

    :param ast: an AST-based CTL formula
    :return: a PyNuSMV specification representing `ast`
    :rtype: :class:`pynusmv.prop.Spec`

    :raise: a :exc:`NotImplementedError` if an operator is not implemented
    """
    if isinstance(ast, TrueExp):
        return true()

    elif isinstance(ast, FalseExp):
        return false()

    elif isinstance(ast, Atom):
        return atom(ast.value)

    elif isinstance(ast, Not):
        return not_(ast_to_spec(ast.child))

    elif isinstance(ast, And):
        return and_(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Or):
        return or_(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Imply):
        return imply(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Iff):
        return iff(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, AX):
        return ax(ast_to_spec(ast.child))

    elif isinstance(ast, AF):
        return af(ast_to_spec(ast.child))

    elif isinstance(ast, AG):
        return ag(ast_to_spec(ast.child))

    elif isinstance(ast, AU):
        return au(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, AW):
        return aw(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, EX):
        return ex(ast_to_spec(ast.child))

    elif isinstance(ast, EF):
        return ef(ast_to_spec(ast.child))

    elif isinstance(ast, EG):
        return eg(ast_to_spec(ast.child))

    elif isinstance(ast, EU):
        return eu(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, EW):
        return ew(ast_to_spec(ast.left), ast_to_spec(ast.right))

    # A(phi oU psi) <=> A(phi U (phi & psi))
    elif isinstance(ast, AoU):
        return au(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # A(phi oW psi) <=> A(phi W (phi & psi))
    elif isinstance(ast, AoW):
        return aw(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # A(phi dU psi) <=> A(phi U (!phi & psi))
    elif isinstance(ast, AdU):
        return au(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # A(phi dW psi) <=> A(phi W (!phi & psi))
    elif isinstance(ast, AdW):
        return aw(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # E(phi oU psi) <=> E(phi U (phi & psi))
    elif isinstance(ast, EoU):
        return eu(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # E(phi oW psi) <=> E(phi W (phi & psi))
    elif isinstance(ast, EoW):
        return ew(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # E(phi dU psi) <=> E(phi U (!phi & psi))
    elif isinstance(ast, EdU):
        return eu(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # E(phi dW psi) <=> E(phi W (!phi & psi))
    elif isinstance(ast, EdW):
        return ew(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    else:
        raise NotImplementedError(NOT_IMPLEMENTED_MSG.format(op=type(ast)))
Ejemplo n.º 14
0
 def test_unknown(self):
     fsm, _, _ = self.init_model()
     with self.assertRaises(NuSMVTypeCheckingError):
         spec = atom("admin = folded")
Ejemplo n.º 15
0
 def test_success_or(self):    
     fsm, _, _ = self.init_model()
     spec = atom("admin = alice | admin = bob")
     specbdd = eval_ctl_spec(fsm, spec)
     self.assertTrue((specbdd & fsm.init).is_false())
Ejemplo n.º 16
0
 def test_success_or(self):
     fsm, _, _ = self.init_model()
     spec = atom("admin = alice | admin = bob")
     specbdd = eval_ctl_spec(fsm, spec)
     self.assertTrue((specbdd & fsm.init).is_false())
Ejemplo n.º 17
0
    def test_ctl(self):
        fsm = self.init_model()
        # EF admin = alice is True
        efaa = prop.ef(prop.atom("admin = alice"))
        self.assertTrue(fsm.init <= eval_ctl(fsm, efaa))

        # EG admin != alice is True
        egana = prop.eg(prop.atom("admin != alice"))
        self.assertTrue(fsm.init <= eval_ctl(fsm, egana))

        # AF admin != none is True
        afann = prop.af(prop.atom("admin != none"))
        self.assertTrue(fsm.init <= eval_ctl(fsm, afann))

        # AG admin in {alice, bob, none} is True
        aga = prop.ag(prop.atom("admin in {alice, bob, none}"))
        self.assertTrue(fsm.init <= eval_ctl(fsm, aga))

        # AG (admin != none -> AG admin != none) is True
        aganniann = prop.ag(
            prop.imply(prop.atom("admin != none"),
                       prop.ag(prop.atom("admin != none"))))
        self.assertTrue(fsm.init <= eval_ctl(fsm, aganniann))

        # AG (admin = alice -> AX admin = alice) is True
        agaaiaxaa = prop.ag(
            prop.imply(prop.atom("admin = alice"),
                       prop.ax(prop.atom("admin = alice"))))
        self.assertTrue(fsm.init <= eval_ctl(fsm, agaaiaxaa))

        # AX admin = alice is False
        axaa = prop.ax(prop.atom("admin = alice"))
        self.assertFalse(fsm.init <= eval_ctl(fsm, axaa))

        # EX admin != none is False
        exann = prop.ex(prop.atom("admin != none"))
        self.assertFalse(fsm.init <= eval_ctl(fsm, exann))

        # AG admin = none is False
        agan = prop.ag(prop.atom("admin = none"))
        self.assertFalse(fsm.init <= eval_ctl(fsm, agan))

        # EG admin = none is False
        egan = prop.eg(prop.atom("admin = none"))
        self.assertFalse(fsm.init <= eval_ctl(fsm, egan))
Ejemplo n.º 18
0
def ast_to_spec(ast):
    """
    Return a PyNuSMV specification representing `ast`.

    :param ast: an AST-based CTL formula
    :return: a PyNuSMV specification representing `ast`
    :rtype: :class:`pynusmv.prop.Spec`

    :raise: a :exc:`NotImplementedError` if an operator is not implemented
    """
    if isinstance(ast, TrueExp):
        return true()

    elif isinstance(ast, FalseExp):
        return false()

    elif isinstance(ast, Atom):
        return atom(ast.value)

    elif isinstance(ast, Not):
        return not_(ast_to_spec(ast.child))

    elif isinstance(ast, And):
        return and_(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Or):
        return or_(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Imply):
        return imply(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, Iff):
        return iff(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, AX):
        return ax(ast_to_spec(ast.child))

    elif isinstance(ast, AF):
        return af(ast_to_spec(ast.child))

    elif isinstance(ast, AG):
        return ag(ast_to_spec(ast.child))

    elif isinstance(ast, AU):
        return au(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, AW):
        return aw(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, EX):
        return ex(ast_to_spec(ast.child))

    elif isinstance(ast, EF):
        return ef(ast_to_spec(ast.child))

    elif isinstance(ast, EG):
        return eg(ast_to_spec(ast.child))

    elif isinstance(ast, EU):
        return eu(ast_to_spec(ast.left), ast_to_spec(ast.right))

    elif isinstance(ast, EW):
        return ew(ast_to_spec(ast.left), ast_to_spec(ast.right))

    # A(phi oU psi) <=> A(phi U (phi & psi))
    elif isinstance(ast, AoU):
        return au(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # A(phi oW psi) <=> A(phi W (phi & psi))
    elif isinstance(ast, AoW):
        return aw(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # A(phi dU psi) <=> A(phi U (!phi & psi))
    elif isinstance(ast, AdU):
        return au(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # A(phi dW psi) <=> A(phi W (!phi & psi))
    elif isinstance(ast, AdW):
        return aw(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # E(phi oU psi) <=> E(phi U (phi & psi))
    elif isinstance(ast, EoU):
        return eu(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # E(phi oW psi) <=> E(phi W (phi & psi))
    elif isinstance(ast, EoW):
        return ew(ast_to_spec(ast.left),
                  and_(ast_to_spec(ast.left), ast_to_spec(ast.right)))

    # E(phi dU psi) <=> E(phi U (!phi & psi))
    elif isinstance(ast, EdU):
        return eu(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    # E(phi dW psi) <=> E(phi W (!phi & psi))
    elif isinstance(ast, EdW):
        return ew(ast_to_spec(ast.left),
                  and_(not_(ast_to_spec(ast.left)), ast_to_spec(ast.right)))

    else:
        raise NotImplementedError(NOT_IMPLEMENTED_MSG.format(op=type(ast)))
Ejemplo n.º 19
0
 def test_ctl(self):
     fsm = self.init_model()
     # EF admin = alice is True
     efaa = prop.ef(prop.atom("admin = alice"))
     self.assertTrue(fsm.init <= eval_ctl(fsm, efaa))
     
     # EG admin != alice is True
     egana = prop.eg(prop.atom("admin != alice"))
     self.assertTrue(fsm.init <= eval_ctl(fsm, egana))
     
     # AF admin != none is True
     afann = prop.af(prop.atom("admin != none"))
     self.assertTrue(fsm.init <= eval_ctl(fsm, afann))
     
     # AG admin in {alice, bob, none} is True
     aga = prop.ag(prop.atom("admin in {alice, bob, none}"))
     self.assertTrue(fsm.init <= eval_ctl(fsm, aga))
     
     # AG (admin != none -> AG admin != none) is True
     aganniann = prop.ag(prop.imply(prop.atom("admin != none"),
                                    prop.ag(prop.atom("admin != none"))))
     self.assertTrue(fsm.init <= eval_ctl(fsm, aganniann))
     
     # AG (admin = alice -> AX admin = alice) is True
     agaaiaxaa = prop.ag(prop.imply(prop.atom("admin = alice"),
                                    prop.ax(prop.atom("admin = alice"))))
     self.assertTrue(fsm.init <= eval_ctl(fsm, agaaiaxaa))
     
     
     # AX admin = alice is False
     axaa = prop.ax(prop.atom("admin = alice"))
     self.assertFalse(fsm.init <= eval_ctl(fsm, axaa))
     
     # EX admin != none is False
     exann = prop.ex(prop.atom("admin != none"))
     self.assertFalse(fsm.init <= eval_ctl(fsm, exann))
     
     # AG admin = none is False
     agan = prop.ag(prop.atom("admin = none"))
     self.assertFalse(fsm.init <= eval_ctl(fsm, agan))
     
     # EG admin = none is False
     egan = prop.eg(prop.atom("admin = none"))
     self.assertFalse(fsm.init <= eval_ctl(fsm, egan))
Ejemplo n.º 20
0
 def test_bool(self):
     fsm, _, _ = self.init_model()
     with self.assertRaises(NuSMVTypeCheckingError):
         spec = atom("admin")
Ejemplo n.º 21
0
 def test_wrong_type(self):
     fsm, _, _ = self.init_model()
     spec = atom("admin = starting")
     specbdd = eval_ctl_spec(fsm, spec)
     self.assertTrue(specbdd.is_false())
Ejemplo n.º 22
0
 def test_bool(self):
     fsm, _, _ = self.init_model()
     with self.assertRaises(NuSMVTypeCheckingError):
         spec = atom("admin")