Beispiel #1
0
def check_fcs_in_state(mod,ag,post,fcs):
#    iu.dbg('"foo"')
    history = ag.get_history(post)
#    iu.dbg('history.actions')
    gmc = lambda cls, final_cond: itr.small_model_clauses(cls,final_cond,shrink=diagnose.get())
    axioms = im.module.background_theory()
    if opt_trace.get():
        clauses = history.post
        clauses = lut.and_clauses(clauses,axioms)
        ffcs = filter_fcs(fcs)
        model = itr.small_model_clauses(clauses,ffcs,shrink=True)
        if model is not None:
#            iu.dbg('history.actions')
            mclauses = lut.and_clauses(*([clauses] + [c.cond() for c in ffcs if c.failed]))
            vocab = lut.used_symbols_clauses(mclauses)
            handler = MatchHandler(mclauses,model,vocab)
            assert all(x is not None for x in history.actions)
            # work around a bug in ivy_interp
            actions = [im.module.actions[a] if isinstance(a,str) else a for a in history.actions]
#            iu.dbg('actions')
            action = act.Sequence(*actions)
            act.match_annotation(action,clauses.annot,handler)
            handler.end()
            exit(0)
    else:
        res = history.satisfy(axioms,gmc,filter_fcs(fcs))
        if res is not None and diagnose.get():
            show_counterexample(ag,post,res)
    return not any(fc.failed for fc in fcs)
Beispiel #2
0
def check_fcs_in_state(mod, ag, post, fcs):
    #    iu.dbg('"foo"')
    history = ag.get_history(post)
    #    iu.dbg('history.actions')
    gmc = lambda cls, final_cond: itr.small_model_clauses(
        cls, final_cond, shrink=diagnose.get())
    axioms = im.module.background_theory()
    if opt_trace.get() or diagnose.get():
        clauses = history.post
        clauses = lut.and_clauses(clauses, axioms)
        ffcs = filter_fcs(fcs)
        model = itr.small_model_clauses(clauses, ffcs, shrink=True)
        if model is not None:
            #            iu.dbg('history.actions')
            failed = [c for c in ffcs if c.failed]
            mclauses = lut.and_clauses(*([clauses] +
                                         [c.cond() for c in failed]))
            vocab = lut.used_symbols_clauses(mclauses)
            #            handler = MatchHandler(mclauses,model,vocab) if opt_trace.get() else ivy_trace.Trace(mclauses,model,vocab)
            handler = ivy_trace.Trace(mclauses, model, vocab)
            thing = failed[-1].get_annot()
            if thing is None:
                assert all(x is not None for x in history.actions)
                # work around a bug in ivy_interp
                actions = [
                    im.module.actions[a] if isinstance(a, str) else a
                    for a in history.actions
                ]
                action = act.Sequence(*actions)
                annot = clauses.annot
            else:
                action, annot = thing
            act.match_annotation(action, annot, handler)
            handler.end()
            ff = failed[0]
            handler.is_cti = (lut.formula_to_clauses(ff.lf.formula)
                              if isinstance(ff, ConjChecker) else None)
            if not opt_trace.get():
                gui_art(handler)
            else:
                print str(handler)
            exit(0)
    else:
        res = history.satisfy(axioms, gmc, filter_fcs(fcs))
        if res is not None and diagnose.get():
            show_counterexample(ag, post, res)
    return not any(fc.failed for fc in fcs)
Beispiel #3
0
def check_fcs_in_state(mod,ag,post,fcs):
    history = ag.get_history(post)
    gmc = lambda cls, final_cond: itr.small_model_clauses(cls,final_cond,shrink=diagnose.get())
    axioms = im.module.background_theory()
    res = history.satisfy(axioms,gmc,filter_fcs(fcs))
    if res is not None and diagnose.get():
        show_counterexample(ag,post,res)
    return res is None
Beispiel #4
0
def sampleUtil(mod, preclause, fcs, actname):
    '''
	a sample created by using z3 which satsfies preclauses and final condition(fcs) where transtion 
	function is obtained from action corresponding to actname
	'''
    action = mod.actions[actname]
    ag = ivy_art.AnalysisGraph()
    pre = itp.State()
    pre.clauses = preclause
    with itp.EvalContext(check=False):  # don't check safety
        post = ag.execute(
            action, pre, None, actname
        )  # action clauses are added to preclause here (transition function and preclause)
        history = ag.get_history(post)
        gmc = lambda cls, final_cond: itr.small_model_clauses(
            cls, final_cond, shrink=True
        )  #shrink=True gives smallest possible sample
        axioms = mod.background_theory()
        return history.satisfy(axioms, gmc, fcs)
Beispiel #5
0
def checkInitialCond(mod):
    print "\nChecking if Initialization establishes the learned invariants"
    print "\n    Invariants are: "
    for lc in mod.labeled_conjs:
        print "    {}".format(Clauses([lc.formula]))
    print ''
    with itp.EvalContext(check=False):
        ag = ivy_art.AnalysisGraph(initializer=lambda x: None)
        lcs = mod.labeled_conjs
        fcs = [icheck.ConjChecker(c) for c in lcs]
        history = ag.get_history(ag.states[0])
        gmc = lambda cls, final_cond: itr.small_model_clauses(
            cls, final_cond, shrink=True)
        axioms = mod.background_theory()
        model = history.satisfy(axioms, gmc, fcs)
        smpl = Sample(model, '-1')  # this sample has no post state
        if hasattr(smpl, 'interp'):  # smpl is not None
            print "<plearn> + sample interpretation : ", smpl.interp, "\n"  # for detailed information
            smpl.displaySample()  # for displaying the sample
            print "\nInitialization establishes the learned Invariant: FAIL"
        else:
            print "\nInitialization establishes the learned Invariant: PASS"