Ejemplo n.º 1
0
        public static bool checkPath(PersistentCBAProgram pmeta, VarSet trackedVars, out ErrorTrace trace)
        {
            PersistentCBAProgram temp;
            InsertionTrans       temp2;

            return(checkPath(pmeta, trackedVars, true, out temp, out temp2, out trace));
        }
Ejemplo n.º 2
0
        public override bool checkPath(PersistentCBAProgram prog, VarSet trackedVars)
        {
            ConfigManager.beginPathVerification(false);

            // Do variable slicing, inlining and verify
            var abs = new VariableSlicePass(trackedVars);

            prog = abs.run(prog);

            VerificationPass verify = null;

            if (GlobalConfig.useLocalVariableAbstraction)
            {
                verify = new StaticInlineAndVerifyPass(new StaticSettings(-1, 1), false);
            }
            else
            {
                verify = new VerificationPass(false);
            }

            try
            {
                verify.run(prog);
            }
            catch (Exception)
            {
                ConfigManager.endPathVerification();
                throw;
            }

            ConfigManager.endPathVerification();
            return(verify.success);
        }
Ejemplo n.º 3
0
 public virtual void Remove(VarSet second)
 {
     foreach (var x in second.values)
     {
         values.Remove(x);
     }
 }
Ejemplo n.º 4
0
        public static VarSet GetAllVars(Program p)
        {
            //List<GlobalVariable> globalDecls = BoogieUtil.GetGlobalVariables(p);
            var procedures      = BoogieUtil.GetProcedures(p);
            var implementations = BoogieUtil.GetImplementations(p);
            var allVars         = new VarSet();

            foreach (var proc in procedures)
            {
                var uses = new GlobalVarsUsed();
                uses.VisitRequiresSeq(proc.Requires);
                uses.VisitEnsuresSeq(proc.Ensures);
                // skip visiting modifies clause
                allVars.Add(new VarSet(uses.globalsUsed, proc.Name));
            }

            foreach (var impl in implementations)
            {
                var uses = new GlobalVarsUsed();
                uses.VisitBlockList(impl.Blocks);
                allVars.Add(new VarSet(uses.globalsUsed, impl.Name));
            }

            //globalDecls.Iterate(x => procedures.Iterate(y => allVars.Add(x.Name, y.Name)));
            //globalDecls.Iterate(x => implementations.Iterate(y => allVars.Add(x.Name, y.Name)));
            return(allVars);
        }
Ejemplo n.º 5
0
 public virtual void Add(VarSet second)
 {
     foreach (var x in second.values)
     {
         values.Add(x);
     }
 }
Ejemplo n.º 6
0
 public PersistentCBAProgram(Program p, string main, int bound) : base(p)
 {
     mainProcName = main;
     contextBound = bound;
     mode         = ConcurrencyMode.AnyInterleaving;
     // allVarsLazy = null;
     allVarsLazy = VarSet.GetAllVars(p);
 }
Ejemplo n.º 7
0
        public static bool checkPath(PersistentCBAProgram pmeta, VarSet trackedVars)
        {
            PersistentCBAProgram temp;
            ErrorTrace           temp2;
            InsertionTrans       temp3;

            return(checkPath(pmeta, trackedVars, false, out temp, out temp3, out temp2));
        }
Ejemplo n.º 8
0
        // Partition a set into two equal halves
        // TODO: Randomized partitioning
        public virtual void PartitionSet(out VarSet part1, out VarSet part2)
        {
            HashSet <Duple <string, string> > part1set;
            HashSet <Duple <string, string> > part2set;

            values.Partition(out part1set, out part2set);
            part1 = new VarSet(part1set);
            part2 = new VarSet(part2set);
        }
Ejemplo n.º 9
0
 public PersistentCBAProgram(Program p, string main, int bound, ConcurrencyMode mode)
     : base(p)
 {
     mainProcName = main;
     contextBound = bound;
     this.mode    = mode;
     // allVarsLazy = null;
     allVarsLazy = VarSet.GetAllVars(p);
 }
Ejemplo n.º 10
0
 public VariableSlicing(VarSet rmv, ModifyTrans t, Implementation impl)
 {
     trackedVars          = new VarSet(rmv);
     trackedVarsVariables = new HashSet <string>(trackedVars.Variables);
     tinfo                  = t;
     onlyGlobals            = false;
     currImplementation     = impl;
     visitedImplementations = new HashSet <string>();
     slicedRequires         = new HashSet <string>();
     slicedEnsures          = new HashSet <string>();
 }
Ejemplo n.º 11
0
        // Returns (p.allVars \intersect (vars x allProcs)
        public static VarSet ToVarSet(HashSet <string> vars, Program p)
        {
            var allVars = GetAllVars(p);
            var ret     = new VarSet();

            foreach (var pair in allVars.values)
            {
                if (vars.Contains(pair.fst))
                {
                    ret.values.Add(pair);
                }
            }
            return(ret);
        }
Ejemplo n.º 12
0
 public void ProjectOnVariables(HashSet <string> vars, out VarSet projection, out VarSet complement)
 {
     projection = new VarSet();
     complement = new VarSet();
     foreach (Duple <string, string> x in values)
     {
         if (vars.Contains(x.fst))
         {
             projection.Add(x);
         }
         else
         {
             complement.Add(x);
         }
     }
 }
Ejemplo n.º 13
0
 public static bool checkPath(PersistentCBAProgram prog, VarSet trackedVars, bool returnTrace,
                              out PersistentCBAProgram pout, out InsertionTrans tinfo, out ErrorTrace cex)
 {
     ConfigManager.beginPathVerification(returnTrace);
     try
     {
         var ret = VerifyProgram(ref prog, trackedVars, returnTrace, out pout, out tinfo, out cex);
         ConfigManager.endPathVerification();
         return(ret);
     }
     catch (Exception)
     {
         ConfigManager.endPathVerification();
         throw;
     }
 }
Ejemplo n.º 14
0
 public void ProjectOnProcedures(HashSet <string> procs, out VarSet projection, out VarSet complement)
 {
     projection = new VarSet();
     complement = new VarSet();
     foreach (Duple <string, string> x in values)
     {
         if (procs.Contains(x.snd))
         {
             projection.Add(x);
         }
         else
         {
             complement.Add(x);
         }
     }
 }
Ejemplo n.º 15
0
        public Program run(Program node)
        {
            globalsRead = new HashSet <string>();

            // Typecheck -- needed for variable abstraction
            if (node.Typecheck() != 0)
            {
                BoogieUtil.PrintProgram(node, "error.bpl");
                throw new InternalError("Type errors");
            }

            // Go through all procedures and implementations (slice locals)
            var TopLevelDeclarations = node.TopLevelDeclarations.ToList();

            for (int i = 0; i < TopLevelDeclarations.Count; i++)
            {
                if (TopLevelDeclarations[i] is Implementation)
                {
                    TopLevelDeclarations[i] = processImplementation(TopLevelDeclarations[i] as Implementation);
                }
                else if (TopLevelDeclarations[i] is Procedure)
                {
                    processProcedure(TopLevelDeclarations[i] as Procedure);
                }
            }
            node.TopLevelDeclarations = TopLevelDeclarations;

            if (onlyLocals)
            {
                return(node);
            }


            sliceGlobals = new VariableSlicing(VarSet.ToVarSet(globalsRead, node), gtinfo);
            node         = sliceGlobals.VisitProgram(node);
            BoogieUtil.DoModSetAnalysis(node);

            return(node);
        }
Ejemplo n.º 16
0
 public VarSet(VarSet t)
 {
     values = new HashSet <Duple <string, string> >(t.values);
 }
Ejemplo n.º 17
0
 public virtual bool Contains(VarSet second)
 {
     return(values.IsSupersetOf(second.values));
 }
Ejemplo n.º 18
0
 public virtual bool Intersects(VarSet varset)
 {
     return(values.Intersect(varset.values).Any());
 }
Ejemplo n.º 19
0
 public virtual VarSet Difference(VarSet second)
 {
     return(new VarSet(HashSetExtras <Duple <string, string> > .Difference(values, second.values)));
 }
Ejemplo n.º 20
0
 public override bool checkPath(PersistentCBAProgram prog, VarSet trackedVars)
 {
     return(CBADriver.checkPath(prog, trackedVars));
 }
Ejemplo n.º 21
0
 public virtual VarSet Intersection(VarSet second)
 {
     return(new VarSet(HashSetExtras <Duple <string, string> > .Intersection(values, second.values)));
 }
Ejemplo n.º 22
0
        // Verify prog while tracking only variables in trackedVars.
        // Returns true if no error is found.
        // Returns false if error is found. Returns counterexample via pout
        // If returnTrace is set to false, then pout is always null
        //     (no counterexample generation is attempted)
        // cex: the error trace in prog (if there is one)
        // tinfo: the transformation carried out in going from prog to pout
        // Call this method via: checkProgram or checkPath
        private static bool VerifyProgram(ref PersistentCBAProgram prog, VarSet trackedVars, bool returnTrace,
                                          out PersistentCBAProgram pout, out InsertionTrans tinfo, out ErrorTrace cex)
        {
            PersistentCBAProgram curr = prog;

            pout  = null;
            cex   = null;
            tinfo = null;

            //////
            // These are the compilation phases
            //////

            VariableSlicePass        cp1 = new VariableSlicePass(trackedVars);
            StormInstrumentationPass cp2 = null;
            var recordK = new HashSet <string>();

            if (!GlobalConfig.isSingleThreaded)
            {
                cp2 = new StormInstrumentationPass();
            }

            StaticInliningAndUnrollingPass cp3 = null;

            if (GlobalConfig.staticInlining > 0)
            {
                cp3 = new StaticInliningAndUnrollingPass(new StaticSettings(CommandLineOptions.Clo.RecursionBound, CommandLineOptions.Clo.RecursionBound));
            }

            ContractInfer ciPass = null;

            // Run the source transformations
            curr = cp1.run(curr);
            if (cp2 != null)
            {
                curr = cp2.run(curr);
            }
            if (cp3 != null)
            {
                curr = cp3.run(curr);
            }

            // infer contracts
            if (GlobalConfig.InferPass != null)
            {
                ciPass = new ContractInfer(GlobalConfig.InferPass);
                ciPass.ExtractLoops = false;
                curr = ciPass.run(curr);
                Console.WriteLine("Houdini took {0} seconds", ciPass.lastRun.TotalSeconds.ToString("F2"));
                GlobalConfig.InferPass = null;

                // add summaries to the original program
                prog = ciPass.addSummaries(prog);
            }

            // record k and tid
            if (cp2 != null)
            {
                recordK.Add(cp2.varKName); recordK.Add(cp2.tidVarName);
            }

            if (GlobalConfig.varsToRecord.Count != 0)
            {
                recordK.UnionWith(GlobalConfig.varsToRecord);
                recordK.IntersectWith(trackedVars.Variables);
            }

            // Now verify
            VerificationPass cp4 = new VerificationPass(true, recordK);

            curr = cp4.run(curr);

            reachedBound = cp4.reachedBound;

            if (cp4.success)
            {
                // Program correct.
                return(true);
            }
            else if (!returnTrace)
            {
                return(false);
            }
            else
            {
                // Concretize the trace and see if its a real bug

                // Concretization: map back the trace to the original program
                var trace4 = cp4.trace;
                //PrintProgramPath.print(cp4.input as PersistentCBAProgram, trace4, "temp4");

                if (ciPass != null)
                {
                    trace4 = ciPass.mapBackTrace(trace4);
                }
                var trace3 = trace4;


                if (cp3 != null)
                {
                    trace3 = cp3.mapBackTrace(trace4);
                }
                //PrintProgramPath.print(cp3.input as PersistentCBAProgram, trace3, "temp3");

                var trace2 = trace3;
                if (cp2 != null)
                {
                    trace2 = cp2.mapBackTrace(trace3);
                }

                var trace1 = cp1.mapBackTrace(trace2);
                //PrintProgramPath.print(cp1.input as PersistentCBAProgram, trace1, "temp1");

                cex = trace1;

                // Restrict the program to the trace
                tinfo = new InsertionTrans();
                var traceProgCons = new RestrictToTrace(cp1.input.getProgram(), tinfo);
                ErrorTrace.fillInContextSwitchInfo(trace1);
                traceProgCons.addTrace(trace1);

                pout =
                    new PersistentCBAProgram(traceProgCons.getProgram(),
                                             traceProgCons.getFirstNameInstance(cp1.getInput().mainProcName),
                                             cp1.getInput().contextBound,
                                             ConcurrencyMode.FixedContext);

                //pout.writeToFile("pout.bpl");
                return(false);
            }
        }
Ejemplo n.º 23
0
 public VariableSlicePass(VarSet v)
 {
     tinfo    = new ModifyTrans();
     vslice   = new VariableSlicing(v, tinfo);
     passName = "Variable Slicing";
 }