Search in sources :

Example 11 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class TestIntegerSearch method testLTArithmetic.

@Test
public void testLTArithmetic() throws SolverEmptyQueryException {
    int var1 = 2;
    int var2 = 1;
    int var3 = 1;
    assertTrue(var1 >= var2 + var3);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.LT, new IntegerBinaryExpression(new IntegerVariable("test2", var2, -1000000, 1000000), Operator.PLUS, new IntegerVariable("test3", var3, -1000000, 1000000), 0L)));
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        if (model.containsKey("test1"))
            var1 = ((Number) model.get("test1")).intValue();
        if (model.containsKey("test2"))
            var2 = ((Number) model.get("test2")).intValue();
        if (model.containsKey("test3"))
            var3 = ((Number) model.get("test3")).intValue();
        assertTrue(var1 < var2 + var3);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 12 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class TestIntegerSearch method mul.

private static IntegerValue mul(IntegerValue left, IntegerValue right) {
    int left_val = left.getConcreteValue().intValue();
    int right_val = right.getConcreteValue().intValue();
    return new IntegerBinaryExpression(left, Operator.MUL, right, (long) left_val * right_val);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint)

Example 13 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class TestIntegerSearch method testGTArithmetic.

@Test
public void testGTArithmetic() throws SolverEmptyQueryException {
    int var1 = 0;
    int var2 = 1;
    int var3 = 1;
    assertTrue(var1 <= var2 + var3);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.GE, new IntegerBinaryExpression(new IntegerVariable("test2", var2, -1000000, 1000000), Operator.PLUS, new IntegerVariable("test3", var3, -1000000, 1000000), 0L)));
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        if (model.containsKey("test1"))
            var1 = ((Number) model.get("test1")).intValue();
        if (model.containsKey("test2"))
            var2 = ((Number) model.get("test2")).intValue();
        if (model.containsKey("test3"))
            var3 = ((Number) model.get("test3")).intValue();
        assertTrue(var1 >= var2 + var3);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 14 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class TestIntegerSearch method testEvosuiteExample3.

@Test
public void testEvosuiteExample3() throws SolverEmptyQueryException {
    Properties.DSE_VARIABLE_RESETS = 3;
    // (var42__SYM(25721) * (var22__SYM(-1043) - 6860)) == 8275
    int var1 = 25721;
    int var2 = -1043;
    IntegerConstant iconst1 = new IntegerConstant(6860);
    IntegerConstant iconst2 = new IntegerConstant(8275);
    IntegerVariable ivar1 = new IntegerVariable("test1", var1, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerVariable ivar2 = new IntegerVariable("test2", var2, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerBinaryExpression sub = new IntegerBinaryExpression(ivar2, Operator.MINUS, iconst1, -7903L);
    IntegerBinaryExpression mul = new IntegerBinaryExpression(ivar1, Operator.MUL, sub, -203273063L);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(mul, Comparator.EQ, iconst2));
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        if (model.containsKey("test1"))
            var1 = ((Number) model.get("test1")).intValue();
        if (model.containsKey("test2"))
            var2 = ((Number) model.get("test2")).intValue();
        assertTrue(var1 * (var2 - 6860) == 8275);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Test(org.junit.Test)

Example 15 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class ArithmeticVM method LXOR.

/**
 * @see http
 *      ://java.sun.com/docs/books/jvms/second_edition/html/Instructions2
 *      .doc8.html#lxor
 */
@Override
public void LXOR() {
    IntegerValue right = env.topFrame().operandStack.popBv64();
    IntegerValue left = env.topFrame().operandStack.popBv64();
    long left_concrete_value = ((Long) left.getConcreteValue()).longValue();
    long right_concrete_value = ((Long) right.getConcreteValue()).longValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewIntegerConstant(right_concrete_value);
    }
    long con = left_concrete_value ^ right_concrete_value;
    IntegerValue intExpr = new IntegerBinaryExpression(left, Operator.IXOR, right, (long) con);
    env.topFrame().operandStack.pushBv64(intExpr);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Aggregations

IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)22 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)14 Constraint (org.evosuite.symbolic.expr.Constraint)12 ArrayList (java.util.ArrayList)8 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)8 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)8 Test (org.junit.Test)8 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)7 SolverResult (org.evosuite.symbolic.solver.SolverResult)7 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)3 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)1 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)1 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)1