Пример #1
0
        public void SimpleForAllWithTrigger()
        {
            var builder  = GetSimpleBuilder();
            var freeVarX = GetVariable("x", BasicType.Int);
            var xid      = new IdentifierExpr(Token.NoToken, freeVarX);

            var fb       = new FunctionCallBuilder();
            var funcCall = fb.CreateUninterpretedFunctionCall("f", BPLType.Int, new List <BPLType>()
            {
                BPLType.Int
            });
            var body = builder.Gt(builder.UFC(funcCall, xid), xid);

            // Single trigger
            var triggers = new Microsoft.Boogie.Trigger(Token.NoToken,
                                                        /*positive=*/ true,
                                                        new List <Expr>()
            {
                builder.UFC(funcCall, xid)
            }, null);

            var result = builder.ForAll(new List <Variable>()
            {
                freeVarX
            }, body, triggers);

            Assert.AreEqual("(forall x: int :: { f(x) } f(x) > x)", result.ToString());
            CheckIsBoolType(result);
        }
Пример #2
0
        public void simpleUF()
        {
            var builder = GetSimpleBuilder();
            var FCB     = new FunctionCallBuilder();
            var func    = FCB.CreateUninterpretedFunctionCall("foo", BasicType.Bool, new List <Microsoft.Boogie.Type>()
            {
                BasicType.Real,
                BasicType.Int,
                BasicType.GetBvType(8)
            });
            var root = builder.UFC(func, builder.ConstantReal("0.0"), builder.ConstantInt(5), builder.ConstantBV(5, 8));

            Assert.AreEqual("foo(0e0, 5, 5bv8)", root.ToString());
            DuplicateAndCheck(root, builder);
        }
Пример #3
0
        public void TestCase()
        {
            var FCB = new FunctionCallBuilder();

            var functionCall = FCB.CreateUninterpretedFunctionCall("uf", Microsoft.Boogie.Type.Bool, new List <Microsoft.Boogie.Type>()
            {
                Microsoft.Boogie.Type.Int,
                Microsoft.Boogie.Type.Real
            });


            var e = SEB.UFC(functionCall, SEB.ConstantInt(5), SEB.ConstantReal("5.5"));

            // FIXME: This needs to be factored out
            using (var writer = new StringWriter())
            {
                var printer = GetPrinter(writer);
                printer.AddDeclarations(e);
                printer.PrintFunctionDeclarations();
                printer.PrintExpr(e);
                Assert.AreEqual("(declare-fun uf (Int Real ) Bool)" + Environment.NewLine + "(uf 5 5.5  )", writer.ToString());
            }
        }
Пример #4
0
        public void RemoveOneConstraintBasedOnVarsAndFunctions()
        {
            IConstraintManager CM = new ConstraintManager();
            var builder           = GetBuilder();

            // Dummy Boogie variable
            var bv8Type      = Microsoft.Boogie.Type.GetBvType(8);
            var bv8TypeIdent = new TypedIdent(Token.NoToken, "bv8", bv8Type);
            var dummyVarBv   = new GlobalVariable(Token.NoToken, bv8TypeIdent);

            // dummyVar needs a programLocation, otherwise SymbolicVariable constructor raises an exception
            var progLoc = new ProgramLocation(dummyVarBv);

            dummyVarBv.SetMetadata <ProgramLocation>((int)Symbooglix.Annotation.AnnotationIndex.PROGRAM_LOCATION, progLoc);

            var s0 = new SymbolicVariable("s0", dummyVarBv).Expr;
            var s1 = new SymbolicVariable("s1", dummyVarBv).Expr;
            var s2 = new SymbolicVariable("s2", dummyVarBv).Expr;

            // Construct some constraints
            Expr c0 = builder.Eq(builder.BVAND(s0, s1), builder.ConstantBV(0, 8));
            Expr c1 = builder.Eq(s2, builder.ConstantBV(1, 8));

            var FCB        = new FunctionCallBuilder();
            var foobarFunc = FCB.CreateUninterpretedFunctionCall("foobar", bv8Type, new List <Microsoft.Boogie.Type>()
            {
                bv8Type
            });
            // foobar(0bv8) == 0bv8
            Expr c2 = builder.Eq(builder.UFC(foobarFunc, builder.ConstantBV(0, 8)), builder.ConstantBV(0, 8));

            CM.AddConstraint(c0, progLoc);
            CM.AddConstraint(c1, progLoc);
            CM.AddConstraint(c2, progLoc);

            var mockSolver      = new MockSolver();
            var indepenceSolver = new Symbooglix.Solver.ConstraintIndependenceSolver(mockSolver);

            // The query expression does not use the "foobar" function so we don't need to keep constraints on that function
            Expr queryExpr = builder.Eq(builder.BVAND(s1, s2), builder.ConstantBV(0, 8));


            indepenceSolver.ComputeSatisfiability(new Solver.Query(CM, new Constraint(queryExpr)));

            // Check no constraints were removed
            Assert.AreEqual(2, mockSolver.Constraints.Count);
            Assert.AreSame(queryExpr, mockSolver.QueryExpr);

            bool c0Found = false;
            bool c1Found = false;

            foreach (var constraint in mockSolver.Constraints)
            {
                if (c0 == constraint.Condition)
                {
                    c0Found = true;
                }

                if (c1 == constraint.Condition)
                {
                    c1Found = true;
                }
            }

            Assert.IsTrue(c0Found);
            Assert.IsTrue(c1Found);
        }