def test_simple_fair_with_alias(self): class main(md.Module): c = md.Var(md.Boolean()) INIT = c TRANS = (c.next() == ~c) FAIRNESS = [c, ~c] model.load(main) fsm = model.bddModel() self.assertIsNotNone(fsm) @alias("EX {child}") def EX(child): return Diamond(child) @alias() def Reach(target): return Mu(Variable("W"), Or(target, EX(Variable("W")))) @alias("And{{{variable} in {elements}}} {body}") def BigAnd(body, variable, elements): if len(elements) <= 0: return MTrue() else: element = next(iter(elements)) elembody = body._substitute(variable, element) elements = elements[1:] if len(elements) > 1: return And(elembody, BigAnd(body, variable, elements)) elif len(elements) == 1: n = next(iter(elements)) nbody = body._substitute(variable, n) return And(elembody, nbody) else: return elembody @alias(form="fair") def fair(fsm): body = EX(Reach(And(Variable("Z"), Variable("fci")))) return Nu( Variable("Z"), BigAnd(body, Variable("fci"), [ POI(Variable("fc%d" % index)) for index in range(len(fsm.fairness_constraints)) ])) # Compute fair expr = SPOI(fair(fsm)) context = { Variable("fc%d" % index): constraint for index, constraint in enumerate(fsm.fairness_constraints) } sat = expr.eval(fsm, context=context) self.assertTrue(fsm.init <= sat) state = fsm.pick_one_state(sat & fsm.init) expl = expr.explain(fsm, state, context=context) self.assertIsNotNone(expl.dot())
def test_one_transition(self): smvmodel = """ MODULE main VAR state: {s1, s2}; INIT state = s1 TRANS next(state) = s2 """ model.load_from_string(smvmodel) fsm = model.bddModel() self.assertSetEqual(set(fsm.transitions.keys()), {'time'}) self.assertEqual(fsm.post(fsm.init, transition='time'), eval_simple_expression(fsm, 'state = s2'))
def test_several_transitions(self): smvmodel = """ MODULE main VAR state: {s1, s2}; IVAR transition : {time, knowledge}; INIT state = s1 TRANS case transition = time : next(state) = s2; transition = knowledge : next(state) = state; esac """ model.load_from_string(smvmodel) fsm = model.bddModel() self.assertSetEqual(set(fsm.transitions.keys()), {'time', 'knowledge'}) self.assertEqual(fsm.post(fsm.init, transition='time'), eval_simple_expression(fsm, 'state = s2')) self.assertEqual(fsm.post(fsm.init, transition='knowledge'), eval_simple_expression(fsm, 'state = s1')) with self.assertRaises(UnknownTransitionError): fsm.post(fsm.init, 'unknown')
def test_additional_transitions(self): smvmodel = """ MODULE main VAR state: {s1, s2}; IVAR transition : {time, knowledge}; INIT state = s1 TRANS case transition = time : next(state) = s2; transition = knowledge : next(state) = state; esac """ model.load_from_string(smvmodel) transitions = {'reset': 'next(state) = s1'} fsm = model.bddModel(transitions=transitions) self.assertSetEqual(set(fsm.transitions.keys()), {'time', 'knowledge', 'reset'}) self.assertEqual(fsm.post(fsm.init, 'time'), eval_simple_expression(fsm, 'state = s2')) self.assertEqual(fsm.post(fsm.init, 'knowledge'), eval_simple_expression(fsm, 'state = s1')) self.assertEqual(fsm.post(fsm.reachable_states, 'reset'), eval_simple_expression(fsm, 'state = s1'))
def test_inputs(self): smvmodel = """ MODULE main VAR state: {s1, s2}; IVAR run: boolean; INIT state = s1 TRANS next(state) = (run ? s2 : state) """ model.load_from_string(smvmodel) fsm = model.bddModel() self.assertSetEqual(set(fsm.transitions.keys()), {'time'}) self.assertEqual( fsm.post(fsm.init, transition='time'), eval_simple_expression(fsm, 'state = s2 | state = s1')) run = eval_simple_expression(fsm, "run") self.assertEqual(fsm.post(fsm.init, inputs=run), eval_simple_expression(fsm, 'state = s2')) nrun = eval_simple_expression(fsm, "!run") self.assertEqual(fsm.post(fsm.init, inputs=nrun), eval_simple_expression(fsm, 'state = s1'))
def cardgame_post_fair(self): model.load_from_file("tests/pynusmv_tools/mucalculus/models/" "cardgame-post-fair.smv") fsm = model.bddModel() self.assertIsNotNone(fsm) return fsm
def cardgame(self): model.load_from_file( "tests/pynusmv_tools/mucalculus/models/cardgame.smv") fsm = model.bddModel() self.assertIsNotNone(fsm) return fsm