Search in sources :

Example 31 with IntegerConstant

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

the class TestStringSearch method testIndexOfC2.

@Test
public void testIndexOfC2() {
    String var1value = ":cc]#0l";
    StringVariable var1 = new StringVariable("var0", var1value);
    IntegerConstant colon_code = new IntegerConstant(58);
    IntegerConstant numeral_code = new IntegerConstant(35);
    IntegerConstant minus_one = new IntegerConstant(-1);
    StringBinaryToIntegerExpression index_of_colon = new StringBinaryToIntegerExpression(var1, Operator.INDEXOFC, colon_code, -1L);
    StringBinaryToIntegerExpression index_of_numeral = new StringBinaryToIntegerExpression(var1, Operator.INDEXOFC, numeral_code, -1L);
    /*
		 * Here we are trying to modify the string such that the first '#' comes
		 * before the first ':', and both are present
		 */
    IntegerConstraint constr1 = new IntegerConstraint(index_of_colon, Comparator.NE, minus_one);
    IntegerConstraint constr2 = new IntegerConstraint(index_of_numeral, Comparator.NE, minus_one);
    IntegerConstraint constr3 = new IntegerConstraint(index_of_numeral, Comparator.LT, index_of_colon);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(constr1);
    constraints.add(constr2);
    constraints.add(constr3);
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution = null;
    try {
        /*
			 * The constraint is not trivial, as there are search plateaus. So
			 * it is ok if sometimes it fails (tried 10 times, failed 3).
			 */
        final int TRIES = 20;
        for (int i = 0; i < TRIES; i++) {
            solution = solve(solver, constraints);
            if (solution != null) {
                break;
            }
        }
        assertNotNull(solution);
        String result = solution.get("var0").toString();
        int colonPos = result.indexOf(':');
        int numeralPos = result.indexOf('#');
        assertTrue("Colon not found in " + result, colonPos >= 0);
        assertTrue("Numeral not found in " + result, numeralPos >= 0);
        assertTrue(colonPos > numeralPos);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) ArrayList(java.util.ArrayList) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Test(org.junit.Test)

Example 32 with IntegerConstant

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

the class ArithmeticVM method IINC.

/**
 * Increment i-th local (int) variable by constant (int) value
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#iinc
 */
@Override
public void IINC(int i, int value) {
    IntegerConstant right = ExpressionFactory.buildNewIntegerConstant(value);
    IntegerValue left = env.topFrame().localsTable.getBv32Local(i);
    int left_concrete_value = ((Long) left.getConcreteValue()).intValue();
    int right_concrete_value = value;
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
    }
    int con = left_concrete_value + right_concrete_value;
    IntegerValue intExpr = ExpressionFactory.add(left, right, (long) con);
    env.topFrame().localsTable.setBv32Local(i, intExpr);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 33 with IntegerConstant

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

the class ArithmeticVM method zeroViolation.

private boolean zeroViolation(IntegerValue value, long valueConcrete) {
    IntegerConstant zero = ExpressionFactory.ICONST_0;
    IntegerConstraint zeroCheck;
    if (valueConcrete == 0)
        zeroCheck = ConstraintFactory.eq(value, zero);
    else
        zeroCheck = ConstraintFactory.neq(value, zero);
    if (zeroCheck.getLeftOperand().containsSymbolicVariable() || zeroCheck.getRightOperand().containsSymbolicVariable())
        pathConstraint.addSupportingConstraint(zeroCheck);
    if (valueConcrete == 0) {
        // JVM will throw an exception
        return true;
    }
    return false;
}
Also used : IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 34 with IntegerConstant

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

the class CallVM method METHOD_BEGIN_PARAM.

@Override
public void METHOD_BEGIN_PARAM(int nr, int index, long value) {
    if (!env.callerFrame().weInvokedInstrumentedCode()) {
        IntegerConstant literal_value = ExpressionFactory.buildNewIntegerConstant(value);
        env.topFrame().localsTable.setBv64Local(index, literal_value);
    }
}
Also used : IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 35 with IntegerConstant

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

the class CallVM method CALL_RESULT.

@Override
public void CALL_RESULT(long res, String owner, String name, String desc) {
    CALL_RESULT(owner, name, desc);
    if (env.topFrame().weInvokedInstrumentedCode()) {
        // RETURN already did it
        return;
    } else {
        /**
         * We are returning from uninstrumented code. This is the only way
         * of storing the uninstrumented return value to the symbolic state.
         */
        IntegerConstant value = ExpressionFactory.buildNewIntegerConstant(res);
        env.topFrame().operandStack.pushBv64(value);
    }
}
Also used : IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Aggregations

IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)65 Constraint (org.evosuite.symbolic.expr.Constraint)42 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)42 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)36 Test (org.junit.Test)36 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)35 ArrayList (java.util.ArrayList)34 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)29 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)26 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)23 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)17 SolverResult (org.evosuite.symbolic.solver.SolverResult)14 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)13 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)12 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)7 Expression (org.evosuite.symbolic.expr.Expression)6 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)5 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)5 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)3