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
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
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)']
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
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_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()))
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()))
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)']
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))
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_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 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
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()
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)
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)
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_compute_model(self): glob.load_from_file("tests/pynusmv/models/counters.smv") glob.compute_model()
def setUp(self): init_nusmv() load_from_file(tests.current_directory(__file__)+"/models/flipflops_vif.smv") go_bmc() self._TESTED = BeEnc.global_singleton_instance()
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
def test_flat_model(self): glob.load_from_file("tests/pynusmv/models/counters.smv") glob.flatten_hierarchy() glob.build_flat_model()
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_parsing(self): glob.load_from_file("tests/pynusmv/models/counters.smv")
def test_file_error(self): with self.assertRaises(IOError): glob.load_from_file("tests/pynusmv/models/no-model.smv")
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_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 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()
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()
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_fsm(self): glob.load_from_file("tests/tools/ctlk/dining-crypto.smv") glob.compute_model() fsm = glob.prop_database().master.bddFsm self.assertIsNotNone(fsm)
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()
def setUp(self): init_nusmv() load_from_file( tests.current_directory(__file__) + "/models/dummy_invarspecs.smv") go_bmc() self.fsm = master_be_fsm()
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())
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
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)
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_file_error(self): with self.assertRaises(IOError): glob.load_from_file( "tests/pynusmv/models/no-model.smv")
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_semantics_error(self): glob.load_from_file("tests/pynusmv/models/counter-semantics-error.smv") with self.assertRaises(NuSMVCannotFlattenError): glob.flatten_hierarchy()
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("------------------------------------------------------")
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)
def test_no_encoding_after_parsing(self): glob.load_from_file("tests/pynusmv/models/counters.smv") with self.assertRaises(NuSMVNeedFlatHierarchyError): glob.encode_variables()
def setUp(self): init_nusmv() load_from_file(tests.current_directory(__file__)+"/models/dummy_invarspecs.smv") go_bmc() self.fsm = master_be_fsm()
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");