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));
        }
        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);
        }
        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));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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());
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }