Exemplo n.º 1
0
 def test_init(self):
     init_nusmv()
     # Should not produce error
     fsm = BddFsm.from_filename("tests/pynusmv/models/admin.smv")
     reset_nusmv()
     # Should not produce error
     fsm = BddFsm.from_filename("tests/pynusmv/models/admin.smv")
     deinit_nusmv()
Exemplo n.º 2
0
 def test_init(self):
     init_nusmv()
     # Should not produce error
     fsm = BddFsm.from_filename("tests/pynusmv/models/admin.smv")
     reset_nusmv()
     # Should not produce error
     fsm = BddFsm.from_filename("tests/pynusmv/models/admin.smv")
     deinit_nusmv()
Exemplo n.º 3
0
 def test_from_string(self):
     model = """
     MODULE main
         VAR test : 0..1;
     """
     fsm = BddFsm.from_string(model)
     self.assertIsNotNone(fsm)
Exemplo n.º 4
0
 def simple_model(self):
     class main(smv.Module):
         c = smv.Var(smv.Range(0, 3))
         INIT = [c == 0]
         TRANS = [c.next() == (c + 1)]
     fsm = BddFsm.from_modules(main)
     return fsm
Exemplo n.º 5
0
 def print_vars_and_trans(self, modelpath):
     fsm = BddFsm.from_filename(modelpath)
     self.assertIsNotNone(fsm)
     
     propDb = glob.prop_database()
     master = propDb.master
     
     print("MODEL:", modelpath)
     print("============================================================")
     
     sexpfsm_ptr = nsprop.Prop_get_scalar_sexp_fsm(master._ptr)
     var_list = nssexp.SexpFsm_get_vars_list(sexpfsm_ptr)
     
     var_list_length = nsutils.NodeList_get_length(var_list)
     print("var_list length:", var_list_length)
     
     var_list_iter = nsutils.NodeList_get_first_iter(var_list)
     while var_list_iter is not None:
         item = nsutils.NodeList_get_elem_at(var_list, var_list_iter)
         
         print(nsnode.sprint_node(item))
         print("--------------------------")
         
         var_init = nssexp.SexpFsm_get_var_init(sexpfsm_ptr, item)
         print(nsnode.sprint_node(var_init))
                     
         print("--------------------------")
         
         var_trans = nssexp.SexpFsm_get_var_trans(sexpfsm_ptr, item)
         print(nsnode.sprint_node(var_trans))
         
         print("--------------------------")
         print()
         
         var_list_iter = nsutils.ListIter_get_next(var_list_iter)
Exemplo n.º 6
0
 def test_from_string_fail(self):
     model = """
     MODULE main
         VAR qsdf : sdfqsdf;
     """
     with self.assertRaises(NuSMVCannotFlattenError):
         fsm = BddFsm.from_string(model)
Exemplo n.º 7
0
 def test_from_string_fail(self):
     model = """
     MODULE main
         VAR qsdf : sdfqsdf;
     """
     with self.assertRaises(NuSMVCannotFlattenError):
         fsm = BddFsm.from_string(model)
Exemplo n.º 8
0
 def test_from_string(self):
     model = """
     MODULE main
         VAR test : 0..1;
     """
     fsm = BddFsm.from_string(model)
     self.assertIsNotNone(fsm)
Exemplo n.º 9
0
    def print_vars_and_trans(self, modelpath):
        fsm = BddFsm.from_filename(modelpath)
        self.assertIsNotNone(fsm)

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

        print("MODEL:", modelpath)
        print("============================================================")

        sexpfsm_ptr = nsprop.Prop_get_scalar_sexp_fsm(master._ptr)
        var_list = nssexp.SexpFsm_get_vars_list(sexpfsm_ptr)

        var_list_length = nsutils.NodeList_get_length(var_list)
        print("var_list length:", var_list_length)

        var_list_iter = nsutils.NodeList_get_first_iter(var_list)
        while var_list_iter is not None:
            item = nsutils.NodeList_get_elem_at(var_list, var_list_iter)

            print(nsnode.sprint_node(item))
            print("--------------------------")

            var_init = nssexp.SexpFsm_get_var_init(sexpfsm_ptr, item)
            print(nsnode.sprint_node(var_init))

            print("--------------------------")

            var_trans = nssexp.SexpFsm_get_var_trans(sexpfsm_ptr, item)
            print(nsnode.sprint_node(var_trans))

            print("--------------------------")
            print()

            var_list_iter = nsutils.ListIter_get_next(var_list_iter)
Exemplo n.º 10
0
    def test_symb_table_new_layer(self):
        fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
        symb_table = fsm.bddEnc.symbTable

        self.assertIsNotNone(symb_table)
        self.assertTrue("translation" not in symb_table.layer_names)

        symb_table.create_layer("translation")
        self.assertTrue("translation" in symb_table.layer_names)
Exemplo n.º 11
0
 def test_symb_table_new_layer(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     symb_table = fsm.bddEnc.symbTable
     
     self.assertIsNotNone(symb_table)
     self.assertTrue("translation" not in symb_table.layer_names)
     
     symb_table.create_layer("translation")
     self.assertTrue("translation" in symb_table.layer_names)
Exemplo n.º 12
0
 def test_is_frozen_var(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     symb_table = fsm.bddEnc.symbTable
     
     var = node.Identifier.from_string("c1.c")
     self.assertFalse(symb_table.is_frozen_var(var))
     
     var = node.Identifier.from_string("blocked")
     with self.assertRaises(NuSMVSymbTableError):
             symb_table.is_frozen_var(var)
Exemplo n.º 13
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))
Exemplo n.º 14
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))
Exemplo n.º 15
0
 def test_symb_table_layer_names(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     symb_table = fsm.bddEnc.symbTable
     
     self.assertIsNotNone(symb_table)
     self.assertIsNotNone(symb_table._ptr)
     
     self.assertEqual(len(symb_table.layer_names), 2)
     self.assertIn("model", symb_table.layer_names)
     self.assertIn("model_bool", symb_table.layer_names)
Exemplo n.º 16
0
    def test_symb_table_layer_names(self):
        fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
        symb_table = fsm.bddEnc.symbTable

        self.assertIsNotNone(symb_table)
        self.assertIsNotNone(symb_table._ptr)

        self.assertEqual(len(symb_table.layer_names), 2)
        self.assertIn("model", symb_table.layer_names)
        self.assertIn("model_bool", symb_table.layer_names)
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo n.º 19
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))
Exemplo n.º 20
0
    def test_symb_table_declare_variable(self):
        fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
        symb_table = fsm.bddEnc.symbTable

        self.assertIsNotNone(symb_table)

        var = node.Identifier.from_string("ran")
        type_ = node.Scalar(("rc1", "rc2"))

        self.assertTrue(symb_table.can_declare_var("model", var))
        symb_table.declare_state_var("model", var, type_)
        self.assertFalse(symb_table.can_declare_var("model", var))
Exemplo n.º 21
0
 def test_symb_table_declare_variable(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     symb_table = fsm.bddEnc.symbTable
     
     self.assertIsNotNone(symb_table)
     
     var = node.Identifier.from_string("ran")
     type_ = node.Scalar(("rc1", "rc2"))
     
     self.assertTrue(symb_table.can_declare_var("model", var))
     symb_table.declare_state_var("model", var, type_)
     self.assertFalse(symb_table.can_declare_var("model", var))
Exemplo n.º 22
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))
Exemplo n.º 23
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)
Exemplo n.º 24
0
    def test_gc(self):
        """
        This test should not produce a segfault due to freed memory after
        deiniting NuSMV. This is thanks to the PyNuSMV GC system that keeps
        track of all wrapped pointers and free them when deiniting NuSMV, if
        needed.
        """
        init_nusmv()

        fsm = BddFsm.from_filename("tests/pynusmv/models/admin.smv")
        init = fsm.init

        deinit_nusmv()
Exemplo n.º 25
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)
Exemplo n.º 26
0
 def test_fairness_from_nusmv(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters-fair.smv")
     self.assertIsNotNone(fsm)
     
     from pynusmv_lower_interface.nusmv.fsm.bdd import bdd as nsbddfsm
     
     justiceList = nsbddfsm.BddFsm_get_justice(fsm._ptr)
     fairnessList = nsbddfsm.justiceList2fairnessList(justiceList)
     
     ite = nsbddfsm.FairnessList_begin(fairnessList)
     fairBdds = []
     while not nsbddfsm.FairnessListIterator_is_end(ite):
         fairBdds.append(nsbddfsm.JusticeList_get_p(justiceList, ite))
         ite = nsbddfsm.FairnessListIterator_next(ite)
     self.assertEqual(len(fairBdds), 2)
Exemplo n.º 27
0
 def do_read(self, arg):
     """
     Read file as SMV model to get FSM.
     usage: read FILEPATH
     """
     if len(arg) < 1:
         print("[ERROR] read command needs the SMV model path.")
     else:
         if self.fsm is not None:
             reset_nusmv()
         try:
             self.fsm = BddFsm.from_filename(arg)
             self.fsmpath = arg
         except Exception as e:
             print("[ERROR]", e)
Exemplo n.º 28
0
 def test_fairness_from_nusmv(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters-fair.smv")
     self.assertIsNotNone(fsm)
     
     from pynusmv.nusmv.fsm.bdd import bdd as nsbddfsm
     
     justiceList = nsbddfsm.BddFsm_get_justice(fsm._ptr)
     fairnessList = nsbddfsm.justiceList2fairnessList(justiceList)
     
     ite = nsbddfsm.FairnessList_begin(fairnessList)
     fairBdds = []
     while not nsbddfsm.FairnessListIterator_is_end(ite):
         fairBdds.append(nsbddfsm.JusticeList_get_p(justiceList, ite))
         ite = nsbddfsm.FairnessListIterator_next(ite)
     self.assertEqual(len(fairBdds), 2)
Exemplo n.º 29
0
 def do_read(self, arg):
     """
     Read file as SMV model to get FSM.
     usage: read FILEPATH
     """
     if len(arg) < 1:
         print("[ERROR] read command needs the SMV model path.")
     else:
         if self.fsm is not None:
             reset_nusmv()
         try:
             self.fsm = BddFsm.from_filename(arg)
             self.fsmpath = arg
         except Exception as e:
             print("[ERROR]", e)
Exemplo n.º 30
0
 def test_symb_table_declare_inputs_variable(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     symb_table = fsm.bddEnc.symbTable
     
     self.assertIsNotNone(symb_table)
     
     var = node.Identifier.from_string("block")
     type_ = node.Boolean()
     
     self.assertTrue(symb_table.can_declare_var("model", var))
     symb_table.declare_input_var("model", var, type_)
     with self.assertRaises(NuSMVSymbTableError):
         symb_table.declare_input_var("model", var, type_)
     with self.assertRaises(NuSMVSymbTableError):
         symb_table.declare_var("model", var, type_,
                                symb_table.SYMBOL_INPUT_VAR)
Exemplo n.º 31
0
    def test_build_model(self):
        # Initialize the model
        ret = cmd.Cmd_SecureCommandExecute("read_model -i"
                                           " tests/pynusmv/models/admin.smv")
        self.assertEqual(ret, 0)
        ret = cmd.Cmd_SecureCommandExecute("go")
        self.assertEqual(ret, 0)

        propDb = prop.PropPkg_get_prop_database()
        fsm_ptr = prop.PropDb_master_get_bdd_fsm(propDb)
        self.assertIsNotNone(fsm_ptr)
        fsm = BddFsm(fsm_ptr)
        enc = fsm.bddEnc
        self.assertIsNotNone(enc)
        init = fsm.init
        self.assertIsNotNone(init)
Exemplo n.º 32
0
 def test_declare_types(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     symb_table = fsm.bddEnc.symbTable
     
     variables = {"v1": node.Boolean(),
                  "v2": node.UnsignedWord(node.Number(2)),
                  "v3": node.SignedWord(node.Number(3)),
                  "v4": node.Range(node.Number(0), node.Number(3)),
                  "v5": node.Scalar(("a", "b"))}
     for var, type_ in variables.items():
         var = node.Identifier.from_string(var)
         symb_table.declare_state_var("model", var, type_)
         # Should not raise any exception
     
     with self.assertRaises(NuSMVSymbTableError):
         var = node.Identifier.from_string("s")
         type_ = node.Identifier.from_string("test")
         symb_table.declare_state_var("model", var, type_)
Exemplo n.º 33
0
def check(modelPath, evalSpecs=True):
    init_nusmv()
    # Initialize the model
    fsm = BddFsm.from_filename(modelPath)
    propDb = glob.prop_database()

    # Check all CTL properties
    if evalSpecs:
        for prop in propDb:
            #  Check type
            if prop.type == propTypes['CTL']:
                spec = prop.exprcore

                # Get violating states
                violating = (fsm.init & ~eval_ctl(fsm, spec)
                             & fsm.state_constraints)
                print('Specification', str(spec), 'is',
                      str(violating.is_false()))
                # We could generate counter-examples here
    deinit_nusmv()
Exemplo n.º 34
0
def check_and_explain(allargs):
    """
    Check specs on the given NuSMV model and compute TLACEs when needed.
    
    Build the model from a given file, check every CTL spec in it
    and compute and store TLACEs when needed.
    
    allargs -- a sys.args-like arguments list, without script name.
    """

    # Parse arguments
    parser = argparse.ArgumentParser(description='CTL model checker '
                                     'with TLACE generation.')
    # Populate arguments: for now, only the model
    parser.add_argument('model', help='the NuSMV model with specifications')
    args = parser.parse_args(allargs)

    # Initialize the model
    fsm = BddFsm.from_filename(args.model)
    propDb = glob.prop_database()

    # Check all CTL properties
    for prop in propDb:
        #  Check type
        if prop.type == propTypes['CTL']:
            spec = prop.exprcore

            (satisfied, cntex) = check_ctl_spec(fsm, spec)
            # Print the result and the TLACE if any
            print('Specification',
                  str(spec),
                  'is',
                  str(satisfied),
                  file=sys.stderr)

            if not satisfied:
                print(xml_representation(fsm, cntex, spec))

            print()
Exemplo n.º 35
0
def check_and_explain(allargs):
    """
    Check specs on the given NuSMV model and compute TLACEs when needed.
    
    Build the model from a given file, check every CTL spec in it
    and compute and store TLACEs when needed.
    
    allargs -- a sys.args-like arguments list, without script name.
    """
    
    # Parse arguments
    parser = argparse.ArgumentParser(description='CTL model checker '
                                                 'with TLACE generation.')
    # Populate arguments: for now, only the model
    parser.add_argument('model', help='the NuSMV model with specifications')
    args = parser.parse_args(allargs)
    
    # Initialize the model
    fsm = BddFsm.from_filename(args.model)
    propDb = glob.prop_database()
    
    # Check all CTL properties
    for prop in propDb:
        #  Check type
        if prop.type == propTypes['CTL']:
            spec = prop.exprcore
    
            (satisfied, cntex) = check_ctl_spec(fsm, spec)
            # Print the result and the TLACE if any
            print('Specification',str(spec), 'is', str(satisfied),
                  file=sys.stderr)
        
            if not satisfied:
                print(xml_representation(fsm, cntex, spec))
            
            print()
Exemplo n.º 36
0
 def init_model(self):
     fsm = BddFsm.from_filename("tests/tools/arctl/counters.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 37
0
 def init_model(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/admin.smv")
     return (fsm, fsm.bddEnc, fsm.bddEnc.DDmanager)
Exemplo n.º 38
0
 def deadlock_model(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/deadlock.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 39
0
 def test_no_fairness(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     self.assertIsNotNone(fsm)
     
     self.assertEqual(len(fsm.fairness_constraints), 0)
Exemplo n.º 40
0
 def init_model(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/admin.smv")
     return (fsm, fsm.bddEnc, fsm.bddEnc.DDmanager)
Exemplo n.º 41
0
 def cardgame_post_fair(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/"
                                "cardgame-post-fair.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 42
0
 def nameche_model(self):
     fsm = BddFsm.from_filename("tests/tools/ctl/nameche08R1.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 43
0
 def model(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 44
0
 def init_model(self):
     fsm = BddFsm.from_filename('examples/short.smv')
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 45
0
 def counters_model(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 46
0
 def deadlock_model(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/deadlock.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 47
0
 def init_model(self):
     fsm = BddFsm.from_filename('examples/admin.smv')
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 48
0
 def model(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/constraints.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 49
0
 def test_no_fairness(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/counters.smv")
     self.assertIsNotNone(fsm)
     
     self.assertEqual(len(fsm.fairness_constraints), 0)
Exemplo n.º 50
0
 def cardgame_post_fair(self):
     fsm = BddFsm.from_filename("tests/pynusmv/models/"
                                "cardgame-post-fair.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 51
0
 def init_model(self):
     fsm = BddFsm.from_filename("tests/tools/ctl/admin.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 52
0
 def model(self, modelpath):
     fsm = BddFsm.from_filename(modelpath)
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 53
0
 def init_finite_model(self):
     fsm = BddFsm.from_filename("tests/tools/arctl/finite_counters.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 54
0
 def init_finite_model(self):
     fsm = BddFsm.from_filename(
         "tests/pynusmv_tools/arctl/finite_model.smv")
     self.assertIsNotNone(fsm)
     return fsm
Exemplo n.º 55
0
 def model(self, modelpath):
     fsm = BddFsm.from_filename(modelpath)
     self.assertIsNotNone(fsm)
     return fsm