コード例 #1
0
        public void checkEqualityConstraint(object executor, Executor.BreakPointEventArgs data, Predicate <LiteralExpr> condition)
        {
            // Check that the equality constraint has been stored
            bool found = false;

            // Find the symbolic associated with variable "a".
            var theLocal = e.CurrentState.GetInScopeVariableAndExprByName("a");

            //var symbolic = e.CurrentState.Symbolics.Where( s => s.Origin.AsVariable == theLocal.Key).First();


            foreach (Expr constraint in e.CurrentState.Constraints.ConstraintExprs)
            {
                LiteralExpr literal  = null;
                Variable    symbolic = null;
                found = FindLiteralAssignment.findAnyVariable(constraint, out symbolic, out literal);
                if (found)
                {
                    Assert.IsInstanceOf <SymbolicVariable>(symbolic);
                    var asSym = symbolic as SymbolicVariable;
                    if (asSym.Origin.IsVariable && asSym.Origin.AsVariable == theLocal.Key)
                    {
                        Assert.IsTrue(condition(literal));
                        found = true;
                        break;
                    }
                }
            }
            Assert.IsTrue(found, "Equality constraint not found");
        }
コード例 #2
0
        public void GlobalConstantWithAxiom()
        {
            p = LoadProgramFrom("programs/GlobalConstantWithAxiom.bpl");
            e = GetExecutor(p);
            e.BreakPointReached += delegate(object executor, Executor.BreakPointEventArgs data)
            {
                Assert.IsTrue(data.Name == "entry");
                var constant = p.TopLevelDeclarations.OfType <Constant>().Where(c => c.Name == "a").First();
                Assert.IsTrue(constant is Constant);
                Assert.IsTrue(e.CurrentState.IsInScopeVariable(constant));
                Assert.IsFalse(e.IsSymbolic(constant)); // There is an equality constraint that forces this to be concrete

                // Find the symbolic associated with Constant
                //var relevantSymbolic = e.CurrentState.Symbolics.Where( s => s.Origin.IsVariable && s.Origin.AsVariable == constant).First();

                // Check for the expect equality constraint.
                bool found = false;
                foreach (Expr constraint in e.CurrentState.Constraints.ConstraintExprs)
                {
                    LiteralExpr literal  = null;
                    Variable    symbolic = null;
                    if (FindLiteralAssignment.findAnyVariable(constraint, out symbolic, out literal))
                    {
                        Assert.IsInstanceOf <SymbolicVariable>(symbolic);
                        var asSym = symbolic as SymbolicVariable;
                        if (asSym.Origin.IsVariable && asSym.Origin.AsVariable == constant)
                        {
                            found = true;
                            Assert.IsTrue(literal.isBvConst);
                            Assert.AreEqual(literal.asBvConst.Value.ToInt, 7);
                        }
                    }
                }
                Assert.IsTrue(found, "Did not find expected equality constraint");
            };
            e.Run(GetMain(p));
        }