示例#1
0
    public override Counterexample extractLoopTrace(Counterexample cex, string mainProcName, Program program,
      Dictionary<string, Dictionary<string, Block>> extractLoopMappingInfo)
    {
      // Construct the set of inlined procs in the original program
      var inlinedProcs = new HashSet<string>();
      foreach (var decl in program.TopLevelDeclarations)
      {
        // Implementations
        if (decl is Implementation)
        {
          var impl = decl as Implementation;
          if (!(impl.Proc is LoopProcedure))
          {
            inlinedProcs.Add(impl.Name);
          }
        }

        // And recording procedures
        if (decl is Procedure)
        {
          var proc = decl as Procedure;
          if (proc.Name.StartsWith(recordProcName))
          {
            Debug.Assert(!(decl is LoopProcedure));
            inlinedProcs.Add(proc.Name);
          }
        }
      }

      return extractLoopTraceRec(
        new CalleeCounterexampleInfo(cex, new List<object>()),
        mainProcName, inlinedProcs, extractLoopMappingInfo).counterexample;
    }
示例#2
0
 public async Task NotifyCounterexampleAsync(Counterexample counterexample)
 {
     if (_predicate(counterexample))
     {
         await _innerNotifier.NotifyCounterexampleAsync(counterexample);
     }
 }
示例#3
0
        private void DisplayParameterValues(Counterexample error)
        {
            if (impl.InParams.Count() == 0)
            {
                return;
            }

            string funName = QKeyValue.FindStringAttribute(impl.Attributes, "source_name");

            Debug.Assert(funName != null);

            Console.Error.WriteLine("Bitwise values of parameters of '" + funName + "':");
            PopulateModelWithStatesIfNecessary(error);

            foreach (var p in impl.InParams)
            {
                int    id;
                string stripped = CleanOriginalProgramVariable(p.Name, out id);
                Console.Error.Write("  " + stripped + " = ");

                var VariableName = p.Name;

                Console.Error.Write(ExtractVariableValueFromModel(VariableName, error.Model));
                Console.Error.WriteLine((id == 1 || id == 2) ? " (" + ThreadDetails(error.Model, id, false) + ")" : "");
            }
            Console.Error.WriteLine();
        }
示例#4
0
        private static IEnumerable <string> BuildLines(
            Counterexample <object?> counterexample,
            int iterations,
            int shrinks,
            Func <string, string>?formatReproduction)
        {
            const string LineBreak = "";

            yield return(FalsifiedAfterLine(iterations, shrinks));

            yield return(ReproductionLine(counterexample, formatReproduction));

            yield return(CounterexampleValueLine(counterexample));

            yield return(LineBreak);

            if (counterexample.Exception == null)
            {
                yield return("Property function returned false");
            }
            else
            {
                yield return(ExceptionLine(counterexample.Exception));
            }
        }
示例#5
0
        public int ReportCounterexample(Counterexample error)
        {
            Contract.Requires(error != null);
            int errors = 0;

            if (error is AssertCounterexample)
            {
                AssertCounterexample cex = error as AssertCounterexample;

                if (QKeyValue.FindBoolAttribute(cex.FailingAssert.Attributes, "race_checking"))
                {
                    errors += this.ReportRace(cex);
                }
                else
                {
                    if (ToolCommandLineOptions.Get().VerboseMode)
                    {
                        Output.PrintLine("..... Error: AssertCounterexample");
                    }
                    errors++;
                }
            }

            if (errors > 0)
            {
                this.FoundErrors = true;
            }

            return(errors);
        }
        private static int RecBound(string recFunc, Counterexample trace, string traceName)
        {
            var ret = 0;

            if (trace == null)
            {
                return(ret);
            }
            if (recFunc == traceName)
            {
                ret++;
            }

            for (int numBlock = 0; numBlock < trace.Trace.Count; numBlock++)
            {
                Block b = trace.Trace[numBlock];
                for (int numInstr = 0; numInstr < b.Cmds.Count; numInstr++)
                {
                    Cmd c   = b.Cmds[numInstr];
                    var loc = new TraceLocation(numBlock, numInstr);
                    if (trace.calleeCounterexamples.ContainsKey(loc))
                    {
                        ret +=
                            RecBound(recFunc, trace.calleeCounterexamples[loc].counterexample,
                                     (c as CallCmd).Proc.Name);
                    }
                }
            }
            return(ret);
        }
示例#7
0
        public override async Task NotifyCounterexampleAsync(Counterexample counterexample)
        {
            var formatted = Formatter.Format(counterexample);
            var path      = _pathGenerator(counterexample);

            await File.WriteAllTextAsync(path, formatted, Encoding.UTF8);
        }
示例#8
0
 private static void PopulateModelWithStatesIfNecessary(Counterexample Cex)
 {
     if (!Cex.ModelHasStatesAlready)
     {
         Cex.PopulateModelWithStates();
         Cex.ModelHasStatesAlready = true;
     }
 }
示例#9
0
 private void PopulateModelWithStatesIfNecessary(Counterexample cex)
 {
     if (!cex.ModelHasStatesAlready)
     {
         cex.PopulateModelWithStates();
         cex.ModelHasStatesAlready = true;
     }
 }
示例#10
0
        //private readonly Dictionary<IToken, List<ErrorCode>> reportedVerificationErrors = new Dictionary<IToken, List<ErrorCode>>();
        //private readonly List<string> errors = new List<string>();

        public void ReportCounterexample(Counterexample ce, string message)
        {
            if (message != null)
            {
                message = " (" + message + ")";
            }
            else
            {
                message = "";
            }

            try {
                ReturnCounterexample /*?*/ rce = ce as ReturnCounterexample;
                if (rce != null)
                {
                    IToken tok = rce.FailingReturn.tok;
                    for (int i = rce.Trace.Length - 1; i >= 0; i--)
                    {
                        foreach (Cmd c in rce.Trace[i].Cmds)
                        {
                            AssertCmd assrt = c as AssertCmd;
                            if (assrt != null)
                            {
                                NAryExpr nary = assrt.Expr as NAryExpr;
                                if (nary != null)
                                {
                                    FunctionCall fcall = nary.Fun as FunctionCall;
                                    if (fcall != null && fcall.FunctionName == "$position_marker")
                                    {
                                        tok = assrt.tok;
                                    }
                                }
                            }
                        }
                    }
                    ReportOutcomePostconditionFailed(rce.FailingEnsures.tok, tok, message);
                }
                AssertCounterexample /*?*/ ace = ce as AssertCounterexample;
                if (ace != null)
                {
                    ReportOutcomeAssertFailed(ace.FailingAssert.tok,
                                              (ace.FailingAssert is LoopInvMaintainedAssertCmd ? "Loop body invariant" :
                                               ace.FailingAssert is LoopInitAssertCmd ? "Loop entry invariant" : "Assertion"),
                                              message
                                              );
                }
                CallCounterexample /*?*/ cce = ce as CallCounterexample;
                if (cce != null)
                {
                    ReportOutcomePreconditionFailed(cce.FailingCall.tok, cce.FailingRequires, message);
                }
            } finally {
                if (commandLineOptions != null && commandLineOptions.PrintCEVModel)
                {
                    ce.PrintModel();
                }
            }
        }
示例#11
0
        public override Task NotifyCounterexampleAsync(Counterexample counterexample)
        {
            var formatted = Formatter.Format(counterexample);

            Console.WriteLine($"Counter-example for {counterexample.TestMethod.Name}:");
            Console.WriteLine(formatted);

            return(Task.CompletedTask);
        }
示例#12
0
        private static string GetStateName(QKeyValue Attributes, Counterexample Cex)
        {
            Contract.Requires(QKeyValue.FindStringAttribute(Attributes, "check_id") != null);
            string CheckId = QKeyValue.FindStringAttribute(Attributes, "check_id");

            return(QKeyValue.FindStringAttribute(
                       (Cex.Trace.Last().Cmds.OfType <AssumeCmd>().Where(
                            Item => QKeyValue.FindStringAttribute(Item.Attributes, "check_id") == CheckId).ToList()[0]
                       ).Attributes, "captureState"));
        }
示例#13
0
 public PropertyFailedException(
     Counterexample <object?> counterexample,
     int iterations,
     int shrinks,
     Func <string, string>?formatReproduction,
     Func <string, string>?formatMessage)
     : base(FormatMessage(formatMessage, BuildMessage(counterexample, iterations, shrinks, formatReproduction)))
 {
     _counterexample = counterexample;
 }
示例#14
0
        private static Counterexample <object?> BoxCounterexample <T>(Counterexample <T> counterexample)
        {
            var value = (object)counterexample.Value !;

            return(new Counterexample <object?>(
                       counterexample.Id,
                       value,
                       counterexample.Distance,
                       counterexample.ReplayParameters,
                       counterexample.ReplayPath,
                       counterexample.Replay,
                       counterexample.Exception,
                       counterexample.PresentationalValue));
        }
示例#15
0
        private void DisplayLoopAbstractions(Counterexample error)
        {
            PopulateModelWithStatesIfNecessary(error);
            Program OriginalProgram = GetOriginalProgram();
            var     CFG             = OriginalProgram.ProcessLoops(GetOriginalImplementation(OriginalProgram));

            for (int i = 0; i < error.Trace.Count(); i++)
            {
                MaybeDisplayLoopHeadState(error.Trace[i], CFG, error.Model, OriginalProgram);
                if (i < error.Trace.Count() - 1)
                {
                    MaybeDisplayLoopEntryState(error.Trace[i], error.Trace[i + 1], CFG, error.Model, OriginalProgram);
                }
                MaybeDisplayLoopBackEdgeState(error.Trace[i], CFG, error.Model, OriginalProgram);
            }
        }
示例#16
0
        public void Basic()
        {
            var arguments = new[]
            {
                new Argument("number", 4),
                new Argument("string", "hello"),
            };
            var counterexample = new Counterexample(Mock.Of <MethodInfo>(), arguments);

            var formatted = new JsonFormatter().Format(counterexample);

            var expected = @"{
  ""number"": 4,
  ""string"": ""hello""
}";

            Assert.That.AreEqualIgnoreNewlineStyle(expected, formatted);
        }
示例#17
0
        public int ReportCounterexample(Counterexample error)
        {
            Contract.Requires(error != null);
            int errors = 0;

            if (error is AssertCounterexample)
            {
                AssertCounterexample cex = error as AssertCounterexample;

                if (QKeyValue.FindBoolAttribute(cex.FailingAssert.Attributes, "race_checking"))
                {
                    errors += this.ReportRace(cex);
                }
                else
                {
                    Console.WriteLine("Error: AssertCounterexample");
                    errors++;
                }
            }
            else if (error is CallCounterexample)
            {
                CallCounterexample cex = error as CallCounterexample;

                Console.WriteLine(cex.FailingRequires.Condition);
                Console.WriteLine(cex.FailingRequires.Line);
                Console.WriteLine("Error: CallCounterexample");
                this.ReportRequiresFailure(cex);
                errors++;
            }
            else if (error is ReturnCounterexample)
            {
                Console.WriteLine((error as ReturnCounterexample).FailingEnsures.Condition);
                Console.WriteLine((error as ReturnCounterexample).FailingEnsures.Line);
                Console.WriteLine("Error: ReturnCounterexample");
                errors++;
            }

            if (errors > 0)
            {
                this.FoundErrors = true;
            }

            return(errors);
        }
示例#18
0
 public static string MakeHTMLForExample(Counterexample aCounterexample)
 {
     if (aCounterexample == null)
     {
         return("<p>This proposition is self-contradictory; there are no examples.</p>");
     }
     else if (aCounterexample is KindOfWorld)
     {
         return("<div class=\"counterexample\"><h3>Example</h3><p>This is a kind of world in which the statement is true.</p>"
                + MakeHTML(aCounterexample as KindOfWorld, @"black") + "</div>");
     }
     else if (aCounterexample is ModalCounterexample)
     {
         return(MakeHTMLForExample(aCounterexample as ModalCounterexample));
     }
     else
     {
         throw new EngineException("Unhandled subclass of Counterexample encountered in MakeHTML: {0}", aCounterexample.GetType());
     }
 }
示例#19
0
        private static void printLabels(Counterexample cex, TokenTextWriter ttw, int indent)
        {
            for (int numBlock = 0; numBlock < cex.Trace.Count; numBlock++)
            {
                Block b = cex.Trace[numBlock];

                printIndent(ttw, indent);
                ttw.WriteLine(b.Label);

                for (int numInstr = 0; numInstr < b.Cmds.Count; numInstr++)
                {
                    Cmd c   = b.Cmds[numInstr];
                    var loc = new TraceLocation(numBlock, numInstr);
                    if (cex.calleeCounterexamples.ContainsKey(loc))
                    {
                        printIndent(ttw, indent); ttw.WriteLine("call to {0}:", (c as CallCmd).Proc.Name);
                        printLabels(cex.calleeCounterexamples[loc].counterexample, ttw, indent + 1);
                        printIndent(ttw, indent); ttw.WriteLine("return from {0}.", (c as CallCmd).Proc.Name);
                        printIndent(ttw, indent); ttw.WriteLine(b.Label);
                    }
                }
            }
        }
示例#20
0
        /// <summary>
        /// Generates the errors from the counter example.
        /// </summary>
        /// <param name="example">The counter example.</param>
        /// <param name="implementation">The implementation.</param>
        /// <returns>The error.</returns>
        private IEnumerable <Error> GenerateErrors(Counterexample example, Implementation implementation)
        {
            List <Error> errors = new List <Error>();

            if (example is CallCounterexample)
            {
                CallCounterexample callCounterexample = example as CallCounterexample;
                if (QKeyValue.FindBoolAttribute(callCounterexample.FailingRequires.Attributes, "barrier_divergence"))
                {
                    DivergenceError divergence = new DivergenceError(example, implementation);
                    ErrorReporter   reporter   = new ErrorReporter(program, implementation.Name);

                    reporter.PopulateDivergenceInformation(callCounterexample, divergence);
                    IdentifyVariables(divergence);

                    errors.Add(divergence);
                    return(errors);
                }
                else if (QKeyValue.FindBoolAttribute(callCounterexample.FailingRequires.Attributes, "race"))
                {
                    RaceError     template = new RaceError(example, implementation);
                    ErrorReporter reporter = new ErrorReporter(program, implementation.Name);

                    IEnumerable <RaceError> races = reporter.GetRaceInformation(callCounterexample, template);
                    foreach (RaceError race in races)
                    {
                        IdentifyVariables(race);
                    }

                    errors.AddRange(races);
                    return(errors);
                }
            }

            errors.Add(new Error(example, implementation));
            return(errors);
        }
示例#21
0
        //private readonly Dictionary<IToken, List<ErrorCode>> reportedVerificationErrors = new Dictionary<IToken, List<ErrorCode>>();
        //private readonly List<string> errors = new List<string>();
        public void ReportCounterexample(Counterexample ce, string message)
        {
            if (message != null) message = " (" + message + ")";
              else message = "";

              try {
            ReturnCounterexample/*?*/ rce = ce as ReturnCounterexample;
            if (rce != null) {
              IToken tok = rce.FailingReturn.tok;
              for (int i = rce.Trace.Length - 1; i >= 0; i--) {
            foreach (Cmd c in rce.Trace[i].Cmds) {
              AssertCmd assrt = c as AssertCmd;
              if (assrt != null) {
                NAryExpr nary = assrt.Expr as NAryExpr;
                if (nary != null) {
                  FunctionCall fcall = nary.Fun as FunctionCall;
                  if (fcall != null && fcall.FunctionName == "$position_marker") {
                    tok = assrt.tok;
                  }
                }
              }
            }
              }
              ReportOutcomePostconditionFailed(rce.FailingEnsures.tok, tok, message);
            }
            AssertCounterexample/*?*/ ace = ce as AssertCounterexample;
            if (ace != null) {
              ReportOutcomeAssertFailed(ace.FailingAssert.tok,
            (ace.FailingAssert is LoopInvMaintainedAssertCmd ? "Loop body invariant" :
               ace.FailingAssert is LoopInitAssertCmd ? "Loop entry invariant" : "Assertion"),
               message
            );
            }
            CallCounterexample/*?*/ cce = ce as CallCounterexample;
            if (cce != null)
              ReportOutcomePreconditionFailed(cce.FailingCall.tok, cce.FailingRequires, message);
              } finally {
            if (commandLineOptions != null && commandLineOptions.PrintCEVModel) {
              ce.PrintModel();
            }
              }
        }
示例#22
0
 public BoogieErrorTrace(Counterexample c, Implementation m, Program p)
 {
     cex  = c;
     impl = m;
     prog = p;
 }
示例#23
0
        // Note: this does not reconstruct the failing assert in trace
        public static void ReconstructImperativeTrace(Counterexample trace, string currProc, Dictionary <string, Implementation> origProg)
        {
            if (trace == null)
            {
                return;
            }

            var originalBlocks = BoogieUtil.labelBlockMapping(origProg[currProc]);

            var newBlocks       = new List <Block>();
            var newCalleeTraces = new Dictionary <TraceLocation, CalleeCounterexampleInfo>();

            for (int numBlock = 0; numBlock < trace.Trace.Count; numBlock++)
            {
                Block b = trace.Trace[numBlock];

                Block ib;
                originalBlocks.TryGetValue(b.Label, out ib);
                if (ib == null)
                {
                    // Such blocks correspond to "itermediate" blocks inserted
                    // by Boogie. We can ignore them. (But note that we should
                    // still check that the counterexample is a valid path in impl
                    // to guard against vagaries of Boogie.)

                    //Log.Out(Log.Normal, "Could not find block " + b.Label);
                    //b.Emit(new TokenTextWriter(Console.Out), 0);
                    for (int numInstr = 0; numInstr < b.Cmds.Count; numInstr++)
                    {
                        if (trace.calleeCounterexamples.ContainsKey(new TraceLocation(numBlock, numInstr)))
                        {
                            throw new InternalError("BoogieVerify: An intermediate block has a procedure call");
                        }
                    }
                }
                else
                {
                    // We have a corresponding block. The number of Commands in b and ib won't match. We
                    // simply use all of the Cmds of ib -- and match the calls manually
                    // TODO: Fix this! It doesn't work when the failing assert is not the last statement
                    // of the block
                    newBlocks.Add(ib);
                    var calleeTraces = new List <Duple <string, CalleeCounterexampleInfo> >();
                    for (int numInstr = 0; numInstr < b.Cmds.Count; numInstr++)
                    {
                        var loc = new TraceLocation(numBlock, numInstr);
                        if (trace.calleeCounterexamples.ContainsKey(loc))
                        {
                            Cmd c           = b.Cmds[numInstr];
                            var calleeName  = trace.getCalledProcName(c);
                            var calleeTrace = trace.calleeCounterexamples[loc].counterexample;
                            ReconstructImperativeTrace(calleeTrace, calleeName, origProg);
                            calleeTraces.Add(
                                new Duple <string, CalleeCounterexampleInfo>(
                                    calleeName,
                                    new CalleeCounterexampleInfo(calleeTrace,
                                                                 trace.calleeCounterexamples[loc].args)
                                    ));
                        }
                    }

                    // Check consistency and map calleeTraces to the actual call instructions
                    var currCount = 0;
                    for (int numInstr = 0; numInstr < ib.Cmds.Count; numInstr++)
                    {
                        Cmd c = ib.Cmds[numInstr];

                        if (!(c is CallCmd))
                        {
                            continue;
                        }

                        var cc = c as CallCmd;

                        // No more calls left to process
                        if (calleeTraces.Count <= currCount)
                        {
                            break;
                        }

                        if (cc.Proc.Name != calleeTraces[currCount].fst)
                        {
                            continue;
                        }

                        // Check if this proc has an implementation
                        //if (!origProg.ContainsKey(cc.Proc.Name))
                        //    continue;

                        // Check if the proc is inlined
                        //if (QKeyValue.FindExprAttribute(cc.Proc.Attributes, "inline") == null)
                        //    continue;

                        // Some thing wrong about the interprocedural trace returned by Boogie if the
                        // following don't match
                        // TODO: Fix when the failing assert is not the last statement of the block
                        //Debug.Assert(cc.Proc.Name == calleeTraces[currCount].fst);

                        newCalleeTraces.Add(new TraceLocation(newBlocks.Count - 1, numInstr), calleeTraces[currCount].snd);
                        currCount++;
                    }
                }
            }
            trace.Trace = newBlocks;
            // reset other info. Safe thing to do unless we know what it is
            trace.calleeCounterexamples = newCalleeTraces;
        }
示例#24
0
        public static Counterexample ReconstructTrace(Counterexample trace, string currProc, TraceLocation currLocation, Dictionary <string, Tuple <Block, Implementation> > origProg)
        {
            // we cannot be starting in the last block
            Debug.Assert(currLocation.numBlock != trace.Trace.Count - 1);
            // we cannot be starting in the middle of a block
            Debug.Assert(currLocation.numInstr == 0);

            var newTrace        = new List <Block>();
            var newTraceCallees = new Dictionary <TraceLocation, CalleeCounterexampleInfo>();

            Block          currOrigBlock = null;
            Implementation currOrigImpl  = null;
            int            currOrigInstr = 0;

            while (true)
            {
                if (currLocation.numInstr == 0 && origProg.ContainsKey(trace.Trace[currLocation.numBlock].Label))
                {
                    var origPlace = origProg[trace.Trace[currLocation.numBlock].Label];
                    if (currOrigImpl != null && currOrigImpl.Name != origPlace.Item2.Name)
                    {
                        // change of proc

                        // First, recurse
                        var calleeTrace = ReconstructTrace(trace, origPlace.Item2.Name, currLocation, origProg);
                        // Find the call to this guy in currOrigBlock
                        while (currOrigInstr < currOrigBlock.Cmds.Count)
                        {
                            var cmd = currOrigBlock.Cmds[currOrigInstr] as CallCmd;
                            if (cmd != null && cmd.callee == origPlace.Item2.Name)
                            {
                                break;
                            }
                            currOrigInstr++;
                        }
                        Debug.Assert(currOrigInstr != currOrigBlock.Cmds.Count);
                        newTraceCallees.Add(new TraceLocation(newTrace.Count - 1, currOrigInstr), new CalleeCounterexampleInfo(calleeTrace, new List <object>()));
                        // we're done
                        break;
                    }

                    currOrigBlock = origPlace.Item1;
                    currOrigImpl  = origProg[trace.Trace[currLocation.numBlock].Label].Item2;
                    currOrigInstr = 0;

                    newTrace.Add(currOrigBlock);
                }

                if (trace.calleeCounterexamples.ContainsKey(currLocation))
                {
                    // find the corresponding call in origBlock
                    var calleeInfo = trace.calleeCounterexamples[currLocation];
                    var calleeName = trace.getCalledProcName(trace.Trace[currLocation.numBlock].Cmds[currLocation.numInstr]);
                    while (currOrigInstr < currOrigBlock.Cmds.Count)
                    {
                        var cmd = currOrigBlock.Cmds[currOrigInstr] as CallCmd;
                        if (cmd != null && cmd.callee == calleeName)
                        {
                            break;
                        }
                        currOrigInstr++;
                    }
                    Debug.Assert(currOrigInstr != currOrigBlock.Cmds.Count);
                    newTraceCallees.Add(new TraceLocation(newTrace.Count - 1, currOrigInstr), calleeInfo);
                }

                // increment location
                currLocation.numInstr++;
                if (currLocation.numInstr >= trace.Trace[currLocation.numBlock].Cmds.Count)
                {
                    currLocation.numBlock++;
                    currLocation.numInstr = 0;
                }
                if (currLocation.numBlock == trace.Trace.Count)
                {
                    break;
                }
            }

            var ret = new AssertCounterexample(newTrace, null, null, trace.Model, trace.MvInfo, trace.Context);

            ret.calleeCounterexamples = newTraceCallees;

            return(ret);
        }
示例#25
0
 public abstract Task NotifyCounterexampleAsync(Counterexample counterexample);
示例#26
0
        internal void ReportCounterexample(Counterexample error)
        {
            int WindowWidth;

            try {
                WindowWidth = Console.WindowWidth;
            } catch (IOException) {
                WindowWidth = 20;
            }

            for (int i = 0; i < WindowWidth; i++)
            {
                Console.Error.Write("-");
            }

            if (error is CallCounterexample)
            {
                CallCounterexample CallCex = (CallCounterexample)error;
                if (QKeyValue.FindBoolAttribute(CallCex.FailingRequires.Attributes, "barrier_divergence"))
                {
                    ReportBarrierDivergence(CallCex.FailingCall);
                }
                else if (QKeyValue.FindBoolAttribute(CallCex.FailingRequires.Attributes, "race"))
                {
                    ReportRace(CallCex);
                }
                else
                {
                    ReportRequiresFailure(CallCex.FailingCall, CallCex.FailingRequires);
                }
            }
            else if (error is ReturnCounterexample)
            {
                ReturnCounterexample ReturnCex = (ReturnCounterexample)error;
                ReportEnsuresFailure(ReturnCex.FailingEnsures);
            }
            else
            {
                AssertCounterexample AssertCex = (AssertCounterexample)error;
                if (AssertCex.FailingAssert is LoopInitAssertCmd)
                {
                    ReportInvariantEntryFailure(AssertCex);
                }
                else if (AssertCex.FailingAssert is LoopInvMaintainedAssertCmd)
                {
                    ReportInvariantMaintedFailure(AssertCex);
                }
                else if (QKeyValue.FindBoolAttribute(AssertCex.FailingAssert.Attributes, "barrier_invariant"))
                {
                    ReportFailingBarrierInvariant(AssertCex);
                }
                else if (QKeyValue.FindBoolAttribute(AssertCex.FailingAssert.Attributes, "barrier_invariant_access_check"))
                {
                    ReportFailingBarrierInvariantAccessCheck(AssertCex);
                }
                else if (QKeyValue.FindBoolAttribute(AssertCex.FailingAssert.Attributes, "constant_write"))
                {
                    ReportFailingConstantWriteCheck(AssertCex);
                }
                else if (QKeyValue.FindBoolAttribute(AssertCex.FailingAssert.Attributes, "bad_pointer_access"))
                {
                    ReportFailingBadPointerAccess(AssertCex);
                }
                else if (QKeyValue.FindBoolAttribute(AssertCex.FailingAssert.Attributes, "array_bounds"))
                {
                    ReportFailingArrayBounds(AssertCex);
                }
                else
                {
                    ReportFailingAssert(AssertCex);
                }
            }

            DisplayParameterValues(error);

            if (((GVCommandLineOptions)CommandLineOptions.Clo).DisplayLoopAbstractions)
            {
                DisplayLoopAbstractions(error);
            }
        }
示例#27
0
 private static string BuildMessage(
     Counterexample <object?> counterexample,
     int iterations,
     int shrinks,
     Func <string, string>?formatReproduction) =>
 string.Join(Environment.NewLine, BuildLines(counterexample, iterations, shrinks, formatReproduction));
示例#28
0
 /// <summary>
 /// Instantiates a new error.
 /// </summary>
 /// <param name="counterExample">The counter example.</param>
 /// <param name="implementation">The implementation.</param>
 public Error(Counterexample counterExample, Implementation implementation)
 {
     CounterExample = counterExample;
     Implementation = implementation;
 }
示例#29
0
 public override void OnCounterexample(Counterexample ce, string message)
 {
     this.modelCount++;
       this.PrintSummary(VC.ConditionGeneration.Outcome.Errors);
       this.errorHandler.ReportCounterexample(ce, message);
 }
示例#30
0
 private static string ReproductionLine(
     Counterexample <object?> counterexample,
     Func <string, string>?formatReproduction)
 {
 private void OnCreateCounterexample(Counterexample response, Dictionary <string, object> customData)
 {
     Log.Debug("ExampleAssistant.OnCreateCounterexample()", "Response: {0}", customData["json"].ToString());
     _createCounterexampleTested = true;
 }
示例#32
0
        private Tuple<List<Tuple<string, List<Model.Element>>>, List<Tuple<string, List<Model.Element>>>> P_ExtractState(string impl, Counterexample error)
        {
            var lastBlock = error.Trace.Last() as Block;
            AssertCmd failingAssert = null;

            CallCounterexample callCounterexample = error as CallCounterexample;
            if (callCounterexample != null)
            {
                Procedure failingProcedure = callCounterexample.FailingCall.Proc;
                Requires failingRequires = callCounterexample.FailingRequires;
                failingAssert = lastBlock.Cmds.OfType<AssertRequiresCmd>().FirstOrDefault(ac => ac.Requires == failingRequires);
            }
            ReturnCounterexample returnCounterexample = error as ReturnCounterexample;
            if (returnCounterexample != null)
            {
                Ensures failingEnsures = returnCounterexample.FailingEnsures;
                failingAssert = lastBlock.Cmds.OfType<AssertEnsuresCmd>().FirstOrDefault(ac => ac.Ensures == failingEnsures);
            }
            AssertCounterexample assertCounterexample = error as AssertCounterexample;
            if (assertCounterexample != null)
            {
                failingAssert = lastBlock.Cmds.OfType<AssertCmd>().FirstOrDefault(ac => ac == assertCounterexample.FailingAssert);
            }
            Debug.Assert(failingAssert != null);

            // extract the lhs of the returned tuple from the AssumeCmds
            List<Tuple<string, List<Model.Element>>> lhs = new List<Tuple<string, List<Model.Element>>>();
            foreach (var cmd in error.AssumedCmds)
            {
                AssumeCmd assumeCmd = cmd as AssumeCmd;
                Debug.Assert(assumeCmd != null);
                lhs.AddRange(P_ExtractState(impl, assumeCmd.Expr, error.Model));
            }

            List<Tuple<string, List<Model.Element>>> rhs = new List<Tuple<string, List<Model.Element>>>();
            rhs = P_ExtractState(impl, failingAssert.Expr, error.Model);
            return Tuple.Create(lhs, rhs);
        }
示例#33
0
        public override Counterexample extractLoopTrace(Counterexample cex, string mainProcName, Program program, Dictionary<string, Dictionary<string, Block>> extractLoopMappingInfo)
        {
            // Construct the set of inlined procs in the original program
            var inlinedProcs = new HashSet<string>();
            foreach (var decl in program.TopLevelDeclarations)
            {
                // Implementations
                if (decl is Implementation)
                {
                    var impl = decl as Implementation;
                    if (!(impl.Proc is LoopProcedure))
                    {
                        inlinedProcs.Add(impl.Name);
                    }
                }

                // And recording procedures
                if (decl is Procedure)
                {
                    var proc = decl as Procedure;
                    if (proc.Name.StartsWith(recordProcName))
                    {
                        // Debug.Assert(!(decl is LoopProcedure));
                        inlinedProcs.Add(proc.Name);
                    }
                }
            }
            return extractLoopTraceRec(
              new CalleeCounterexampleInfo(cex, new List<object>()),
              mainProcName, inlinedProcs, extractLoopMappingInfo).counterexample;
        }
示例#34
0
 public override void OnCounterexample(Counterexample ce, string reason)
 {
     //numErrors++;
     if (container.HandleCounterExample(currImpl, ce))
     {
         real_errors.Add(ce);
     }
     else
     {
         conjecture_errors.Add(ce);
     }
     //funcsChanged.UnionWith(
     //    container.HandleCounterExample(currImpl, ce));
 }
示例#35
0
        /*
        public void AddNewInvConstraintToZ3Context()
        {
            List<Term> args = new List<Term>();
            foreach(var funcName in function2Value.Keys)
            {
                args.Add(function2Value[funcName].currLearnedInvAsTerm(ref z3Context));
            }

            Context context = z3Context.context;
            context.AssertCnstr(context.MkNot(context.MkAnd(args.ToArray())));
        }*/
        public bool HandleCounterExample(string impl, Counterexample error)
        {
            // return true if a true error encountered.
            // return false if the error is due to a wrong choice of current conjecture.

            VCisValid = false;
            var cex = P_ExtractState(impl, error);

            // the counter-example does not involve any existential function ==> Is a real counter-example !
            if (cex.Item1.Count == 0 && cex.Item2.Count == 0)
            {
                realErrorEncountered = true;
                return true;
            }

            AddCounterExample(cex);
            AddCounterExampleToZ3Context(cex);
            /*
            AddNewInvConstraintToZ3Context();
            */
            newSamplesAdded = true;
            return false;
        }
示例#36
0
        private List<Tuple<string, List<Model.Element>>> ExtractState(string impl, Counterexample error)
        {
            var lastBlock = error.Trace.Last() as Block;
            AssertCmd failingAssert = null;

            CallCounterexample callCounterexample = error as CallCounterexample;
            if (callCounterexample != null)
            {
                Procedure failingProcedure = callCounterexample.FailingCall.Proc;
                Requires failingRequires = callCounterexample.FailingRequires;
                failingAssert = lastBlock.Cmds.OfType<AssertRequiresCmd>().FirstOrDefault(ac => ac.Requires == failingRequires);
            }
            ReturnCounterexample returnCounterexample = error as ReturnCounterexample;
            if (returnCounterexample != null)
            {
                Ensures failingEnsures = returnCounterexample.FailingEnsures;
                failingAssert = lastBlock.Cmds.OfType<AssertEnsuresCmd>().FirstOrDefault(ac => ac.Ensures == failingEnsures);
            }
            AssertCounterexample assertCounterexample = error as AssertCounterexample;
            if (assertCounterexample != null)
            {
                failingAssert = lastBlock.Cmds.OfType<AssertCmd>().FirstOrDefault(ac => ac == assertCounterexample.FailingAssert);
            }

            Debug.Assert(failingAssert != null);
            return ExtractState(impl, failingAssert.Expr, error.Model);
        }
示例#37
0
        public bool HandleCounterExample(string impl, Counterexample error, out bool counterExampleAdded)
        {
            // return true if a true error encountered.
            // return false if the error is due to a wrong choice of current conjecture.
            counterExampleAdded = false;

            VCisValid = false;
            var cex = P_ExtractState(impl, error);

            // the counter-example does not involve any existential function ==> Is a real counter-example !
            if (cex.Item1.Count == 0 && cex.Item2.Count == 0)
            {
                realErrorEncountered = true;
                return true;
            }
            if (!newSamplesAdded || (cex.Item1.Count == 1 && cex.Item2.Count == 0) || (cex.Item2.Count == 1 && cex.Item1.Count == 0))
            {
                AddCounterExample(cex);
                counterExampleAdded = true;
            }
            newSamplesAdded = true;          
            return false;
        }
示例#38
0
        private static ErrorInformation CreateErrorInformation(Counterexample error, VC.VCGen.Outcome outcome)
        {
            // BP1xxx: Parsing errors
              // BP2xxx: Name resolution errors
              // BP3xxx: Typechecking errors
              // BP4xxx: Abstract interpretation errors (Is there such a thing?)
              // BP5xxx: Verification errors

              ErrorInformation errorInfo;
              var cause = "Error";
              if (outcome == VCGen.Outcome.TimedOut)
              {
            cause = "Timed out on";
              }
              else if (outcome == VCGen.Outcome.OutOfMemory)
              {
            cause = "Out of memory on";
              }

              var callError = error as CallCounterexample;
              var returnError = error as ReturnCounterexample;
              var assertError = error as AssertCounterexample;
              if (callError != null)
              {
            errorInfo = errorInformationFactory.CreateErrorInformation(callError.FailingCall.tok, callError.FailingCall.ErrorData as string ?? "A precondition for this call might not hold.", callError.RequestId, callError.OriginalRequestId, cause);
            errorInfo.BoogieErrorCode = "BP5002";
            errorInfo.Kind = ErrorKind.Precondition;
            errorInfo.AddAuxInfo(callError.FailingRequires.tok, callError.FailingRequires.ErrorData as string ?? "This is the precondition that might not hold.", "Related location");

            if (!CommandLineOptions.Clo.ForceBplErrors && callError.FailingRequires.ErrorMessage != null)
            {
              errorInfo = errorInformationFactory.CreateErrorInformation(null, callError.FailingRequires.ErrorMessage, callError.RequestId, callError.OriginalRequestId, cause);
            }
              }
              else if (returnError != null)
              {
            errorInfo = errorInformationFactory.CreateErrorInformation(returnError.FailingReturn.tok, "A postcondition might not hold on this return path.", returnError.RequestId, returnError.OriginalRequestId, cause);
            errorInfo.BoogieErrorCode = "BP5003";
            errorInfo.Kind = ErrorKind.Postcondition;
            errorInfo.AddAuxInfo(returnError.FailingEnsures.tok, returnError.FailingEnsures.ErrorData as string ?? "This is the postcondition that might not hold.", "Related location");

            if (!CommandLineOptions.Clo.ForceBplErrors && returnError.FailingEnsures.ErrorMessage != null)
            {
              errorInfo = errorInformationFactory.CreateErrorInformation(null, returnError.FailingEnsures.ErrorMessage, returnError.RequestId, returnError.OriginalRequestId, cause);
            }
              }
              else // error is AssertCounterexample
              {
            if (assertError.FailingAssert is LoopInitAssertCmd)
            {
              errorInfo = errorInformationFactory.CreateErrorInformation(assertError.FailingAssert.tok, "This loop invariant might not hold on entry.", assertError.RequestId, assertError.OriginalRequestId, cause);
              errorInfo.BoogieErrorCode = "BP5004";
              errorInfo.Kind = ErrorKind.InvariantEntry;
            }
            else if (assertError.FailingAssert is LoopInvMaintainedAssertCmd)
            {
              errorInfo = errorInformationFactory.CreateErrorInformation(assertError.FailingAssert.tok, "This loop invariant might not be maintained by the loop.", assertError.RequestId, assertError.OriginalRequestId, cause);
              errorInfo.BoogieErrorCode = "BP5005";
              errorInfo.Kind = ErrorKind.InvariantMaintainance;
            }
            else
            {
              var msg = assertError.FailingAssert.ErrorData as string;
              var tok = assertError.FailingAssert.tok;
              if (!CommandLineOptions.Clo.ForceBplErrors && assertError.FailingAssert.ErrorMessage != null)
              {
            msg = assertError.FailingAssert.ErrorMessage;
            tok = null;
            if (cause == "Error")
            {
              cause = null;
            }
              }
              string bec = null;
              if (msg == null)
              {
            msg = "This assertion might not hold.";
            bec = "BP5001";
              }

              errorInfo = errorInformationFactory.CreateErrorInformation(tok, msg, assertError.RequestId, assertError.OriginalRequestId, cause);
              errorInfo.BoogieErrorCode = bec;
              errorInfo.Kind = ErrorKind.Assertion;
            }
              }

              return errorInfo;
        }
示例#39
0
        public bool HandleCounterExample(string impl, Counterexample error, out bool cexAdded)
        {
            // return true if a true error encountered.
            // return false if the error is due to a wrong choice of current conjecture.
            VCisValid = false;
            var cex = P_ExtractState(impl, error);

            // the counter-example does not involve any existential function ==> Is a real counter-example !
            if (cex.Item1.Count == 0 && cex.Item2.Count == 0)
            {
                //realErrorEncountered = true;
                cexAdded = false;
                return true;
            }

#if true
            if (cex.Item1.Count == 0 || cex.Item2.Count == 0)
            {
                cexAdded = true;
                AddCounterExample(cex);
                return false;
            }
            else
            {
                cexAdded = false;
                implicationCounterExamples.Add(cex);
                return false;
            }

            /*
            if (!this.posNegCexAdded || (cex.Item1.Count == 0 || cex.Item2.Count == 0))
            {
                // Record the cex. Is a positive or negative cex or is the first occurence of the implications
                if(cex.Item1.Count == 0 || cex.Item2.Count == 0)
                    this.posNegCexAdded = true;

                cexAdded = true;
                AddCounterExample(cex);
                newSamplesAdded = true;
                return false;
            }
            else
            {
#if false
                AddCounterExample(cex, false);
#endif
                cexAdded = false;
                return false;
            }
            */
#else
            cexAdded = true;
            AddCounterExample(cex);
            newSamplesAdded = true;
            return false;
#endif
        }
示例#40
0
 /// <summary>
 /// Instantiates a new error.
 /// </summary>
 /// <param name="counterExample">The counter example.</param>
 /// <param name="implementation">The implementation.</param>
 public RaceError(Counterexample counterExample, Implementation implementation)
     : base(counterExample, implementation)
 {
 }
示例#41
0
            public override void OnCounterexample(Counterexample ce, string reason)
            {                
                //numErrors++;                
#if Pranav
                bool counterExampleAdded;
                if (container.HandleCounterExample(currImpl, ce, out counterExampleAdded))
                {
                    real_errors.Add(ce);
                }
                else
                {
                    if (counterExampleAdded)
                    {
                        conjecture_errors.Add(ce);
                    }
                }
#endif
                bool cexAdded;
                if (container.HandleCounterExample(currImpl, ce, out cexAdded))
                {
                    real_errors.Add(ce);
                }
                else
                {
                    if (cexAdded)
                    {
                        conjecture_errors.Add(ce);
                    }
                    else
                    {
                        implication_errors.Add(ce);
                    }
                }
                //funcsChanged.UnionWith(
                //    container.HandleCounterExample(currImpl, ce));
            }