public void ShouldBeSame()
        {
            var builder = new SimpleExprBuilder(true);

            var dummyV = SymbooglixLibTests.MapProxyTests.GetVariable("dummy", BPLType.Int);

            // Hack
            dummyV.SetMetadata((int)Symbooglix.Annotation.AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(dummyV));
            var v  = new SymbolicVariable("foo", dummyV);
            var id = builder.Identifier(v);

            var c0     = new Constraint(builder.Gt(id, builder.ConstantInt(0)));
            var c0Copy = new Constraint(builder.Gt(id, builder.ConstantInt(0)));
            var c1     = new Constraint(builder.Lt(id, builder.ConstantInt(10)));
            var c1Copy = new Constraint(builder.Lt(id, builder.ConstantInt(10)));

            var CM0 = new ConstraintManager();

            Assert.AreEqual(0, CM0.GetHashCode());
            CM0.AddConstraint(c0);
            var firstHashCode = CM0.GetHashCode();

            CM0.AddConstraint(c1);
            Assert.AreNotEqual(firstHashCode, CM0.GetHashCode());

            var CM1 = new ConstraintManager();

            CM1.AddConstraint(c0Copy);
            Assert.AreEqual(firstHashCode, CM1.GetHashCode());
            CM1.AddConstraint(c1Copy);
            Assert.AreEqual(CM0.GetHashCode(), CM1.GetHashCode());

            Assert.IsTrue(CM0.Equals(CM1));
        }
Esempio n. 2
0
        public void ConstraintDifferent()
        {
            var builder = new SimpleExprBuilder(true);

            var dummyV = SymbooglixLibTests.MapProxyTests.GetVariable("dummy", BPLType.Int);

            // Hack
            dummyV.SetMetadata((int)Symbooglix.Annotation.AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(dummyV));
            var v  = new SymbolicVariable("foo", dummyV);
            var id = builder.Identifier(v);

            var c0     = new Constraint(builder.Gt(id, builder.ConstantInt(0)));
            var c0Copy = new Constraint(builder.Gt(id, builder.ConstantInt(0)));
            var c1     = new Constraint(builder.Lt(id, builder.ConstantInt(10)));
            var c1diff = new Constraint(builder.Le(id, builder.ConstantInt(10)));

            var CM0 = new ConstraintManager();
            var CM1 = new ConstraintManager();

            CM0.AddConstraint(c0);
            CM0.AddConstraint(c1);
            CM1.AddConstraint(c0Copy);
            CM1.AddConstraint(c1diff);

            var queryExpr0 = builder.Eq(id, builder.ConstantInt(5));
            var queryExpr1 = builder.Eq(id, builder.ConstantInt(5));

            var query0 = new Symbooglix.Solver.Query(CM0, new Constraint(queryExpr0));
            var query1 = new Symbooglix.Solver.Query(CM1, new Constraint(queryExpr1));

            Assert.AreNotEqual(query0.GetHashCode(), query1.GetHashCode());

            Assert.IsFalse(query0.Equals(query1));
        }
        public void GetSubSet()
        {
            var builder = new SimpleExprBuilder(true);

            var dummyV = SymbooglixLibTests.MapProxyTests.GetVariable("dummy", BPLType.Int);

            // Hack
            dummyV.SetMetadata((int)Symbooglix.Annotation.AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(dummyV));
            var v  = new SymbolicVariable("foo", dummyV);
            var id = builder.Identifier(v);

            var c0 = new Constraint(builder.Gt(id, builder.ConstantInt(0)));
            var c1 = new Constraint(builder.Lt(id, builder.ConstantInt(10)));

            var CM0      = new ConstraintManager();
            var CMSubset = new ConstraintManager();

            CM0.AddConstraint(c0);
            CM0.AddConstraint(c1);

            CMSubset.AddConstraint(c1);

            var getSubset = CM0.GetSubSet(new HashSet <Constraint>()
            {
                c1
            });

            // Check they are the same
            Assert.AreEqual(1, getSubset.Count);
            Assert.AreEqual(1, CMSubset.Count);
            Assert.AreEqual(CMSubset.GetHashCode(), getSubset.GetHashCode());
            Assert.IsTrue(CMSubset.Equals(getSubset));
        }
        public void DoClone()
        {
            var builder = new SimpleExprBuilder(true);

            var dummyV = SymbooglixLibTests.MapProxyTests.GetVariable("dummy", BPLType.Int);

            // Hack
            dummyV.SetMetadata((int)Symbooglix.Annotation.AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(dummyV));
            var v  = new SymbolicVariable("foo", dummyV);
            var id = builder.Identifier(v);

            var c0 = new Constraint(builder.Gt(id, builder.ConstantInt(0)));
            var c1 = new Constraint(builder.Lt(id, builder.ConstantInt(10)));

            var CM0 = new ConstraintManager();

            CM0.AddConstraint(c0);
            CM0.AddConstraint(c1);

            var copy = CM0.Clone();

            Assert.AreNotSame(CM0, copy);
            Assert.AreEqual(CM0.Count, copy.Count);
            Assert.AreEqual(CM0.GetHashCode(), copy.GetHashCode());
            Assert.IsTrue(CM0.Equals(copy));

            // Modify original and check copy has not changed
            CM0.AddConstraint(new Constraint(builder.Lt(id, builder.ConstantInt(8))));
            Assert.AreNotEqual(copy.GetHashCode(), CM0.GetHashCode());
            Assert.IsFalse(CM0.Equals(copy));
            Assert.AreEqual(2, copy.Count);
            Assert.AreEqual(3, CM0.Count);
        }
Esempio n. 5
0
        public void Arguments()
        {
            var tcDecl = new TypeCtorDecl(Token.NoToken, "fox", 1);
            var tc     = new CtorType(Token.NoToken, tcDecl, new List <Microsoft.Boogie.Type>()
            {
                Microsoft.Boogie.Type.Bool
            });
            var tcTypeIdent = new TypedIdent(Token.NoToken, "fox", tc);
            var gv          = new GlobalVariable(Token.NoToken, tcTypeIdent);

            // FIXME: The Symbolic constructor shouldn't really need the program location
            gv.SetMetadata <ProgramLocation>((int)AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(gv));
            var sym = new SymbolicVariable("y", gv);

            var builder = new SimpleExprBuilder(/*immutable=*/ true);
            var eq      = builder.Eq(sym.Expr, sym.Expr);

            Assert.IsNotInstanceOf <LiteralExpr>(eq); // Check that it wasn't constant folded

            using (var writer = new StringWriter())
            {
                var printer = GetPrinter(writer);
                printer.AddDeclarations(eq);
                printer.PrintSortDeclarations();
                Assert.AreEqual("(declare-sort @fox)\n", writer.ToString());
            }
        }
Esempio n. 6
0
        public void ShouldBeIdentical()
        {
            var builder = new SimpleExprBuilder(true);

            var dummyV = SymbooglixLibTests.MapProxyTests.GetVariable("dummy", BPLType.Int);

            // Hack
            dummyV.SetMetadata((int)Symbooglix.Annotation.AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(dummyV));
            var v = new SymbolicVariable("foo", dummyV);

            var c0 = new Constraint(builder.Lt(builder.Identifier(v), builder.ConstantInt(5)));
            var c1 = new Constraint(builder.Lt(builder.Identifier(v), builder.ConstantInt(5)));

            Assert.AreEqual(c0.GetHashCode(), c1.GetHashCode());
            Assert.IsTrue(c0.Equals(c1));

            // Check used variables
            Assert.AreEqual(1, c0.UsedVariables.Count);
            Assert.AreEqual(1, c1.UsedVariables.Count);
            Assert.IsTrue(c0.UsedVariables.Contains(v));
            Assert.IsTrue(c1.UsedVariables.Contains(v));

            Assert.AreEqual(0, c0.UsedUninterpretedFunctions.Count);
            Assert.AreEqual(0, c1.UsedUninterpretedFunctions.Count);
        }
Esempio n. 7
0
        public void Test()
        {
            var builder = new SimpleExprBuilder(/*immutable=*/ true);
            var bv0_32  = builder.ConstantBV(0, 32);
            var bv1_32  = builder.ConstantBV(1, 32);
            var neq     = builder.NotEq(bv0_32, bv1_32);

            using (var writer = new StringWriter())
            {
                var printer = GetPrinter(writer);
                printer.PrintExpr(neq);
                Assert.AreEqual("(distinct (_ bv0 32) (_ bv1 32) )", writer.ToString());
            }
        }
Esempio n. 8
0
        public void Test()
        {
            var builder   = new SimpleExprBuilder(/*immutable=*/ true);
            var boolTrue  = builder.ConstantBool(true);
            var boolFalse = builder.ConstantBool(false);
            var iffExpr   = builder.Iff(boolTrue, boolFalse);

            using (var writer = new StringWriter())
            {
                var printer = GetPrinter(writer);
                printer.PrintExpr(iffExpr);
                Assert.AreEqual("(and (=> true false ) (=> false true ) )", writer.ToString());
            }
        }
Esempio n. 9
0
 public void NoFold()
 {
     var builders = GetSimpleAndConstantFoldingBuilder();
     SimpleExprBuilder sfb = builders.Item1;
     ConstantFoldingExprBuilder cfb = builders.Item2;
     var arg0 = GetVarAndIdExpr("x", BasicType.GetBvType(8)).Item2;
     var arg1 = GetVarAndIdExpr("y", BasicType.GetBvType(8)).Item2;
     var simpleResult = sfb.BVSMOD(arg0, arg1);
     var result = cfb.BVSMOD(arg0, arg1);
     CheckIsBvType(result, 8);
     CheckIsBvType(simpleResult, 8);
     Assert.IsNull(ExprUtil.AsLiteral(result));
     Assert.IsNotNull(ExprUtil.AsBVSMOD(result));
     Assert.IsTrue(ExprUtil.StructurallyEqual(result, simpleResult));
 }
Esempio n. 10
0
        public void ShouldNotBeIdentical()
        {
            var builder = new SimpleExprBuilder(true);

            var dummyV = SymbooglixLibTests.MapProxyTests.GetVariable("dummy", BPLType.Int);

            // Hack
            dummyV.SetMetadata((int)Symbooglix.Annotation.AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(dummyV));
            var v = new SymbolicVariable("foo", dummyV);

            var c0 = new Constraint(builder.Lt(builder.Identifier(v), builder.ConstantInt(5)));
            var c1 = new Constraint(builder.Gt(builder.Identifier(v), builder.ConstantInt(5)));

            Assert.AreNotEqual(c0.GetHashCode(), c1.GetHashCode());
            Assert.IsFalse(c0.Equals(c1));
        }
Esempio n. 11
0
        public void Test()
        {
            var builder  = new SimpleExprBuilder(/*immutable=*/ true);
            var v0       = builder.False;
            var v1       = builder.True;
            var distinct = builder.Distinct(new List <Expr>()
            {
                v0, v1
            });

            using (var writer = new StringWriter())
            {
                var printer = GetPrinter(writer);
                printer.PrintExpr(distinct);
                Assert.AreEqual("(distinct false true )", writer.ToString());
            }
        }
Esempio n. 12
0
        public void PartialIndexMap()
        {
            p = LoadProgramFrom(@"
            procedure main()
            {
                var x:[int][int]bool;
                var y:[int][int]bool;
                var symIndex:int;
                x[0][0] := false;
                // only partially index into y
                y[0] := x[0];
                assert {:symbooglix_bp ""check_written""} true;
            }

            ", "test.bpl");

            e = GetExecutor(p);
            bool check_written = false;
            var  builder       = new SimpleExprBuilder(true);
            var  localVarX     = p.TopLevelDeclarations.OfType <Implementation>().Where(i => i.Name == "main").First().LocVars.Where(v => v.Name == "x").First();
            var  localVarY     = p.TopLevelDeclarations.OfType <Implementation>().Where(i => i.Name == "main").First().LocVars.Where(v => v.Name == "y").First();

            e.BreakPointReached += delegate(object sender, Executor.BreakPointEventArgs eventArgs)
            {
                Assert.AreEqual("check_written", eventArgs.Name);
                check_written = true;

                // Check we can read x[0][0] directly
                var x00 = e.CurrentState.ReadMapVariableInScopeAt(localVarX, new List <Expr>()
                {
                    builder.ConstantInt(0),
                    builder.ConstantInt(0)
                });
                Assert.AreEqual(builder.False, x00);

                var yExpr = e.CurrentState.GetInScopeVariableExpr(localVarY);
                Assert.AreEqual("~sb_y_0[0 := ~sb_x_0[0 := ~sb_x_0[0][0 := false]][0]]", yExpr.ToString());
            };
            e.Run(GetMain(p));
            Assert.IsTrue(check_written);
        }
Esempio n. 13
0
        public void MapWithTypeConstructorTypesNoArguments()
        {
            var tcDecl  = new TypeCtorDecl(Token.NoToken, "fox", 0);
            var tc      = new CtorType(Token.NoToken, tcDecl, new List <Microsoft.Boogie.Type>());
            var tcDecl2 = new TypeCtorDecl(Token.NoToken, "fox_two", 0);
            var tc2     = new CtorType(Token.NoToken, tcDecl2, new List <Microsoft.Boogie.Type>());
            var tcDecl3 = new TypeCtorDecl(Token.NoToken, "fox_three", 0);
            var tc3     = new CtorType(Token.NoToken, tcDecl3, new List <Microsoft.Boogie.Type>());
            var mapType = new MapType(
                Token.NoToken,
                new List <Microsoft.Boogie.TypeVariable>(),
                new List <Microsoft.Boogie.Type>()
            {
                tc, tc2
            },
                tc3);
            var mapTypeTypeIdent = new TypedIdent(Token.NoToken, "mapx", mapType);
            var gv = new GlobalVariable(Token.NoToken, mapTypeTypeIdent);

            // FIXME: The Symbolic constructor shouldn't really need the program location
            gv.SetMetadata <ProgramLocation>((int)AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(gv));
            var sym = new SymbolicVariable("y", gv);

            var builder = new SimpleExprBuilder(/*immutable=*/ true);
            var eq      = builder.Eq(sym.Expr, sym.Expr);

            Assert.IsNotInstanceOf <LiteralExpr>(eq); // Check that it wasn't constant folded

            using (var writer = new StringWriter()) {
                var printer = GetPrinter(writer);
                printer.AddDeclarations(eq);
                printer.PrintSortDeclarations();
                var str = writer.ToString().Trim();
                // Check we can see all the sort declarations we expect but don't depend on their order
                Assert.IsTrue(str.Contains("(declare-sort @fox)"));
                Assert.IsTrue(str.Contains("(declare-sort @fox_two)"));
                Assert.IsTrue(str.Contains("(declare-sort @fox_three)"));
            }
        }
Esempio n. 14
0
        public static Executor GetExecutor(Program p, IStateScheduler scheduler = null, ISolver solver = null, bool useConstantFolding = false)
        {
            if (scheduler == null)
            {
                scheduler = new DFSStateScheduler();
            }

            if (solver == null)
            {
                solver = new SimpleSolver(new DummySolver());
            }

            IExprBuilder builder = new SimpleExprBuilder(/*immutable=*/ true);

            if (useConstantFolding)
            {
                builder = new ConstantFoldingExprBuilder(new ConstantCachingExprBuilder(builder));
            }

            Executor e = new Executor(p, scheduler, solver, builder, new SimpleSymbolicPool());

            return(e);
        }
Esempio n. 15
0
        public void ConcreteMapAssign()
        {
            p = LoadProgramFrom(@"
            procedure main()
            {
                var x:[int][int]bool;
                var symIndex:int;
                x[0][0] := true;
                x[0][1] := false;
                assert {:symbooglix_bp ""check_written""} true;

                // write to symbolic location
                x[0][symIndex] := false;

                assert {:symbooglix_bp ""check_sym_write""} true;
            }

            ", "test.bpl");

            e = GetExecutor(p);
            bool check_written   = false;
            bool check_sym_write = false;
            var  builder         = new SimpleExprBuilder(true);
            var  localVarV       = p.TopLevelDeclarations.OfType <Implementation>().Where(i => i.Name == "main").First().LocVars.Where(v => v.Name == "x").First();

            e.BreakPointReached += delegate(object sender, Executor.BreakPointEventArgs eventArgs)
            {
                switch (eventArgs.Name)
                {
                case "check_written":
                    check_written = true;


                    // Check we can read x[0][0] directly
                    var x00 = e.CurrentState.ReadMapVariableInScopeAt(localVarV, new List <Expr>()
                    {
                        builder.ConstantInt(0), builder.ConstantInt(0)
                    });
                    Assert.AreEqual(builder.True, x00);
                    var x01 = e.CurrentState.ReadMapVariableInScopeAt(localVarV, new List <Expr>()
                    {
                        builder.ConstantInt(0), builder.ConstantInt(1)
                    });
                    Assert.AreEqual(builder.False, x01);

                    // Check the flushed expression from
                    // Note without the constant folding expr builder the form is
                    // "~sb_x_0[0 := ~sb_x_0[0][0 := true]][0 := ~sb_x_0[0 := ~sb_x_0[0][0 := true]][0][1 := false]]"
                    Assert.AreEqual("~sb_x_0[0 := ~sb_x_0[0][0 := true][1 := false]]",
                                    e.CurrentState.GetInScopeVariableExpr(localVarV).ToString());
                    break;

                case "check_sym_write":
                    check_sym_write = true;

                    var x00After = e.CurrentState.ReadMapVariableInScopeAt(localVarV, new List <Expr>()
                    {
                        builder.ConstantInt(0), builder.ConstantInt(0)
                    });
                    Console.WriteLine(x00After.ToString());
                    // FIXME: I'm unsure if this is correct
                    Console.WriteLine(x00After.ToString());
                    Assert.AreEqual("~sb_x_0[0][0 := true][1 := false][~sb_symIndex_0 := false][0]",
                                    x00After.ToString());
                    break;

                default:
                    Assert.Fail("Unexpected breakpoint");
                    break;
                }
            };
            e.Run(GetMain(p));

            Assert.IsTrue(check_written);
            Assert.IsTrue(check_sym_write);
        }
Esempio n. 16
0
        public static int RealMain(String[] args)
        {
            // Debug log output goes to standard error.
            Debug.Listeners.Add(new ExceptionThrowingTextWritierTraceListener(Console.Error));

            // FIXME: Urgh... we are forced to use Boogie's command line
            // parser becaue the Boogie program resolver/type checker
            // is dependent on the parser being used...EURGH!
            CommandLineOptions.Install(new Microsoft.Boogie.CommandLineOptions());


            var options = new CmdLineOpts();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                Console.WriteLine("Failed to parse args");
                ExitWith(ExitCode.COMMAND_LINE_ERROR);
            }

            if (options.boogieProgramPath == null)
            {
                Console.WriteLine("A boogie program must be specified. See --help");
                ExitWith(ExitCode.COMMAND_LINE_ERROR);
            }

            if (!File.Exists(options.boogieProgramPath))
            {
                Console.WriteLine("Boogie program \"" + options.boogieProgramPath + "\" does not exist");
                ExitWith(ExitCode.COMMAND_LINE_ERROR);
            }


            Program program = null;

            if (options.Defines != null)
            {
                foreach (var define in options.Defines)
                {
                    Console.WriteLine("Adding define \"" + define + "\" to Boogie parser");
                }
            }

            int errors = Microsoft.Boogie.Parser.Parse(options.boogieProgramPath, options.Defines, out program);

            if (errors != 0)
            {
                Console.WriteLine("Failed to parse");
                ExitWith(ExitCode.PARSE_ERROR);
            }

            errors = program.Resolve();

            if (errors != 0)
            {
                Console.WriteLine("Failed to resolve.");
                ExitWith(ExitCode.RESOLVE_ERROR);
            }

            if (options.useModSetTransform > 0)
            {
                // This is useful for Boogie Programs produced by the GPUVerify tool that
                // have had instrumentation added that invalidates the modset attached to
                // procedures. By running the analysis we may modify the modsets attached to
                // procedures in the program to be correct so that Boogie's Type checker doesn't
                // produce an error.
                var modsetAnalyser = new ModSetCollector();
                modsetAnalyser.DoModSetAnalysis(program);
            }

            errors = program.Typecheck();

            if (errors != 0)
            {
                Console.WriteLine("Failed to Typecheck.");
                ExitWith(ExitCode.TYPECHECK_ERROR);
            }


            IStateScheduler scheduler = GetScheduler(options);

            // Limit Depth if necessary
            if (options.MaxDepth >= 0)
            {
                scheduler = new LimitExplicitDepthScheduler(scheduler, options.MaxDepth);
                Console.WriteLine("Using Depth limit:{0}", options.MaxDepth);
            }

            if (options.FailureLimit < 0)
            {
                Console.Error.WriteLine("FailureLimit must be >= 0");
                ExitWith(ExitCode.COMMAND_LINE_ERROR);
            }


            Console.WriteLine("Using Scheduler: {0}", scheduler.ToString());

            var           nonSpeculativeterminationCounter = new TerminationCounter(TerminationCounter.CountType.ONLY_NON_SPECULATIVE);
            var           speculativeTerminationCounter    = new TerminationCounter(TerminationCounter.CountType.ONLY_SPECULATIVE);
            IExprBuilder  builder      = new SimpleExprBuilder(/*immutable=*/ true);
            ISymbolicPool symbolicPool = null;

            if (options.useSymbolicPoolCache > 0)
            {
                throw new Exception("DON'T USE THIS. IT'S BROKEN");
                symbolicPool = new CachingSymbolicPool();
            }
            else
            {
                symbolicPool = new SimpleSymbolicPool();
            }

            Console.WriteLine("Using Symbolic Pool: {0}", symbolicPool.ToString());

            if (options.useConstantFolding > 0)
            {
                if (options.ConstantCaching > 0)
                {
                    Console.WriteLine("Using ConstantCachingExprBuilder");
                    builder = new ConstantCachingExprBuilder(builder);
                }

                builder = new ConstantFoldingExprBuilder(builder);
            }

            // Destroy the solver when we stop using it
            using (var solver = BuildSolverChain(options))
            {
                Executor executor = new Executor(program, scheduler, solver, builder, symbolicPool);

                executor.ExecutorTimeoutReached += delegate(object sender, Executor.ExecutorTimeoutReachedArgs eventArgs)
                {
                    TimeoutHit = true; // Record so we can set the exitcode appropriately later
                    Console.Error.WriteLine("Timeout hit. Trying to kill Executor (may wait for solver)");
                };

                // Check all implementations exist and build list of entry points to execute
                var entryPoints = new List <Implementation>();

                // This is specific to GPUVerify
                if (options.gpuverifyEntryPoints)
                {
                    var kernels = program.TopLevelDeclarations.OfType <Implementation>().Where(impl => QKeyValue.FindBoolAttribute(impl.Attributes, "kernel"));
                    foreach (var kernel in kernels)
                    {
                        entryPoints.Add(kernel);
                    }

                    if (entryPoints.Count() == 0)
                    {
                        Console.WriteLine("Could not find any kernel entry points");
                        ExitWith(ExitCode.ENTRY_POINT_NOT_FOUND_ERROR);
                    }
                }
                else
                {
                    // Set main as default.
                    if (options.entryPoints == null)
                    {
                        options.entryPoints = new List <string>()
                        {
                            "main"
                        }
                    }
                    ;

                    foreach (var implString in options.entryPoints)
                    {
                        Implementation entry = program.TopLevelDeclarations.OfType <Implementation>().Where(i => i.Name == implString).FirstOrDefault();
                        if (entry == null)
                        {
                            Console.WriteLine("Could not find implementation \"" + implString + "\" to use as entry point");
                            ExitWith(ExitCode.ENTRY_POINT_NOT_FOUND_ERROR);
                        }
                        entryPoints.Add(entry);
                    }
                }

                if (options.useInstructionPrinter)
                {
                    Console.WriteLine("Installing instruction printer");
                    var instrPrinter = new InstructionPrinter(Console.Out);
                    instrPrinter.Connect(executor);
                }

                if (options.useCallSequencePrinter)
                {
                    Console.WriteLine("Installing call sequence printer");
                    var callPrinter = new CallPrinter(Console.Out);
                    callPrinter.Connect(executor);
                }

                if (options.gotoAssumeLookAhead > 0)
                {
                    executor.UseGotoLookAhead = true;
                }
                else
                {
                    executor.UseGotoLookAhead = false;
                }

                if (options.ForkAtPredicatedAssign)
                {
                    executor.UseForkAtPredicatedAssign = true;
                }

                if (options.CheckEntryRequires > 0)
                {
                    executor.CheckEntryRequires = true;
                }
                else
                {
                    Console.WriteLine("Warning: Requires at the entry point are not being checked");
                    executor.CheckEntryRequires = false;
                }

                if (options.CheckEntryAxioms > 0)
                {
                    executor.CheckEntryAxioms = true;
                }
                else
                {
                    Console.WriteLine("Warning: Axioms are not being checked");
                    executor.CheckEntryAxioms = false;
                }

                if (options.CheckUniqueVariableDecls > 0)
                {
                    executor.CheckUniqueVariableDecls = true;
                }
                else
                {
                    Console.WriteLine("Warning: Unique variables are not being checked");
                    executor.CheckUniqueVariableDecls = false;
                }

                if (options.GlobalDDE > 0)
                {
                    executor.UseGlobalDDE = true;
                    Console.WriteLine("WARNING: Using GlobalDDE. This may remove unsatisfiable axioms");
                }
                else
                {
                    executor.UseGlobalDDE = false;
                }

                // Just print a message about break points for now.
                executor.BreakPointReached += BreakPointPrinter.handleBreakPoint;

                // Write to the console about context changes
                var contextChangeReporter = new ContextChangedReporter();
                contextChangeReporter.Connect(executor);

                var stateHandler = new TerminationConsoleReporter();
                stateHandler.Connect(executor);

                nonSpeculativeterminationCounter.Connect(executor);
                speculativeTerminationCounter.Connect(executor);

                if (options.FileLogging > 0)
                {
                    SetupFileLoggers(options, executor, solver);
                }

                SetupTerminationCatchers(executor);
                ApplyFilters(executor, options);

                if (options.FailureLimit > 0)
                {
                    var failureLimiter = new FailureLimiter(options.FailureLimit);
                    failureLimiter.Connect(executor);
                    Console.WriteLine("Using failure limit of {0}", options.FailureLimit);
                }

                try
                {
                    // Supply our own PassManager for preparation so we can hook into its events
                    executor.PreparationPassManager = GetPassManager(options);

                    foreach (var entryPoint in entryPoints)
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine("Entering Implementation " + entryPoint.Name + " as entry point");
                        Console.ResetColor();
                        executor.Run(entryPoint, options.timeout);
                    }
                }
                catch (InitialStateTerminated)
                {
                    if (options.CatchExceptions == 0)
                    {
                        throw;
                    }
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine("The initial state terminated. Execution cannot continue");
                    Console.ResetColor();
                    ExitWith(ExitCode.INITIAL_STATE_TERMINATED);
                }
                catch (RecursiveFunctionDetectedException rfdException)
                {
                    if (options.CatchExceptions == 0)
                    {
                        throw;
                    }
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine("Detected the following recursive functions");
                    foreach (var function in rfdException.Functions)
                    {
                        Console.Error.Write(function.Name + ": ");
                        if (function.Body != null)
                        {
                            Console.Error.WriteLine(function.Body.ToString());
                        }

                        if (function.DefinitionAxiom != null)
                        {
                            Console.Error.WriteLine(function.DefinitionAxiom.Expr.ToString());
                        }
                    }
                    Console.ResetColor();
                    ExitWith(ExitCode.RECURSIVE_FUNCTIONS_FOUND_ERROR);
                }
                catch (OutOfMemoryException e)
                {
                    if (options.CatchExceptions == 0)
                    {
                        throw;
                    }
                    Console.Error.WriteLine("Ran out of memory!");
                    Console.Error.WriteLine(e.ToString());
                    ExitWith(ExitCode.OUT_OF_MEMORY);
                }
                catch (NotImplementedException e)
                {
                    if (options.CatchExceptions == 0)
                    {
                        throw;
                    }
                    Console.Error.WriteLine("Feature not implemented!");
                    Console.Error.WriteLine(e.ToString());
                    ExitWith(ExitCode.NOT_IMPLEMENTED_EXCEPTION);
                }
                catch (NotSupportedException e)
                {
                    if (options.CatchExceptions == 0)
                    {
                        throw;
                    }
                    Console.Error.WriteLine("Feature not supported!");
                    Console.Error.WriteLine(e.ToString());
                    ExitWith(ExitCode.NOT_SUPPORTED_EXCEPTION);
                }


                Console.WriteLine("Finished executing");
                DumpStats(executor, solver, nonSpeculativeterminationCounter, speculativeTerminationCounter);
            }

            if (TimeoutHit)
            {
                ExitWith(nonSpeculativeterminationCounter.NumberOfFailures > 0 ? ExitCode.ERRORS_TIMEOUT : ExitCode.NO_ERRORS_TIMEOUT);
                throw new InvalidOperationException("Unreachable");
            }

            var exitCode = nonSpeculativeterminationCounter.NumberOfFailures > 0 ? ExitCode.ERRORS_NO_TIMEOUT : ExitCode.NO_ERRORS_NO_TIMEOUT;

            if (exitCode == ExitCode.NO_ERRORS_NO_TIMEOUT)
            {
                // If no errors were found we may need to pick a different exit code
                // because path exploration may not have been exhaustive due to speculative paths
                // or hitting a bound. This isn't perfect because we may hit a bound and have speculative
                // paths so we could use either exit code in this case.
                if (nonSpeculativeterminationCounter.DisallowedSpeculativePaths > 0 || speculativeTerminationCounter.NumberOfTerminatedStates > 0)
                {
                    exitCode = ExitCode.NO_ERRORS_NO_TIMEOUT_BUT_FOUND_SPECULATIVE_PATHS;
                    Console.WriteLine("NOTE: Bugs may have been missed!");
                }
                else if (nonSpeculativeterminationCounter.DisallowedPathDepths > 0)
                {
                    exitCode = ExitCode.NO_ERRORS_NO_TIMEOUT_BUT_HIT_BOUND;
                    Console.WriteLine("NOTE: Bugs may have been missed!");
                }
            }
            ExitWith(exitCode);
            return((int)exitCode); // This is required to keep the compiler happy.
        }
Esempio n. 17
0
        public void DirectMapCopy()
        {
            p = LoadProgramFrom(@"
            procedure main()
            {
                var x:[int]bool;
                var y:[int]bool;
                x[0] := true;
                x[1] := false;
                assert {:symbooglix_bp ""check_written""} true;

                // copy the map
                y := x;

                assert {:symbooglix_bp ""check_map_copy""} true;
            }

            ", "test.bpl");

            e = GetExecutor(p);
            bool check_written  = false;
            bool check_map_copy = false;
            var  builder        = new SimpleExprBuilder(true);
            var  localVarX      = p.TopLevelDeclarations.OfType <Implementation>().Where(i => i.Name == "main").First().LocVars.Where(v => v.Name == "x").First();
            var  localVarY      = p.TopLevelDeclarations.OfType <Implementation>().Where(i => i.Name == "main").First().LocVars.Where(v => v.Name == "y").First();

            e.BreakPointReached += delegate(object sender, Executor.BreakPointEventArgs eventArgs)
            {
                switch (eventArgs.Name)
                {
                case "check_written":
                    check_written = true;

                    // Check we can read x[0] and x[1] directly
                    var x0 = e.CurrentState.ReadMapVariableInScopeAt(localVarX, new List <Expr>()
                    {
                        builder.ConstantInt(0)
                    });
                    Assert.AreEqual(builder.True, x0);
                    var x1 = e.CurrentState.ReadMapVariableInScopeAt(localVarX, new List <Expr>()
                    {
                        builder.ConstantInt(1)
                    });
                    Assert.AreEqual(builder.False, x1);

                    // Check the full expression form
                    Assert.AreEqual("~sb_x_0[0 := true][1 := false]", e.CurrentState.GetInScopeVariableExpr(localVarX).ToString());
                    break;

                case "check_map_copy":
                    check_map_copy = true;

                    // Check we can read y[0] and y[1] directly
                    var y0 = e.CurrentState.ReadMapVariableInScopeAt(localVarY, new List <Expr>()
                    {
                        builder.ConstantInt(0)
                    });
                    Assert.AreEqual(builder.True, y0);
                    var y1 = e.CurrentState.ReadMapVariableInScopeAt(localVarY, new List <Expr>()
                    {
                        builder.ConstantInt(1)
                    });
                    Assert.AreEqual(builder.False, y1);

                    // Check the full expression form
                    Assert.AreEqual("~sb_x_0[0 := true][1 := false]", e.CurrentState.GetInScopeVariableExpr(localVarX).ToString());
                    Assert.AreEqual("~sb_x_0[0 := true][1 := false]", e.CurrentState.GetInScopeVariableExpr(localVarY).ToString());

                    break;

                default:
                    Assert.Fail("Unexpected breakpoint");
                    break;
                }
            };
            e.Run(GetMain(p));
            Assert.IsTrue(check_written);
            Assert.IsTrue(check_map_copy);
        }
Esempio n. 18
0
 public UninterpretedFunction()
 {
     SymbooglixLibTests.SymbooglixTest.SetupDebug();
     SEB = new SimpleExprBuilder(/*immutable=*/ true);
 }