Example #1
0
        public void AddAssociativityAddNearbyConstants()
        {
            var builderPair = GetSimpleAndConstantFoldingBuilder();
            var sb          = builderPair.Item1;
            var cfb         = builderPair.Item2;

            var x = GetVarAndIdExpr("x", BasicType.GetBvType(8)).Item2;

            Expr foldedResult   = x;
            Expr unfoldedResult = foldedResult;

            for (int index = 1; index <= 3; ++index)
            {
                foldedResult   = cfb.BVADD(cfb.ConstantBV(index, 8), foldedResult);
                unfoldedResult = sb.BVADD(sb.ConstantBV(index, 8), unfoldedResult);
                CheckIsBvType(foldedResult, 8);
                CheckIsBvType(unfoldedResult, 8);
            }
            Assert.AreEqual("BVADD8(6bv8, x)", foldedResult.ToString());
            Assert.AreEqual("BVADD8(3bv8, BVADD8(2bv8, BVADD8(1bv8, x)))", unfoldedResult.ToString());
            Assert.IsFalse(foldedResult.Equals(unfoldedResult));

            var foldedTopAsNAry = ExprUtil.AsBVADD(foldedResult);
            // Check the constant is the top left argument
            var topLeftConstant = ExprUtil.AsLiteral(foldedTopAsNAry.Args[0]);

            Assert.IsNotNull(topLeftConstant);
            CheckIsBvType(topLeftConstant, 8);
            Assert.AreEqual(6, topLeftConstant.asBvConst.Value.ToInt);
        }
Example #2
0
        public void AddAssociativityPropagateConstantUp()
        {
            var builderPair = GetSimpleAndConstantFoldingBuilder();
            var sb          = builderPair.Item1;
            var cfb         = builderPair.Item2;

            Expr foldedResult   = sb.ConstantBV(1, 8);
            Expr unfoldedResult = foldedResult;

            for (int index = 0; index < 3; ++index)
            {
                var x = GetVarAndIdExpr("x" + index.ToString(), BasicType.GetBvType(8)).Item2;
                foldedResult   = cfb.BVADD(x, foldedResult);
                unfoldedResult = sb.BVADD(x, unfoldedResult);
                CheckIsBvType(foldedResult, 8);
                CheckIsBvType(unfoldedResult, 8);
            }
            Assert.AreEqual("BVADD8(1bv8, BVADD8(x2, BVADD8(x1, x0)))", foldedResult.ToString());
            Assert.AreEqual("BVADD8(x2, BVADD8(x1, BVADD8(x0, 1bv8)))", unfoldedResult.ToString());
            Assert.IsFalse(foldedResult.Equals(unfoldedResult));

            var foldedTopAsNAry = ExprUtil.AsBVADD(foldedResult);
            // Check the constant is the top left argument
            var topLeftConstant = ExprUtil.AsLiteral(foldedTopAsNAry.Args[0]);

            Assert.IsNotNull(topLeftConstant);
            CheckIsBvType(topLeftConstant, 8);
            Assert.AreEqual(1, topLeftConstant.asBvConst.Value.ToInt);
        }
Example #3
0
        public void SimpleConcreteAssignmentAndCheckCondition()
        {
            p = LoadProgramFrom(@"
                // Bitvector functions
                function {:bvbuiltin ""bvadd""} bv8add(bv8,bv8) returns(bv8);
                function {:bvbuiltin ""bvugt""} bv8ugt(bv8,bv8) returns(bool);

                procedure main(p1:int, p2:bv8) returns (r:bv8)
                {
                    var a:bv8;
                    var b:bv8;
                    a := 1bv8;
                    b := 2bv8;
                    assert {:symbooglix_bp ""before""} true;
                    r := bv8add(a,b);
                    assert {:symbooglix_bp ""after""} true;
                    assert bv8ugt(r, 0bv8);
                }
            ", "file.bpl");
            e = GetExecutor(p, new DFSStateScheduler(), GetSolver(), /*useConstantFolding*/ false);

            int count = 0;

            e.BreakPointReached += delegate(object sender, Executor.BreakPointEventArgs eventArgs)
            {
                switch (eventArgs.Name)
                {
                case "before":
                    var vAndExpr = e.CurrentState.GetInScopeVariableAndExprByName("r");
                    Assert.IsInstanceOf <IdentifierExpr>(vAndExpr.Value);
                    Assert.IsInstanceOf <SymbolicVariable>((vAndExpr.Value as IdentifierExpr).Decl);
                    break;

                case "after":
                    vAndExpr = e.CurrentState.GetInScopeVariableAndExprByName("r");
                    var asBvugt = ExprUtil.AsBVADD(vAndExpr.Value);
                    Assert.IsNotNull(asBvugt);
                    Assert.AreEqual("BVADD8(1bv8, 2bv8)", asBvugt.ToString());
                    break;

                default:
                    Assert.Fail("unrecognised breakpoint");
                    break;
                }
                ++count;
            };
            var tc = new TerminationCounter();

            tc.Connect(e);
            e.Run(GetMain(p));
            Assert.AreEqual(2, count);
            Assert.AreEqual(1, tc.Sucesses);
            Assert.AreEqual(0, tc.NumberOfFailures);
        }
Example #4
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.BVADD(arg0, arg1);
            var result       = cfb.BVADD(arg0, arg1);

            CheckIsBvType(result, 8);
            CheckIsBvType(simpleResult, 8);
            Assert.IsNull(ExprUtil.AsLiteral(result));
            Assert.IsNotNull(ExprUtil.AsBVADD(result));
            Assert.IsTrue(ExprUtil.StructurallyEqual(result, simpleResult));
        }