Beispiel #1
0
        /// <summary>
        /// Gets the errors and associated metadata after verifying the program.
        /// </summary>
        /// <returns>The metadata of the errors.</returns>
        public IEnumerable <RepairableError> GetErrors()
        {
            List <Error> errors = new List <Error>();

            VCGen gen = new VCGen(program, CommandLineOptions.Clo.SimplifyLogFilePath, CommandLineOptions.Clo.SimplifyLogFileAppend, new List <Checker>());

            foreach (Declaration declaration in program.TopLevelDeclarations)
            {
                if (declaration is Implementation)
                {
                    Implementation        implementation = declaration as Implementation;
                    List <Counterexample> examples;

                    ConditionGeneration.Outcome outcome = gen.VerifyImplementation(implementation, out examples);
                    if (outcome == ConditionGeneration.Outcome.Errors)
                    {
                        foreach (Counterexample example in examples)
                        {
                            errors.AddRange(GenerateErrors(example, implementation));
                        }
                    }
                }
            }

            gen.Close();

            // there are no repairable errors that have a variable assigned to them
            if (!errors.Any(x => x is RepairableError && (x as RepairableError).Barriers.Any()))
            {
                if (errors.Any(x => x.CounterExample is AssertCounterexample))
                {
                    throw new AssertionException("Assertions do not hold!");
                }
                if (errors.Any(x => !(x is RepairableError)))
                {
                    throw new NonBarrierException("The program cannot be repaired since it has errors besides race and divergence errors!");
                }
                if (errors.Any(x => x is RepairableError))
                {
                    throw new RepairException("Encountered a counterexample without any barrier assignments!");
                }
            }

            return(errors.Where(x => x is RepairableError && (x as RepairableError).Barriers.Any())
                   .Select(x => x as RepairableError).ToList());
        }
        private static ResultCounter VerifyProgram(Program program)
        {
            var counters = new ResultCounter();

            ConditionGeneration vcgen = null;

            try {
                vcgen = new VCGen(program, CommandLineOptions.Clo.SimplifyLogFilePath, CommandLineOptions.Clo.SimplifyLogFileAppend, new List <Checker>());
            }
            catch (ProverException e) {
                GVUtil.IO.ErrorWriteLine("Fatal Error: ProverException: {0}", e);
                return(ResultCounter.GetNewCounterWithInternalError());
            }

            // operate on a stable copy, in case it gets updated while we're running
            var decls = program.TopLevelDeclarations.ToArray();

            foreach (Declaration decl in decls)
            {
                Contract.Assert(decl != null);

                int prevAssertionCount = vcgen.CumulativeAssertionCount;

                Implementation impl = decl as Implementation;
                if (impl != null && CommandLineOptions.Clo.UserWantsToCheckRoutine(cce.NonNull(impl.Name)) && !impl.SkipVerification)
                {
                    List <Counterexample /*!*/> /*?*/ errors;

                    DateTime start = new DateTime(); // to please compiler's definite assignment rules
                    if (CommandLineOptions.Clo.Trace)
                    {
                        start = DateTime.UtcNow;
                        if (CommandLineOptions.Clo.Trace)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Verifying {0} ...", impl.Name);
                        }
                    }

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

                    string   timeIndication = "";
                    DateTime end            = DateTime.UtcNow;
                    TimeSpan elapsed        = end - start;
                    if (CommandLineOptions.Clo.Trace)
                    {
                        int poCount = vcgen.CumulativeAssertionCount - prevAssertionCount;
                        timeIndication = string.Format("  [{0:F3} s, {1} proof obligation{2}]  ", elapsed.TotalSeconds, poCount, poCount == 1 ? "" : "s");
                    }
                    KernelAnalyser.ProcessOutcome(program, impl.Name, outcome, errors, timeIndication, ref counters);

                    if (outcome == VCGen.Outcome.Errors || CommandLineOptions.Clo.Trace)
                    {
                        Console.Out.Flush();
                    }
                }
            }

            vcgen.Close();
            cce.NonNull(CommandLineOptions.Clo.TheProverFactory).Close();

            GVUtil.IO.WriteTrailer(counters);
            return(counters);
        }