def test_generate_counter_example(self): load_from_string(""" MODULE main VAR v : boolean; w : boolean; ASSIGN init(v) := TRUE; next(v) := !v; init(w) := FALSE; next(w) := !w; """) with BmcSupport(): bound = 2 fsm = master_be_fsm() expr = Node.from_ptr(parse_ltl_spec("F ( w <-> v )")) pb = generate_ltl_problem(fsm, expr, bound=bound) cnf = pb.inline(True).to_cnf() solver = SatSolverFactory.create() solver += cnf solver.polarity(cnf, Polarity.POSITIVE) self.assertEqual(SatSolverResult.SATISFIABLE, solver.solve()) trace = bmcutils.generate_counter_example(fsm, pb, solver, bound, "GENERATED") self.assertIsNotNone(trace) self.assertEqual(2, len(trace)) print(trace)
def test_concat(self): with BmcSupport(): sexp_fsm = master_bool_sexp_fsm() be_fsm = master_be_fsm() trace = Trace.create("Dummy example", TraceType.COUNTER_EXAMPLE, sexp_fsm.symbol_table, sexp_fsm.symbols_list, is_volatile=True) spec = Node.from_ptr(parse_ltl_spec("F (w <-> v)")) bound = 2 problem = generate_ltl_problem(be_fsm, spec, bound=bound) #.inline(True) cnf = problem.to_cnf() solver = SatSolverFactory.create() solver += cnf solver.polarity(cnf, Polarity.POSITIVE) solver.solve() other = generate_counter_example(be_fsm, problem, solver, bound) trace.concat(other) self.assertEquals(-1, trace.id) self.assertFalse(trace.is_registered) self.assertEquals("Dummy example", trace.description) self.assertEquals(TraceType.COUNTER_EXAMPLE, trace.type) self.assertTrue(trace.is_volatile) self.assertEquals(2, trace.length) self.assertEquals(2, len(trace)) self.assertFalse(trace.is_empty) self.assertFalse(trace.is_frozen) self.assertTrue(trace.is_thawed)
def check_problem(pb, length): fsm = master_be_fsm() cnf = pb.to_cnf(Polarity.POSITIVE) solver = SatSolverFactory.create() solver+= cnf solver.polarity(cnf, Polarity.POSITIVE) if solver.solve() == SatSolverResult.SATISFIABLE: cnt_ex = bmcutils.generate_counter_example(fsm, pb, solver, length, "Violation") return ("Violation", cnt_ex) else: return ("Ok", None)
def check_ltl_onepb(fml, length, no_fairness=False, no_invar=False, dry_run=False): """ This function verifies that the given FSM satisfies the given property for paths with an exact length of `length`. :param fml: an LTL formula parsed with `pynusmv_tools.bmcLTL.parsing` (hence the abstract syntax tree of that formula). Note, this is *NOT* the NuSMV format (Node). :param length: the exact length of the considered paths :param no_fairness: a flag telling whether or not the generated problem should focus on fair executions only (the considered fairness constraints must be declared in the SMV model). :param no_invar: a flag telling whether or not the generated problem should enforce the declared invariants (these must be declared in the SMV text). :return: a tuple ('OK', None) if the property is satisfied on all paths of length `length` :return: a tuple ('Violation', counter_example) if the property is violated. The counter_example passed along is a trace leading to a violation of the property """ fsm = master_be_fsm() pb = generate_problem(fml, fsm, length, no_fairness, no_invar) if not dry_run: cnf = pb.to_cnf(Polarity.POSITIVE) solver = SatSolverFactory.create() solver += cnf solver.polarity(cnf, Polarity.POSITIVE) if solver.solve() == SatSolverResult.SATISFIABLE: cnt_ex = generate_counter_example(fsm, pb, solver, length, str(fml)) return ("Violation", cnt_ex) else: return ("Ok", None) return ("Ok", None)
def check_ltl_onepb(fml, length, no_fairness=False, no_invar=False, dry_run=False): """ This function verifies that the given FSM satisfies the given property for paths with an exact length of `length`. :param fml: an LTL formula parsed with `tools.bmcLTL.parsing` (hence the abstract syntax tree of that formula). Note, this is *NOT* the NuSMV format (Node). :param length: the exact length of the considered paths :param no_fairness: a flag telling whether or not the generated problem should focus on fair executions only (the considered fairness constraints must be declared in the SMV model). :param no_invar: a flag telling whether or not the generated problem should enforce the declared invariants (these must be declared in the SMV text). :return: a tuple ('OK', None) if the property is satisfied on all paths of length `length` :return: a tuple ('Violation', counter_example) if the property is violated. The counter_example passed along is a trace leading to a violation of the property """ fsm = master_be_fsm() pb = generate_problem(fml, fsm, length, no_fairness, no_invar) if not dry_run: cnf = pb.to_cnf(Polarity.POSITIVE) solver = SatSolverFactory.create() solver+= cnf solver.polarity(cnf, Polarity.POSITIVE) if solver.solve() == SatSolverResult.SATISFIABLE: cnt_ex = generate_counter_example(fsm, pb, solver, length, str(fml)) return ("Violation", cnt_ex) else: return ("Ok", None) return ("Ok", None)
def test_concat(self): with BmcSupport(): sexp_fsm = master_bool_sexp_fsm() be_fsm = master_be_fsm() trace = Trace.create( "Dummy example", TraceType.COUNTER_EXAMPLE, sexp_fsm.symbol_table, sexp_fsm.symbols_list, is_volatile=True, ) spec = Node.from_ptr(parse_ltl_spec("F (w <-> v)")) bound = 2 problem = generate_ltl_problem(be_fsm, spec, bound=bound) # .inline(True) cnf = problem.to_cnf() solver = SatSolverFactory.create() solver += cnf solver.polarity(cnf, Polarity.POSITIVE) solver.solve() other = generate_counter_example(be_fsm, problem, solver, bound) trace.concat(other) self.assertEquals(-1, trace.id) self.assertFalse(trace.is_registered) self.assertEquals("Dummy example", trace.description) self.assertEquals(TraceType.COUNTER_EXAMPLE, trace.type) self.assertTrue(trace.is_volatile) self.assertEquals(2, trace.length) self.assertEquals(2, len(trace)) self.assertFalse(trace.is_empty) self.assertFalse(trace.is_frozen) self.assertTrue(trace.is_thawed)