Example #1
0
 public void FollowElse()
 {
     p = LoadProgramFrom(@"
         procedure main()
         {
             var a:int;
             var b:int;
             var old_b:int;
             old_b := b;
             assume a < 0;
             b := if a > 0 then 1 else b;
             assert {:symbooglix_bp ""follow_else""} b == old_b;
         }
         ", "test.bpl");
     Run(0, 1, (object sender, Executor.BreakPointEventArgs e) =>
     {
         Assert.AreEqual("follow_else", e.Name);
         Executor executor = sender as Executor;
         Assert.IsNotNull(executor);
         var pair = executor.CurrentState.GetInScopeVariableAndExprByName("b");
         var id   = ExprUtil.AsIdentifer(pair.Value);
         Assert.IsNotNull(id);
         Assert.IsInstanceOf <SymbolicVariable>(id.Decl);
     });
 }
Example #2
0
        public void simpleHavoc()
        {
            p = LoadProgramFrom(@"
                procedure main()
                {
                    var a:int;
                    a := 1;
                    assert {:symbooglix_bp ""a_is_concrete""} true;
                    havoc a;
                    assert {:symbooglix_bp ""a_is_symbolic""} true;
                }

                ", "test.bpl");
            e = GetExecutor(p, new DFSStateScheduler(), GetSolver());
            int counter = 0;
            KeyValuePair <Variable, Expr>?aBefore = null;

            e.BreakPointReached += delegate(object sender, Executor.BreakPointEventArgs eventArgs)
            {
                switch (eventArgs.Name)
                {
                case "a_is_concrete":
                    aBefore = e.CurrentState.GetInScopeVariableAndExprByName("a");
                    var asLit = ExprUtil.AsLiteral(aBefore.Value.Value);
                    Assert.IsNotNull(asLit);
                    Assert.IsTrue(asLit.isBigNum);
                    Assert.AreEqual(Microsoft.Basetypes.BigNum.FromInt(1), asLit.asBigNum);
                    break;

                case "a_is_symbolic":
                    var aAfter = e.CurrentState.GetInScopeVariableAndExprByName("a");
                    Assert.IsTrue(aBefore != null && aBefore.HasValue);
                    Assert.AreNotSame(aBefore.Value, aAfter.Value);
                    var asId = ExprUtil.AsIdentifer(aAfter.Value);
                    Assert.IsNotNull(asId);
                    break;

                default:
                    Assert.Fail("Unrecognised breakpoint");
                    break;
                }
                ++counter;
            };

            e.Run(GetMain(p));
            Assert.AreEqual(2, counter);
        }