def test_bmc_setup(self): # pre conditions not satisfied # model must be loaded with self.assertRaises(NuSMVNeedBooleanModelError): bmcglob.bmc_setup() # vars need to be encoded load(self.model()) with self.assertRaises(NuSMVNeedBooleanModelError): bmcglob.bmc_setup() # boolean model must be compiled out of the sexp flatten_hierarchy() with self.assertRaises(NuSMVNeedBooleanModelError): bmcglob.bmc_setup() # hierarchy must be flattened (actually, this is a requirement for the # boolean model too) encode_variables() with self.assertRaises(NuSMVNeedBooleanModelError): bmcglob.bmc_setup() # may not be called 2 times build_boolean_model() with self.assertRaises(NuSMVBmcAlreadyInitializedError): bmcglob.bmc_setup() bmcglob.bmc_setup() # even if the force flag is on (that's COI related) with self.assertRaises(NuSMVBmcAlreadyInitializedError): bmcglob.bmc_setup(force=True) bmcglob.bmc_exit()
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()
def test_sets_the_global_values(self): glob.flatten_hierarchy() glob.encode_variables() with self.assertRaises(NuSMVNeedBooleanModelError): glob.master_bool_sexp_fsm() glob.build_boolean_model() self.assertIsNotNone(glob.master_bool_sexp_fsm())
def test_master_be_fsm(self): load(self.model()) flatten_hierarchy() encode_variables() build_boolean_model() bmcglob.bmc_setup() # may not provoke C assert failures bmcglob.build_master_be_fsm() self.assertEqual(bmcglob.master_be_fsm(), BeFsm.global_master_instance()) bmcglob.bmc_exit()
def test_build_master_be_fsm(self): load(self.model()) flatten_hierarchy() encode_variables() build_boolean_model() bmcglob.bmc_setup() # may not provoke C assert failures bmcglob.build_master_be_fsm() bmcglob.bmc_exit()
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 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 test_variables_ordering(self): glob.load_from_file("tests/pynusmv/models/constraints.smv") glob.flatten_hierarchy() glob.encode_variables( variables_ordering="tests/pynusmv/models/constraints.ord") glob.compute_model() 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()))
def test_variables_ordering(self): glob.load_from_file("tests/pynusmv/models/constraints.smv") glob.flatten_hierarchy() glob.encode_variables(variables_ordering= "tests/pynusmv/models/constraints.ord") glob.compute_model() 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()))
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("------------------------------------------------------")
def test_change_trans_of_flat(self): glob.load(*self.counters()) glob.flatten_hierarchy() flat = glob.flat_hierarchy() self.assertIsNotNone(flat) trans = flat.trans choose_run = node.Expression.from_string("run = rc1") flat.trans = flat.trans & choose_run glob.compute_model() fsm = glob.prop_database().master.bddFsm self.assertEqual(fsm.count_states(fsm.reachable_states), 3)
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()
def go_bmc(force=False): """ Performs all the necessary steps to use loaded model and be able to perform bmc related operations on it. :raises NuSMVNoReadModelError: if no module was read (:func:`pynusmv.glob.load`) before this method was called. """ cmp = glob.global_compile_cmps() if not _compile.cmp_struct_get_read_model(cmp): raise NuSMVNoReadModelError("No read model.") # Check cmps and perform what is needed if not _compile.cmp_struct_get_flatten_hrc(cmp): glob.flatten_hierarchy() if not _compile.cmp_struct_get_encode_variables(cmp): glob.encode_variables() if not _compile.cmp_struct_get_build_bool_model(cmp): glob.build_boolean_model(force=force) if not _compile.cmp_struct_get_bmc_setup(cmp): bmc_setup(force=force)
def go_bmc(force=False): """ Performs all the necessary steps to use loaded model and be able to perform bmc related operations on it. :raises NuSMVNoReadModelError: if no module was read (:see:`glob.load`) before this method was called. """ cmp = glob.global_compile_cmps() if not _compile.cmp_struct_get_read_model(cmp): raise NuSMVNoReadModelError("No read model.") # Check cmps and perform what is needed if not _compile.cmp_struct_get_flatten_hrc(cmp): glob.flatten_hierarchy() if not _compile.cmp_struct_get_encode_variables(cmp): glob.encode_variables() if not _compile.cmp_struct_get_build_bool_model(cmp): glob.build_boolean_model(force=force) if not _compile.cmp_struct_get_bmc_setup(cmp): bmc_setup(force=force)
def test_flat_model(self): glob.load_from_file("tests/pynusmv/models/counters.smv") glob.flatten_hierarchy() glob.build_flat_model() with self.assertRaises(NuSMVFlatModelAlreadyBuiltError): glob.build_flat_model()
def test_semantics_error(self): glob.load_from_file( "tests/pynusmv/models/counter-semantics-error.smv") with self.assertRaises(NuSMVCannotFlattenError): glob.flatten_hierarchy()
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()
def test_must_not_be_already_built_unless_force_flag(self): glob.flatten_hierarchy() glob.encode_variables() glob.build_boolean_model() glob.build_boolean_model(force=True)
def test_flat_model(self): glob.load_from_file("tests/pynusmv/models/counters.smv") glob.flatten_hierarchy() glob.build_flat_model()
def test_prop_database(self): glob.load_from_file("tests/pynusmv/models/counters.smv") glob.flatten_hierarchy() pd = glob.prop_database() self.assertIsNotNone(pd)
def test_bdd_encoding(self): glob.load_from_file("tests/pynusmv/models/counters.smv") glob.flatten_hierarchy() be = glob.bdd_encoding() self.assertIsNotNone(be)
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")
def test_no_flattening_hierarchy(self): with self.assertRaises(NuSMVNoReadModelError): glob.flatten_hierarchy()
def test_semantics_error(self): glob.load_from_file("tests/pynusmv/models/counter-semantics-error.smv") with self.assertRaises(NuSMVCannotFlattenError): glob.flatten_hierarchy()
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()
def test_must_not_be_already_built(self): glob.flatten_hierarchy() glob.encode_variables() glob.build_boolean_model() with self.assertRaises(NuSMVModelAlreadyBuiltError): glob.build_boolean_model()
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()
def test_vars_must_be_encoded(self): glob.flatten_hierarchy() with self.assertRaises(NuSMVNeedVariablesEncodedError): glob.build_boolean_model()