示例#1
0
 def setUp(self):
     init_nusmv()
     load_from_file(
         tests.current_directory(__file__) + "/models/flipflops.smv")
     go_bmc()
     self.enc = BeEnc.global_singleton_instance()
     self.mgr = self.enc.manager
示例#2
0
 def setUp(self):
     init_nusmv()
     load_from_file(tests.current_directory(__file__)+"/models/flipflops_trans_invar_fairness.smv")
     go_bmc()
     
     self.fsm = BeFsm.global_master_instance()
     self.enc = self.fsm.encoding
示例#3
0
 def setUp(self):
     init_nusmv()
     load_from_file(tests.current_directory(__file__)+"/models/flipflops_vif.smv")
     go_bmc()
     self.enc = master_be_fsm().encoding
     self.v   = self.enc.by_name['v']
     self.f   = self.enc.by_name['f']
     self.i   = self.enc.by_name['i']
     self.n   = self.enc.by_name['next(v)']
示例#4
0
文件: utils.py 项目: xgillard/pynusmv
 def __enter__(self):
     """Performs what one would usually do in setUp"""
     init_nusmv()
     load_from_file(self.model)
     go_bmc()
     self.testcase.sexpfsm = master_bool_sexp_fsm()
     self.testcase.befsm   = master_be_fsm()
     self.testcase.enc     = self.testcase.befsm.encoding
     self.testcase.mgr     = self.testcase.enc.manager
示例#5
0
 def test_no_model(self):
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
     glob.flatten_hierarchy()
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
示例#6
0
 def test_no_model(self):
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
     glob.flatten_hierarchy()
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
示例#7
0
 def __enter__(self):
     """Performs what one would usually do in setUp"""
     init_nusmv()
     load_from_file(self.model)
     go_bmc()
     self.testcase.sexpfsm = master_bool_sexp_fsm()
     self.testcase.befsm = master_be_fsm()
     self.testcase.enc = self.testcase.befsm.encoding
     self.testcase.mgr = self.testcase.enc.manager
示例#8
0
 def test_variables_ordering_compute(self):
     glob.load_from_file("tests/pynusmv/models/constraints.smv")
     glob.compute_model(variables_ordering=
                        "tests/pynusmv/models/constraints.ord")
     fsm = glob.prop_database().master.bddFsm
     
     with open("tests/pynusmv/models/constraints.ord", "r") as f:
         order = f.read().split("\n")
         self.assertListEqual(order,
                              list(fsm.bddEnc.get_variables_ordering()))
示例#9
0
    def test_variables_ordering_compute(self):
        glob.load_from_file("tests/pynusmv/models/constraints.smv")
        glob.compute_model(
            variables_ordering="tests/pynusmv/models/constraints.ord")
        fsm = glob.prop_database().master.bddFsm

        with open("tests/pynusmv/models/constraints.ord", "r") as f:
            order = f.read().split("\n")
            self.assertListEqual(order,
                                 list(fsm.bddEnc.get_variables_ordering()))
示例#10
0
 def setUp(self):
     init_nusmv()
     load_from_file(
         tests.current_directory(__file__) + "/models/flipflops_vif.smv")
     go_bmc()
     self.enc = master_be_fsm().encoding
     self.v = self.enc.by_name['v']
     self.f = self.enc.by_name['f']
     self.i = self.enc.by_name['i']
     self.n = self.enc.by_name['next(v)']
示例#11
0
 def test_get_mod_instance_type(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.compute_model()
     
     sexp = parse_simple_expression("c1")
     self.assertIsNotNone(sexp)
     
     st = glob.symb_table()
     tp = nssymb_table.SymbTable_get_type_checker(st._ptr)
     expr_type = nstype_checking.TypeChecker_get_expression_type(
                                                        tp, sexp, None)
     self.assertTrue(nssymb_table.SymbType_is_error(expr_type))
示例#12
0
    def test_get_mod_instance_type(self):
        glob.load_from_file("tests/pynusmv/models/counters.smv")
        glob.compute_model()

        sexp = parse_simple_expression("c1")
        self.assertIsNotNone(sexp)

        st = glob.symb_table()
        tp = nssymb_table.SymbTable_get_type_checker(st._ptr)
        expr_type = nstype_checking.TypeChecker_get_expression_type(
            tp, sexp, None)
        self.assertTrue(nssymb_table.SymbType_is_error(expr_type))
示例#13
0
    def test_get_instances_after_flattening(self):
        car = nsnode.car
        cdr = nsnode.cdr

        glob.load_from_file("tests/tools/ctlk/dining-crypto.smv")

        # Flatten
        glob.flatten_hierarchy()

        # Get parsed tree
        tree = nsparser.cvar.parsed_tree
        self.assertIsNotNone(tree)
        self.assertIsNotNone(car(tree))

        print(tree.type)  # 145 = CONS
        print(car(tree).type)  # 117 = MODULE
        print(nsnode.sprint_node(car(car(car(tree)))))  # main
        print(cdr(car(tree)).type)  # 145 = CONS
        print(car(cdr(car(tree))).type)  # 113 = DEFINE
        print(cdr(cdr(car(tree))))  # None
        print(cdr(tree).type)  # 145 = CONS
        print(car(cdr(tree)).type)  # 117 = MODULE
        print(nsnode.sprint_node(car(car(car(cdr(tree))))))  # cryptograph

        print("----- Instances after flattening")
        # main module is car(tree)
        main_vars = self.get_instances_for_module(car(tree))
        # Variables are removed from parsed_tree when flattening
        self.assertEqual(len(main_vars), 0)

        instances_args = {}

        for var in main_vars:
            # var = COLON(ATOM, MODTYPE(ATOM, CONS))

            varname = nsnode.sprint_node(car(var))
            instances_args[varname] = []

            args = cdr(cdr(var))
            argslist = []
            while args is not None:
                arg = car(args)
                instances_args[varname].append(arg)
                argslist.append(nsnode.sprint_node(arg))
                args = cdr(args)

            print(varname, ":", nsnode.sprint_node(car(cdr(var))), argslist)

        print("------------------------------------------------------")
示例#14
0
 def test_get_instances_after_flattening(self):
     car = nsnode.car
     cdr = nsnode.cdr
     
     glob.load_from_file("tests/tools/ctlk/dining-crypto.smv")
     
     # Flatten
     glob.flatten_hierarchy()
     
     # Get parsed tree
     tree = nsparser.cvar.parsed_tree
     self.assertIsNotNone(tree)
     self.assertIsNotNone(car(tree))
     
     print(tree.type) # 145 = CONS
     print(car(tree).type) # 117 = MODULE
     print(nsnode.sprint_node(car(car(car(tree))))) # main
     print(cdr(car(tree)).type) # 145 = CONS
     print(car(cdr(car(tree))).type) # 113 = DEFINE
     print(cdr(cdr(car(tree)))) # None 
     print(cdr(tree).type) # 145 = CONS
     print(car(cdr(tree)).type) # 117 = MODULE
     print(nsnode.sprint_node(car(car(car(cdr(tree)))))) # cryptograph
     
     print("----- Instances after flattening")
     # main module is car(tree)
     main_vars = self.get_instances_for_module(car(tree))
     # Variables are removed from parsed_tree when flattening
     self.assertEqual(len(main_vars), 0)
     
     instances_args = {}
     
     for var in main_vars:
         # var = COLON(ATOM, MODTYPE(ATOM, CONS))
         
         varname = nsnode.sprint_node(car(var))
         instances_args[varname] = []
         
         args = cdr(cdr(var))
         argslist = []
         while args is not None:
             arg = car(args)
             instances_args[varname].append(arg)
             argslist.append(nsnode.sprint_node(arg))
             args = cdr(args)
             
         print(varname, ":", nsnode.sprint_node(car(cdr(var))), argslist)
         
     print("------------------------------------------------------")
示例#15
0
 def test_no_model(self):
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
     glob.flatten_hierarchy()
     with self.assertRaises(NuSMVNeedFlatModelError):
         glob.build_model()
     glob.build_flat_model()
     with self.assertRaises(NuSMVNeedVariablesEncodedError):
         glob.build_model()
     glob.encode_variables()
     glob.build_model()
     with self.assertRaises(NuSMVModelAlreadyBuiltError):
         glob.build_model()
示例#16
0
    def test_printing_parsed_tree(self):
        car = nsnode.car
        cdr = nsnode.cdr

        glob.load_from_file("tests/tools/ctlk/dining-crypto.smv")

        # Get parsed tree
        tree = nsparser.cvar.parsed_tree

        print(tree.type)  # 145 = CONS
        print(car(tree).type)  # 117 = MODULE
        print(car(car(tree)).type)  # 119 = MODTYPE
        print(nsnode.sprint_node(car(car(car(tree)))))  # main
        print(cdr(tree).type)  # 145 = CONS
        print(car(cdr(tree)).type)  # 117 = MODULE
        print(car(car(car(cdr(tree)))).type)  # 161 = ATOM
        print(nsnode.sprint_node(car(car(car(cdr(tree))))))  # cryptograph
        print(cdr(cdr(tree)))  # None
示例#17
0
def run_model_in_nusmv(filename, get_path=False):
    init_nusmv()
    load_from_file(filename)
    compute_model(keep_single_enum=True)
    fsm = prop_database().master.bddFsm
    propDb = prop_database()

    for prop in propDb:
        spec = prop.expr
        status = check_ctl_spec(
            fsm,
            spec) if prop.type == propTypes['CTL'] else check_ltl_spec(spec)
        if status is False:
            print('Specification', str(spec), 'is', str(status))
            if get_path:
                explanation = explain(fsm, fsm.init, spec)
                print_specification_explanation(explanation)

    deinit_nusmv()
示例#18
0
 def test_printing_parsed_tree(self):
     car = nsnode.car
     cdr = nsnode.cdr
     
     glob.load_from_file("tests/tools/ctlk/dining-crypto.smv")
     
     # Get parsed tree
     tree = nsparser.cvar.parsed_tree
     
     
     print(tree.type) # 145 = CONS
     print(car(tree).type) # 117 = MODULE
     print(car(car(tree)).type) # 119 = MODTYPE
     print(nsnode.sprint_node(car(car(car(tree))))) # main
     print(cdr(tree).type) # 145 = CONS
     print(car(cdr(tree)).type) # 117 = MODULE
     print(car(car(car(cdr(tree)))).type) # 161 = ATOM
     print(nsnode.sprint_node(car(car(car(cdr(tree)))))) # cryptograph
     print(cdr(cdr(tree))) # None
示例#19
0
def process(allargs):
    """
    Process program arguments and dump the model.
    Write on standard output the DOT format of the dumped model.
    
    allargs -- a sys.args-like arguments list, without script name.
    
    """

    # Parse arguments
    parser = argparse.ArgumentParser(description="SMV model DOT dumper.")
    # Populate arguments: for now, only the model
    parser.add_argument("model", help="the SMV model")
    args = parser.parse_args(allargs)

    # Initialize the model
    glob.load_from_file(args.model)
    glob.compute_model()
    fsm = glob.prop_database().master.bddFsm

    try:
        print(dumpDot(fsm))
    except PyNuSMVError as e:
        print("[ERROR]", str(e), file=sys.stderr)
示例#20
0
def process(allargs):
    """
    Process program arguments and dump the model.
    Write on standard output the DOT format of the dumped model.
    
    allargs -- a sys.args-like arguments list, without script name.
    
    """

    # Parse arguments
    parser = argparse.ArgumentParser(description='SMV model DOT dumper.')
    # Populate arguments: for now, only the model
    parser.add_argument('model', help='the SMV model')
    args = parser.parse_args(allargs)

    # Initialize the model
    glob.load_from_file(args.model)
    glob.compute_model()
    fsm = glob.prop_database().master.bddFsm

    try:
        print(dumpDot(fsm))
    except PyNuSMVError as e:
        print("[ERROR]", str(e), file=sys.stderr)
示例#21
0
 def test_semantics_error(self):
     glob.load_from_file(
                         "tests/pynusmv/models/counter-semantics-error.smv")
     with self.assertRaises(NuSMVCannotFlattenError):
         glob.flatten_hierarchy()
示例#22
0
 def test_compute_model(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.compute_model()
示例#23
0
 def setUp(self):
     init_nusmv()
     load_from_file(tests.current_directory(__file__)+"/models/flipflops_vif.smv")
     go_bmc()
     self._TESTED = BeEnc.global_singleton_instance()
示例#24
0
 def model(self):
     glob.load_from_file("tests/pynusmv/models/inputs.smv")
     glob.compute_model()
     fsm = glob.prop_database().master.bddFsm
     self.assertIsNotNone(fsm)
     return fsm
示例#25
0
 def model(self):
     glob.load_from_file("tests/pynusmv/models/inputs.smv")
     glob.compute_model()
     fsm = glob.prop_database().master.bddFsm
     self.assertIsNotNone(fsm)
     return fsm
示例#26
0
 def test_flat_model(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     glob.build_flat_model()
示例#27
0
 def test_load_and_flat_allow_encoding_with_command(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     ret = nscmd.Cmd_SecureCommandExecute("encode_variables")
示例#28
0
 def test_parsing(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
示例#29
0
 def test_file_error(self):
     with self.assertRaises(IOError):
         glob.load_from_file("tests/pynusmv/models/no-model.smv")
示例#30
0
 def test_compute_model(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.compute_model()
示例#31
0
 def test_already_encoded(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     glob.encode_variables()
     with self.assertRaises(NuSMVModelAlreadyEncodedError):
         glob.encode_variables()
示例#32
0
 def test_flattening_hierarchy_already_done(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy(keep_single_enum=True)
     with self.assertRaises(NuSMVModelAlreadyFlattenedError):
         glob.flatten_hierarchy()
示例#33
0
 def setUp(self):
     init_nusmv()
     glob.load_from_file(tests.current_directory(__file__)+"/models/dummy_define_justice.smv")
     bmcGlob.go_bmc()
     self.fsm = glob.master_bool_sexp_fsm()
示例#34
0
 def test_no_flat_model_after_parsing(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     with self.assertRaises(NuSMVNeedFlatHierarchyError):
         glob.build_flat_model()
示例#35
0
 def test_bdd_encoding(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     be = glob.bdd_encoding()
     self.assertIsNotNone(be)
示例#36
0
 def test_fsm(self):
     glob.load_from_file("tests/tools/ctlk/dining-crypto.smv")
     glob.compute_model()
     fsm = glob.prop_database().master.bddFsm
     self.assertIsNotNone(fsm)
示例#37
0
 def test_no_prop_database(self):
     with self.assertRaises(NuSMVNeedFlatHierarchyError):
         glob.prop_database()
     with self.assertRaises(NuSMVNeedFlatHierarchyError):
         glob.load_from_file("tests/pynusmv/models/counters.smv")
         glob.prop_database()
示例#38
0
 def setUp(self):
     init_nusmv()
     load_from_file(
         tests.current_directory(__file__) + "/models/dummy_invarspecs.smv")
     go_bmc()
     self.fsm = master_be_fsm()
示例#39
0
 def test_no_flat_model_after_parsing(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     with self.assertRaises(NuSMVNeedFlatHierarchyError):
         glob.build_flat_model()
示例#40
0
文件: testInit.py 项目: yyaan/pynusmv
 def test_init_deinit_stats(self):
     init_nusmv()
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.compute_model()
     deinit_nusmv(ddinfo=True)
     self.assertFalse(is_nusmv_init())
示例#41
0
 def setUp(self):
     init_nusmv()
     load_from_file(tests.current_directory(__file__)+"/models/flipflops.smv")
     go_bmc()
     self.enc = BeEnc.global_singleton_instance()
     self.mgr = self.enc.manager
示例#42
0
 def test_bdd_encoding(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     be = glob.bdd_encoding()
     self.assertIsNotNone(be)
示例#43
0
 def test_flat_command_allow_prop_db(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     ret = nscmd.Cmd_SecureCommandExecute("flatten_hierarchy")
     self.assertEqual(ret, 0)
     pd = glob.prop_database()
     self.assertIsNotNone(pd)
示例#44
0
 def test_model(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     glob.encode_variables()
     glob.build_flat_model()
     glob.build_model()
示例#45
0
 def test_no_prop_database(self):
     with self.assertRaises(NuSMVNeedFlatHierarchyError):
         glob.prop_database()
     with self.assertRaises(NuSMVNeedFlatHierarchyError):
         glob.load_from_file("tests/pynusmv/models/counters.smv")
         glob.prop_database()
示例#46
0
 def test_file_error(self):
     with self.assertRaises(IOError):
         glob.load_from_file(
                         "tests/pynusmv/models/no-model.smv")
示例#47
0
 def test_prop_database(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     pd = glob.prop_database()
     self.assertIsNotNone(pd)
示例#48
0
 def test_semantics_error(self):
     glob.load_from_file("tests/pynusmv/models/counter-semantics-error.smv")
     with self.assertRaises(NuSMVCannotFlattenError):
         glob.flatten_hierarchy()
示例#49
0
 def print_instances(self, filepath):
     print("----- Instances for", filepath)
     
     car = nsnode.car
     cdr = nsnode.cdr
     
     glob.load_from_file(filepath)
     
     # Get parsed tree
     tree = nsparser.cvar.parsed_tree
     
     
     print("--- Main instances")
     # main module is car(tree)
     main_vars = self.get_instances_for_module(car(tree))
     
     instances_args = {}
     
     for var in main_vars:
         # var = COLON(ATOM, MODTYPE(ATOM, CONS))
         
         varname = nsnode.sprint_node(car(var))
         instances_args[varname] = []
         
         args = cdr(cdr(var))
         argslist = []
         while args is not None:
             arg = car(args)
             instances_args[varname].append(arg)
             argslist.append(nsnode.sprint_node(arg))
             args = cdr(args)
             
         print(varname, ":", nsnode.sprint_node(car(cdr(var))), argslist)
             
     
     # Get FSM and stuff
     glob.compute_model()
     fsm = glob.prop_database().master.bddFsm
     self.assertIsNotNone(fsm)
     
     flatH = nscompile.cvar.mainFlatHierarchy
     st = nscompile.Compile_get_global_symb_table()
     self.assertIsNotNone(flatH)
     
     
     print("--- Check arguments instances")
     for instance in instances_args:
         print("INSTANCE", instance)
         for arg in instances_args[instance]:                
             arg, err = nscompile.FlattenSexp(st, arg, None)
             self.assertEqual(err, 0)
             isVar = nssymb_table.SymbTable_is_symbol_var(st, arg)
             if isVar:
                 print("VAR", nsnode.sprint_node(arg))
             else:
                 print("NOT VAR", nsnode.sprint_node(arg))
     
     
     print("--- All vars")
     varset = nscompile.FlatHierarchy_get_vars(flatH)
     self.assertIsNotNone(varset)
     varlist = nsset.Set_Set2List(varset)
     self.assertIsNotNone(varlist)
     
     ite = nsutils.NodeList_get_first_iter(varlist)
     while not nsutils.ListIter_is_end(ite):
         var = nsutils.NodeList_get_elem_at(varlist, ite)
         isInput = nssymb_table.SymbTable_is_symbol_input_var(st, var)
         isVar = nssymb_table.SymbTable_is_symbol_var(st, var)
         if isInput:
             print("IVAR", "\t",
                   "IN", "'" + nsnode.sprint_node(car(var)) + "'", "\t",
                   nsnode.sprint_node(var))
         elif isVar:
             print("VAR", "\t",
                   "IN", "'" + nsnode.sprint_node(car(var)) + "'", "\t",
                   nsnode.sprint_node(var))
         else:
             print("[ERROR] Unknown type:", nsnode.sprint_node(var))
         ite = nsutils.ListIter_get_next(ite)
         
     print("------------------------------------------------------")
示例#50
0
 def test_load_allow_flattening_with_command(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     ret = nscmd.Cmd_SecureCommandExecute("flatten_hierarchy")
     self.assertEqual(ret, 0)
示例#51
0
 def test_parsing(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
示例#52
0
 def test_no_encoding_after_parsing(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     with self.assertRaises(NuSMVNeedFlatHierarchyError):
         glob.encode_variables()
示例#53
0
 def test_load_allow_flattening_with_command(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     ret = nscmd.Cmd_SecureCommandExecute("flatten_hierarchy")
     self.assertEqual(ret, 0)
示例#54
0
 def test_flat_command_allow_prop_db(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     ret = nscmd.Cmd_SecureCommandExecute("flatten_hierarchy")
     self.assertEqual(ret, 0)
     pd = glob.prop_database()
     self.assertIsNotNone(pd)
示例#55
0
 def test_load_and_flat_allow_encoding_with_command(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     ret = nscmd.Cmd_SecureCommandExecute("encode_variables")
示例#56
0
 def test_prop_database(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     glob.flatten_hierarchy()
     pd = glob.prop_database()
     self.assertIsNotNone(pd)
示例#57
0
 def test_no_encoding_after_parsing(self):
     glob.load_from_file("tests/pynusmv/models/counters.smv")
     with self.assertRaises(NuSMVNeedFlatHierarchyError):
         glob.encode_variables()
示例#58
0
 def setUp(self):
     init_nusmv()
     load_from_file(tests.current_directory(__file__)+"/models/dummy_invarspecs.smv")
     go_bmc()
     self.fsm = master_be_fsm()
示例#59
0
def go_bmc(model):
  glob.load_from_file(model)
  _cmd.Cmd_CommandExecute("flatten_hierarchy")
  _cmd.Cmd_CommandExecute("encode_variables")
  _cmd.Cmd_CommandExecute("build_boolean_model")
  _cmd.Cmd_CommandExecute("bmc_setup");