Beispiel #1
0
 private void CloseVcGen()
 {
     if (vcgen != null)
     {
         try {
             parent.swBoogie.Start();
             vcgen.Close();
         } finally {
             parent.swBoogie.Stop();
         }
         vcgen = null;
     }
 }
Beispiel #2
0
        public static VC.ConditionGeneration InitializeVC(Program prog)
        {
            VC.ConditionGeneration vcgen = null;
            try
            {
                if (CommandLineOptions.Clo.vcVariety == CommandLineOptions.VCVariety.Doomed)
                {
                    throw new Exception("The doomed option is not supported in SymDiff");
                    //vcgen = new VC.DCGen(prog, CommandLineOptions.Clo.SimplifyLogFilePath, CommandLineOptions.Clo.SimplifyLogFileAppend);
                }
                else
                {
                    vcgen = new VC.VCGen(prog, CommandLineOptions.Clo.SimplifyLogFilePath, CommandLineOptions.Clo.SimplifyLogFileAppend, new List <Checker>());
                }
            }
            catch (ProverException)
            {
                Log.Out(Log.Error, "Fatal Error: ProverException: {0}");
                return(null);
            }

            return(vcgen);
        }
Beispiel #3
0
 private void CloseVcGen()
 {
     if (vcgen != null) {
     try {
       parent.swBoogie.Start();
       vcgen.Close();
     } finally {
       parent.swBoogie.Stop();
     }
     vcgen = null;
       }
 }
Beispiel #4
0
        public override VerificationResult Verify(string funcName)
        {
            double start = VccCommandLineHost.GetTime();

              // Match replacement in Boogie names
              string sanitizedFuncName = funcName.Replace('\\', '#');

              bool restartProver = false;
              bool isolateProof = HasIsolateProofAttribute(funcName);

              if (isolateProof) { CloseVcGen(); }

              if (parent.options.AggressivePruning || isolateProof) {
            restartProver = true;
            // this needs to be done before pruning; otherwise call cycles might get hidden
            Termination.checkCallCycles(env, currentDecls);
            var decls = TransUtil.pruneBy(env, funcName, currentDecls);
            var boogieDecls = Translator.translate(funcName, env, () => VccCommandLineHost.StandardPrelude(parent.options), decls);
            if (!env.ShouldContinue) return VerificationResult.UserError;
            currentBoogie = PrepareBoogie(boogieDecls);
            mustRegenerateBoogie = true;
              } else {
            if (mustRegenerateBoogie || currentBoogie == null) {
              var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(parent.options), currentDecls);
              if (!env.ShouldContinue) return VerificationResult.UserError;
              currentBoogie = PrepareBoogie(boogieDecls);
              mustRegenerateBoogie = false;
            }
              }

              Implementation impl = null;
              foreach (Declaration decl in currentBoogie.TopLevelDeclarations) {
            impl = decl as Implementation;
            if (impl != null && impl.Name == sanitizedFuncName) break;
            impl = null;
              }
              if (impl == null) {
            Logger.Instance.Error("cannot find function: {0}", funcName);
            return VerificationResult.UserError;
              }

              if (this.errorMode || !env.ShouldContinue) return VerificationResult.UserError;

              if (impl.SkipVerification) return VerificationResult.Skipped;

              Logger.Instance.LogMethodStart(funcName);

              string logPath = CommandLineOptions.Clo.SimplifyLogFilePath;
              if (logPath != null)
            logPath = logPath.Replace("@VCCFILE@", TestRunner.currentTestcaseName);
              if (logPath != null && logPath.Contains("@VCCFUNC@")) {
            logPath = logPath.Replace("@VCCFUNC@", funcName.Replace("$", "_").Replace("^", "_"));
            CloseVcGen();
              }

              string extraFunctionOptions = null;
              bool isBvLemmaCheck = IsBvLemmaCheck(impl);
              bool skipSmoke = HasSkipSmokeAttr(impl);
              if ((parent.options.RunInBatchMode && (extraFunctionOptions = GetExtraFunctionOptions(impl)) != null) || isBvLemmaCheck || skipSmoke) {
            CloseVcGen();
            extraFunctionOptions = extraFunctionOptions ?? ""; // this prevents parsing errors in case of bv_lemma checks and will also cause the VcGen to be closed later
            VccOptions extraCommandLineOptions = OptionParser.ParseCommandLineArguments(VccCommandLineHost.dummyHostEnvironment, extraFunctionOptions.Split(' ', '\t'), false);
            List<string> effectiveOptions = new List<string>(extraCommandLineOptions.BoogieOptions);
            effectiveOptions.AddRange(extraCommandLineOptions.Z3Options.Select(z3option => "/z3opt:" + z3option));
            effectiveOptions.AddRange(options);
            if (isBvLemmaCheck) {
              effectiveOptions.Add("/proverOpt:OPTIMIZE_FOR_BV=true");
              effectiveOptions.RemoveAll(opt => opt == "/z3opt:CASE_SPLIT");
              effectiveOptions.Add("/z3opt:CASE_SPLIT=1");
            }

            if (skipSmoke) {
              effectiveOptions.RemoveAll(opt => opt == "/smoke");
            }

            if (restartProver) {
              effectiveOptions.Add("/restartProver");
            }

            if (!ReParseBoogieOptions(effectiveOptions, parent.options.RunningFromCommandLine)) {
              Logger.Instance.Error("Error parsing extra options '{0}' for function '{1}'", extraFunctionOptions, impl.Name);
              return VerificationResult.UserError;
            }
            try {
              parent.swBoogie.Start();
              vcgen = new VC.VCGen(currentBoogie, logPath, CommandLineOptions.Clo.SimplifyLogFileAppend);
            } finally {
              parent.swBoogie.Stop();
            }
              } else if (vcgen == null) {
            // run with default options
            ReParseBoogieOptions(options, parent.options.RunningFromCommandLine);
            try {
              parent.swBoogie.Start();
              vcgen = new VC.VCGen(currentBoogie, logPath, CommandLineOptions.Clo.SimplifyLogFileAppend);
            } finally {
              parent.swBoogie.Stop();
            }
              }

              var reporter = new ErrorReporter(parent.options, impl.Proc.Name, impl.Proc.tok, start, VccCommandLineHost.ErrorHandler);

              try {
            parent.swVcOpt.Start();
              } finally {
            parent.swVcOpt.Stop();
              }

              VC.ConditionGeneration.Outcome outcome;
              string extraInfo = null;
              try {
            parent.swVerifyImpl.Start();
            VCGenPlugin plugin = parent.plugin;
            outcome = plugin != null ? plugin.VerifyImpl(env, vcgen, impl, currentBoogie, reporter) : vcgen.VerifyImplementation(impl, currentBoogie, reporter);
              } catch (UnexpectedProverOutputException exc) {
            outcome = VC.ConditionGeneration.Outcome.OutOfMemory;
            extraInfo = "caused an exception \"" + exc.Message + "\"";
              } finally {
            parent.swVerifyImpl.Stop();
              }

              if (extraFunctionOptions != null) {
            CloseVcGen();
              }

              reporter.PrintSummary(outcome, extraInfo);

              modelCount += reporter.modelCount;

              switch (outcome) {
            case VC.ConditionGeneration.Outcome.Correct: return VerificationResult.Succeeded;
            case VC.ConditionGeneration.Outcome.Errors: return VerificationResult.Failed;
            case VC.ConditionGeneration.Outcome.Inconclusive: return VerificationResult.Inconclusive;
            case VC.ConditionGeneration.Outcome.OutOfMemory: return VerificationResult.Crashed;
            case VC.ConditionGeneration.Outcome.TimedOut: return VerificationResult.Crashed;
            default: return VerificationResult.Crashed;
              }
        }
Beispiel #5
0
        public void Run()
        {
            if (WhoopRaceCheckerCommandLineOptions.Get().MeasurePassExecutionTime)
            {
                Console.WriteLine(" |------ [{0} :: {1}]", this.EP1.Name, this.EP2.Name);
                Console.WriteLine(" |  |");
                this.Timer = new ExecutionTimer();
                this.Timer.Start();
            }

            this.AC.EliminateDeadVariables();
            this.AC.Inline();
            if (WhoopRaceCheckerCommandLineOptions.Get().LoopUnrollCount != -1)
            {
                this.AC.Program.UnrollLoops(WhoopRaceCheckerCommandLineOptions.Get().LoopUnrollCount,
                                            WhoopRaceCheckerCommandLineOptions.Get().SoundLoopUnrolling);
            }

            string         checkerName = "check$" + this.EP1.Name + "$" + this.EP2.Name;
            Implementation checker     = this.AC.TopLevelDeclarations.OfType <Implementation>().ToList().
                                         Find(val => val.Name.Equals(checkerName));

            Contract.Assert(checker != null);

            VC.ConditionGeneration vcgen = null;

            try
            {
                vcgen = new VC.VCGen(this.AC.Program, WhoopRaceCheckerCommandLineOptions.Get().SimplifyLogFilePath,
                                     WhoopRaceCheckerCommandLineOptions.Get().SimplifyLogFileAppend, new List <Checker>());
            }
            catch (ProverException e)
            {
                Whoop.IO.Reporter.ErrorWriteLine("Fatal Error: ProverException: {0}", e);
                Environment.Exit((int)Outcome.FatalError);
            }

            int prevAssertionCount = vcgen.CumulativeAssertionCount;

            List <Counterexample> errors;

            DateTime start = new DateTime();

            if (WhoopRaceCheckerCommandLineOptions.Get().Trace)
            {
                start = DateTime.UtcNow;
                if (WhoopRaceCheckerCommandLineOptions.Get().Trace)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Verifying {0} ...", checker.Name.Substring(5));
                }
            }

            VC.VCGen.Outcome vcOutcome;
            try
            {
                vcOutcome = vcgen.VerifyImplementation(checker, out errors);
            }
            catch (VC.VCGenException e)
            {
                Whoop.IO.Reporter.ReportBplError(checker, String.Format("Error BP5010: {0}  Encountered in implementation {1}.",
                                                                        e.Message, checker.Name), true, true);
                errors    = null;
                vcOutcome = VC.VCGen.Outcome.Inconclusive;
            }
            catch (UnexpectedProverOutputException e)
            {
                Whoop.IO.Reporter.AdvisoryWriteLine("Advisory: {0} SKIPPED because of internal error: unexpected prover output: {1}",
                                                    checker.Name, e.Message);
                errors    = null;
                vcOutcome = VC.VCGen.Outcome.Inconclusive;
            }

            string   timeIndication = "";
            DateTime end            = DateTime.UtcNow;
            TimeSpan elapsed        = end - start;

            if (WhoopRaceCheckerCommandLineOptions.Get().Trace)
            {
                int poCount = vcgen.CumulativeAssertionCount - prevAssertionCount;
                timeIndication = string.Format("  [{0:F3} s, {1} proof obligation{2}]  ",
                                               elapsed.TotalSeconds, poCount, poCount == 1 ? "" : "s");
            }

            this.ProcessOutcome(checker, vcOutcome, errors, timeIndication, this.Stats);

            if (vcOutcome == VC.VCGen.Outcome.Errors || WhoopRaceCheckerCommandLineOptions.Get().Trace)
            {
                Console.Out.Flush();
            }

            WhoopRaceCheckerCommandLineOptions.Get().TheProverFactory.Close();
//      cce.NonNull(WhoopRaceCheckerCommandLineOptions.Get().TheProverFactory).Close();
            vcgen.Dispose();

            if (WhoopRaceCheckerCommandLineOptions.Get().MeasurePassExecutionTime)
            {
                this.Timer.Stop();
                Console.WriteLine(" |  |------ [StaticLocksetAnalyser] {0}", this.Timer.Result());
                Console.WriteLine(" |");
            }
        }
Beispiel #6
0
        private void CheckForRaces()
        {
            this.AC.EliminateDeadVariables();
            this.AC.Inline();
            if (ToolCommandLineOptions.Get().LoopUnrollCount != -1)
            {
                this.AC.BoogieProgram.UnrollLoops(ToolCommandLineOptions.Get().LoopUnrollCount,
                                                  ToolCommandLineOptions.Get().SoundLoopUnrolling);
            }

            VC.ConditionGeneration vcgen = null;

            try
            {
                vcgen = new VC.VCGen(this.AC.BoogieProgram, ToolCommandLineOptions.Get().SimplifyLogFilePath,
                                     ToolCommandLineOptions.Get().SimplifyLogFileAppend, new List <Checker>());
            }
            catch (ProverException e)
            {
                Lockpwn.IO.Reporter.ErrorWriteLine("Fatal Error: ProverException: {0}", e);
                Environment.Exit((int)Outcome.FatalError);
            }

            int prevAssertionCount = vcgen.CumulativeAssertionCount;

            List <Counterexample> errors;

            DateTime start = new DateTime();

            if (ToolCommandLineOptions.Get().Trace)
            {
                start = DateTime.UtcNow;
                if (ToolCommandLineOptions.Get().Trace)
                {
                    Output.PrintLine("");
                    Output.PrintLine("Verifying {0} ...", this.AC.EntryPoint.Name.Substring(5));
                }
            }

            GC.Collect();

            VC.VCGen.Outcome vcOutcome;
            try
            {
                vcOutcome = vcgen.VerifyImplementation(this.AC.EntryPoint, out errors);
            }
            catch (VC.VCGenException e)
            {
                Lockpwn.IO.Reporter.ReportBplError(this.AC.EntryPoint, String.Format("Error BP5010: {0}  Encountered in implementation {1}.",
                                                                                     e.Message, this.AC.EntryPoint.Name), true, true);
                errors = null;
                this.AC.GetErrorReporter().Result = ErrorReporter.Outcome.Inconclusive;
                vcOutcome = VC.VCGen.Outcome.Inconclusive;
                GC.Collect();
            }
            catch (UnexpectedProverOutputException e)
            {
                Lockpwn.IO.Reporter.WarningWriteLine("Warning: unexpected prover output: {0}", e.Message);
                errors = null;
                this.AC.GetErrorReporter().Result = ErrorReporter.Outcome.Inconclusive;
                vcOutcome = VC.VCGen.Outcome.Inconclusive;
                GC.Collect();
            }
            catch (OutOfMemoryException)
            {
                Lockpwn.IO.Reporter.WarningWriteLine("Warning: run out of memory during VC verification");
                errors = null;
                this.AC.GetErrorReporter().Result = ErrorReporter.Outcome.OutOfMemory;
                vcOutcome = VC.VCGen.Outcome.OutOfMemory;
                GC.Collect();
            }
            catch (Exception ex)
            {
                Lockpwn.IO.Reporter.WarningWriteLine("Warning: VC verification failed: " + ex.Message);
                errors = null;
                this.AC.GetErrorReporter().Result = ErrorReporter.Outcome.Inconclusive;
                vcOutcome = VC.VCGen.Outcome.Inconclusive;
                GC.Collect();
            }

            string   timeIndication = "";
            DateTime end            = DateTime.UtcNow;
            TimeSpan elapsed        = end - start;

            if (ToolCommandLineOptions.Get().Trace)
            {
                int poCount = vcgen.CumulativeAssertionCount - prevAssertionCount;
                timeIndication = string.Format("  [{0:F3} s, {1} proof obligation{2}]  ",
                                               elapsed.TotalSeconds, poCount, poCount == 1 ? "" : "s");
            }

            this.ProcessOutcome(this.AC.EntryPoint, vcOutcome, errors, timeIndication, this.Stats);

            if (vcOutcome == VC.VCGen.Outcome.Errors || ToolCommandLineOptions.Get().Trace)
            {
                Console.Out.Flush();
            }

            ToolCommandLineOptions.Get().TheProverFactory.Close();
            cce.NonNull(ToolCommandLineOptions.Get().TheProverFactory).Close();
            vcgen.Dispose();

            Lockpwn.IO.Reporter.WriteTrailer(this.Stats);
        }
Beispiel #7
0
        public override VerificationResult Verify(string funcName)
        {
            double start = VccCommandLineHost.GetTime();

            // Match replacement in Boogie names
            string sanitizedFuncName = funcName.Replace('\\', '#');

            bool restartProver = false;
            bool isolateProof  = HasIsolateProofAttribute(funcName);

            if (isolateProof)
            {
                CloseVcGen();
            }

            if (parent.options.AggressivePruning || isolateProof)
            {
                restartProver = true;
                // this needs to be done before pruning; otherwise call cycles might get hidden
                Termination.checkCallCycles(env, currentDecls);
                var decls       = TransUtil.pruneBy(env, funcName, currentDecls);
                var boogieDecls = Translator.translate(funcName, env, () => VccCommandLineHost.StandardPrelude(parent.options), decls);
                if (!env.ShouldContinue)
                {
                    return(VerificationResult.UserError);
                }
                currentBoogie        = PrepareBoogie(boogieDecls);
                mustRegenerateBoogie = true;
            }
            else
            {
                if (mustRegenerateBoogie || currentBoogie == null)
                {
                    var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(parent.options), currentDecls);
                    if (!env.ShouldContinue)
                    {
                        return(VerificationResult.UserError);
                    }
                    currentBoogie        = PrepareBoogie(boogieDecls);
                    mustRegenerateBoogie = false;
                }
            }

            Implementation impl = null;

            foreach (Declaration decl in currentBoogie.TopLevelDeclarations)
            {
                impl = decl as Implementation;
                if (impl != null && impl.Name == sanitizedFuncName)
                {
                    break;
                }
                impl = null;
            }
            if (impl == null)
            {
                Logger.Instance.Error("cannot find function: {0}", funcName);
                return(VerificationResult.UserError);
            }

            if (this.errorMode || !env.ShouldContinue)
            {
                return(VerificationResult.UserError);
            }

            if (impl.SkipVerification)
            {
                return(VerificationResult.Skipped);
            }

            Logger.Instance.LogMethodStart(funcName);

            string logPath = CommandLineOptions.Clo.SimplifyLogFilePath;

            if (logPath != null)
            {
                logPath = logPath.Replace("@VCCFILE@", TestRunner.currentTestcaseName);
            }
            if (logPath != null && logPath.Contains("@VCCFUNC@"))
            {
                logPath = logPath.Replace("@VCCFUNC@", funcName.Replace("$", "_").Replace("^", "_"));
                CloseVcGen();
            }

            string extraFunctionOptions = null;
            bool   isBvLemmaCheck       = IsBvLemmaCheck(impl);
            bool   skipSmoke            = HasSkipSmokeAttr(impl);

            if ((parent.options.RunInBatchMode && (extraFunctionOptions = GetExtraFunctionOptions(impl)) != null) || isBvLemmaCheck || skipSmoke)
            {
                CloseVcGen();
                extraFunctionOptions = extraFunctionOptions ?? ""; // this prevents parsing errors in case of bv_lemma checks and will also cause the VcGen to be closed later
                VccOptions    extraCommandLineOptions = OptionParser.ParseCommandLineArguments(VccCommandLineHost.dummyHostEnvironment, extraFunctionOptions.Split(' ', '\t'), false);
                List <string> effectiveOptions        = new List <string>(extraCommandLineOptions.BoogieOptions);
                effectiveOptions.AddRange(extraCommandLineOptions.Z3Options.Select(z3option => "/z3opt:" + z3option));
                effectiveOptions.AddRange(options);
                if (isBvLemmaCheck)
                {
                    effectiveOptions.Add("/proverOpt:OPTIMIZE_FOR_BV=true");
                    effectiveOptions.RemoveAll(opt => opt == "/z3opt:CASE_SPLIT");
                    effectiveOptions.Add("/z3opt:CASE_SPLIT=1");
                }

                if (skipSmoke)
                {
                    effectiveOptions.RemoveAll(opt => opt == "/smoke");
                }

                if (restartProver)
                {
                    effectiveOptions.Add("/restartProver");
                }

                if (!ReParseBoogieOptions(effectiveOptions, parent.options.RunningFromCommandLine))
                {
                    Logger.Instance.Error("Error parsing extra options '{0}' for function '{1}'", extraFunctionOptions, impl.Name);
                    return(VerificationResult.UserError);
                }
                try {
                    parent.swBoogie.Start();
                    vcgen = new VC.VCGen(currentBoogie, logPath, CommandLineOptions.Clo.SimplifyLogFileAppend);
                } finally {
                    parent.swBoogie.Stop();
                }
            }
            else if (vcgen == null)
            {
                // run with default options
                ReParseBoogieOptions(options, parent.options.RunningFromCommandLine);
                try {
                    parent.swBoogie.Start();
                    vcgen = new VC.VCGen(currentBoogie, logPath, CommandLineOptions.Clo.SimplifyLogFileAppend);
                } finally {
                    parent.swBoogie.Stop();
                }
            }

            var reporter = new ErrorReporter(parent.options, impl.Proc.Name, impl.Proc.tok, start, VccCommandLineHost.ErrorHandler);

            try {
                parent.swVcOpt.Start();
            } finally {
                parent.swVcOpt.Stop();
            }


            VC.ConditionGeneration.Outcome outcome;
            string extraInfo = null;

            try {
                parent.swVerifyImpl.Start();
                VCGenPlugin plugin = parent.plugin;
                outcome = plugin != null?plugin.VerifyImpl(env, vcgen, impl, currentBoogie, reporter) : vcgen.VerifyImplementation(impl, currentBoogie, reporter);
            } catch (UnexpectedProverOutputException exc) {
                outcome   = VC.ConditionGeneration.Outcome.OutOfMemory;
                extraInfo = "caused an exception \"" + exc.Message + "\"";
            } finally {
                parent.swVerifyImpl.Stop();
            }

            if (extraFunctionOptions != null)
            {
                CloseVcGen();
            }

            reporter.PrintSummary(outcome, extraInfo);

            modelCount += reporter.modelCount;

            switch (outcome)
            {
            case VC.ConditionGeneration.Outcome.Correct: return(VerificationResult.Succeeded);

            case VC.ConditionGeneration.Outcome.Errors: return(VerificationResult.Failed);

            case VC.ConditionGeneration.Outcome.Inconclusive: return(VerificationResult.Inconclusive);

            case VC.ConditionGeneration.Outcome.OutOfMemory: return(VerificationResult.Crashed);

            case VC.ConditionGeneration.Outcome.TimedOut: return(VerificationResult.Crashed);

            default: return(VerificationResult.Crashed);
            }
        }
Beispiel #8
0
 public abstract VC.ConditionGeneration.Outcome VerifyImpl(TransHelper.TransEnv env, VC.VCGen vcgen, Implementation impl, Program prog, VerifierCallback reporter);