def build_master_be_fsm(): """ Creates the BE fsm from the Sexpr FSM. Currently the be_enc is a singleton global private variable which is shared between all the BE FSMs. If not previoulsy committed (because a boolean encoder was not available at the time due to the use of coi) the determinization layer will be committed to the be_encoder :raises NuSMVBeEncNotInitializedError: if the global BeEnc singleton is not initialized """ global __be_fsm # raises the exception if necessary be_enc = BeEnc.global_singleton_instance() sym_table = be_enc.symbol_table if _symb_table.SymbTable_get_layer(sym_table._ptr, "inlining") is not None: # commits the determ layer if not previously committed if not _baseenc.BaseEnc_layer_occurs(be_enc._ptr, "determ"): _baseenc.BaseEnc_commit_layer(be_enc._ptr, "determ") # commits the inlining layer if not previously committed # note: I find this a little bit weird, but that's the way NuSMV proceeds if not _baseenc.BaseEnc_layer_occurs(be_enc._ptr, "inlining"): _baseenc.BaseEnc_commit_layer(be_enc._ptr, "inlining") # actual fsm creation __be_fsm = BeFsm.create_from_sexp(be_enc, glob.master_bool_sexp_fsm()) propdb = _prop.PropPkg_get_prop_database() _prop.PropDb_master_set_be_fsm(propdb, __be_fsm._ptr);
def setUp(self): init_nusmv() glob.load(self.model()) glob.flatten_hierarchy() glob.encode_variables() # does it for BDD self.go_bmc() pd = _prop.PropPkg_get_prop_database() fsm = _prop.PropDb_master_get_be_fsm(pd) self._TEST = _be.BeFsm_get_fairness_list(fsm)
def build_model(): """ Build the BDD FSM of the current model and store it in global data structures. :raise: a :exc:`NuSMVNeedFlatModelError <pynusmv.exception.NuSMVNeedFlatModelError>` if the Sexp FSM of the model is not built yet :raise: a :exc:`NuSMVNeedVariablesEncodedError <pynusmv.exception.NuSMVNeedVariablesEncodedError>` if the variables of the model are not encoded yet :raise: a :exc:`NuSMVModelAlreadyBuiltError <pynusmv.exception.NuSMVModelAlreadyBuiltError>` if the BDD FSM of the model is already built """ # Check cmps if not nscompile.cmp_struct_get_build_flat_model(global_compile_cmps()): raise NuSMVNeedFlatModelError("Need flat model.") if not nscompile.cmp_struct_get_encode_variables(global_compile_cmps()): raise NuSMVNeedVariablesEncodedError("Need variables encoded.") if nscompile.cmp_struct_get_build_model(global_compile_cmps()): raise NuSMVModelAlreadyBuiltError("The model is already built.") # Build the model pd = nsprop.PropPkg_get_prop_database() sexp_fsm = nsprop.PropDb_master_get_scalar_sexp_fsm(pd) bdd_fsm = nsfsm.FsmBuilder_create_bdd_fsm( nscompile.Compile_get_global_fsm_builder(), nsenc.Enc_get_bdd_encoding(), sexp_fsm, nsopt.get_partition_method(nsopt.OptsHandler_get_instance())) nsprop.PropDb_master_set_bdd_fsm(pd, bdd_fsm) # Register executors enc = nsbddfsm.BddFsm_get_bdd_encoding(bdd_fsm) nstrace.TraceManager_register_complete_trace_executor( nstrace.TracePkg_get_global_trace_manager(), "bdd", "BDD partial trace execution", nstraceexec.bddCompleteTraceExecutor2completeTraceExecutor( nstraceexec.BDDCompleteTraceExecutor_create(bdd_fsm, enc))) nstrace.TraceManager_register_partial_trace_executor( nstrace.TracePkg_get_global_trace_manager(), "bdd", "BDD complete trace execution", nstraceexec.bddPartialTraceExecutor2partialTraceExecutor( nstraceexec.BDDPartialTraceExecutor_create(bdd_fsm, enc))) # Update cmps nscompile.cmp_struct_set_build_model(global_compile_cmps())
def test_nsmc(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) # Check CTL specs propDb = nsprop.PropPkg_get_prop_database() for i in range(nsprop.PropDb_get_size(propDb)): p = nsprop.PropDb_get_prop_at_index(propDb, i) if nsprop.Prop_get_type(p) == nsprop.Prop_Ctl: nsmc.Mc_CheckCTLSpec(p)
def prop_database(): """ Return the global properties database. :rtype: :class:`PropDb <pynusmv.prop.PropDb>` """ if not nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()): # Need a flat hierarchy raise NuSMVNeedFlatHierarchyError("Need flat hierarchy.") global __prop_database if __prop_database is None: __prop_database = PropDb(nsprop.PropPkg_get_prop_database()) return __prop_database
def global_master_instance(): """ :return: the boolean FSM in BE stored in the master prop. :raises NuSMVBeFsmMasterInstanceNotInitializedError: when the global BE FSM is null in the global properties database (ie when coi is enabled). """ _pd = _prop.PropPkg_get_prop_database() _fsm = _prop.PropDb_master_get_be_fsm(_pd) if _fsm is None: raise NuSMVBeFsmMasterInstanceNotInitializedError(""" BE fsm stored in master prop is not initialized. You must either initialize the BE model (ie. go_bmc) or disable COI. """) return BeFsm(_fsm)
def master_bool_sexp_fsm(): """ Return the global boolean SEXP model. :rtype: :class:`BoolSexpFsm <pynusmv.sexp.BoolSexpFsm>` """ global __bool_sexp_fsm if not nscompile.cmp_struct_get_build_bool_model(global_compile_cmps()): raise NuSMVNeedBooleanModelError("boolean model not initialized") if __bool_sexp_fsm is None: propdb = nsprop.PropPkg_get_prop_database() fsm_ptr = nsprop.PropDb_master_get_bool_sexp_fsm(propdb) __bool_sexp_fsm = BoolSexpFsm(fsm_ptr, freeit=False) return __bool_sexp_fsm
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)
def build_flat_model(): """ Build the Sexp FSM (Simple Expression FSM) of the current model and store it in global data structures. :raise: a :exc:`NuSMVNeedFlatHierarchyError <pynusmv.exception.NuSMVNeedFlatHierarchyError>` if the model is not flattened :raise: a :exc:`NuSMVFlatModelAlreadyBuiltError <pynusmv.exception.NuSMVFlatModelAlreadyBuiltError>` if the Sexp FSM is already built """ # Check cmps if not nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()): raise NuSMVNeedFlatHierarchyError("Need flat hierarchy.") if nscompile.cmp_struct_get_build_flat_model(global_compile_cmps()): raise NuSMVFlatModelAlreadyBuiltError( "The flat model is already built.") # Simplify the model st = nscompile.Compile_get_global_symb_table() layer = nssymb_table.SymbTable_get_layer(st, "model") ite = nssymb_table.gen_iter(layer, nssymb_table.STT_VAR) variables = nssymb_table.SymbLayer_iter_to_set(layer, ite) sexp_fsm = nsfsm.FsmBuilder_create_scalar_sexp_fsm( nscompile.Compile_get_global_fsm_builder(), global_compile_flathierarchy(), variables) nsset.Set_ReleaseSet(variables) nsprop.PropDb_master_set_scalar_sexp_fsm( nsprop.PropPkg_get_prop_database(), sexp_fsm) # Update cmps nscompile.cmp_struct_set_build_flat_model(global_compile_cmps())
def build_boolean_model(force=False): """ Compiles the flattened hierarchy into a boolean model (SEXP) and stores it it a global variable. .. note:: This function is subject to the following requirements: - hierarchy must already be flattened (:func:`flatten_hierarchy`) - encoding must be already built (:func:`encode_variables`) - boolean model must not exist yet (or the force flag must be on) :param force: a flag telling whether or not the boolean model must be built even though the cone of influence option is turned on. :raises NuSMVNeedFlatHierarchyError: if the hierarchy wasn't flattened yet. :raises NuSMVNeedVariablesEncodedError: if the variables are not yet encoded :raises NuSMVModelAlreadyBuiltError: if the boolean model is already built and force=False """ global __bool_sexp_fsm # check the preconditions if not nscompile.cmp_struct_get_encode_variables(global_compile_cmps()): raise NuSMVNeedVariablesEncodedError("Need variables encoded.") if nscompile.cmp_struct_get_build_bool_model( global_compile_cmps()) and not force: raise NuSMVModelAlreadyBuiltError( "The boolean model is already built and the force flag is off") # create the flat model if need be. if not nscompile.cmp_struct_get_build_flat_model(global_compile_cmps()): build_flat_model() # Create the boolean model proper (CompileCmd.c/compile_create_boolean_model) propdb = nsprop.PropPkg_get_prop_database() bool_sexp_fsm = nsprop.PropDb_master_get_bool_sexp_fsm(propdb) # even though the force flag is on, a call to this method will have no effect # if the bool sexp_fsm already exists in the propdb (reproduces the behavior # of CompileCmd.c/compile_create_boolean_model() ) if bool_sexp_fsm is None: benc = __bdd_encoding symb = benc.symbTable mgr = benc.DDmanager # Temporarily disable reordering (if needed) reord = nsdd.wrap_dd_reordering_status(mgr._ptr) if reord.status == 1: nsdd.dd_autodyn_disable(mgr._ptr) # add 'determ' to the default and Artifact classes determ = symb.create_layer("determ", nssymb_table.SYMB_LAYER_POS_BOTTOM) nssymb_table.SymbTable_layer_add_to_class(symb._ptr, "determ", None) nssymb_table.SymbTable_layer_add_to_class(symb._ptr, "determ", "Artifacts Class") # THIS IS THE REAL CREATION !! scalar_sexp_fsm = nsprop.PropDb_master_get_scalar_sexp_fsm(propdb) bool_sexp_fsm = nssexp.BoolSexpFsm_create_from_scalar_fsm( scalar_sexp_fsm, benc._ptr, determ) __bool_sexp_fsm = BoolSexpFsm(bool_sexp_fsm, freeit=False) nsprop.PropDb_master_set_bool_sexp_fsm(propdb, bool_sexp_fsm) # unfortunately, if the C malloc fails, the C assertion will also fail # and result in a program crash. boolenc = nsboolenc.boolenc2baseenc(nsenc.Enc_get_bool_encoding()) nsbaseenc.BaseEnc_commit_layer(boolenc, "determ") bddenc = nsbddenc.bddenc2baseenc(nsenc.Enc_get_bdd_encoding()) nsbaseenc.BaseEnc_commit_layer(bddenc, "determ") # Re-enable reordering if it had been disabled if reord.status == 1: nsdd.dd_autodyn_enable(mgr._ptr, reord.method) # Tell NuSMV that the boolean model was built nscompile.cmp_struct_set_build_bool_model(global_compile_cmps())