Search in sources :

Example 16 with IntegerConstraint

use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.

the class TestStringSearch method testIndexOfC.

@Test
public void testIndexOfC() {
    String var1value = "D<E\u001E";
    StringVariable var1 = new StringVariable("var1", var1value);
    IntegerConstant colon_code = new IntegerConstant(35);
    IntegerConstant numeral_code = new IntegerConstant(58);
    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);
    IntegerConstraint constr1 = new IntegerConstraint(index_of_colon, Comparator.EQ, minus_one);
    IntegerConstraint constr2 = new IntegerConstraint(index_of_numeral, Comparator.NE, minus_one);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(constr1);
    constraints.add(constr2);
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution;
    try {
        solution = solve(solver, constraints);
        assertNotNull(solution);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) 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) Test(org.junit.Test)

Example 17 with IntegerConstraint

use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.

the class TestStringSearch method testInsertIndexOfC.

@Test
public void testInsertIndexOfC() {
    String var1value = "D<E\u001Exqaasaksajij1§n";
    StringVariable var1 = new StringVariable("var1", var1value);
    IntegerConstant colon_code = new IntegerConstant(58);
    IntegerConstant minus_one = new IntegerConstant(-1);
    int colon_int_code = (int) ':';
    int concrete_value = var1value.indexOf(colon_int_code);
    StringBinaryToIntegerExpression index_of_colon = new StringBinaryToIntegerExpression(var1, Operator.INDEXOFC, colon_code, (long) concrete_value);
    IntegerConstraint constr1 = new IntegerConstraint(index_of_colon, Comparator.NE, minus_one);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(constr1);
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution;
    try {
        solution = solve(solver, constraints);
        assertNotNull(solution);
    } 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 18 with IntegerConstraint

use of org.evosuite.symbolic.expr.IntegerConstraint 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 19 with IntegerConstraint

use of org.evosuite.symbolic.expr.IntegerConstraint 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 20 with IntegerConstraint

use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.

the class ConstraintNormalizer method normalizeIntegerConstriant.

private static Constraint<?> normalizeIntegerConstriant(IntegerConstraint c) {
    if (c.getLeftOperand() instanceof IntegerComparison) {
        IntegerComparison cmp = (IntegerComparison) c.getLeftOperand();
        int value = ((Number) c.getRightOperand().getConcreteValue()).intValue();
        Comparator op = c.getComparator();
        Expression<Long> cmp_left = cmp.getLeftOperant();
        Expression<Long> cmp_right = cmp.getRightOperant();
        return createIntegerConstraint(cmp_left, op, cmp_right, value);
    } else {
        assert (c.getRightOperand() instanceof IntegerComparison);
        IntegerComparison cmp = (IntegerComparison) c.getRightOperand();
        int value = ((Number) c.getLeftOperand().getConcreteValue()).intValue();
        Comparator op = c.getComparator();
        Expression<Long> cmp_left = cmp.getLeftOperant();
        Expression<Long> cmp_right = cmp.getRightOperant();
        Comparator swap_op = op.swap();
        int swap_value = -value;
        return createIntegerConstraint(cmp_left, swap_op, cmp_right, swap_value);
    }
}
Also used : IntegerComparison(org.evosuite.symbolic.expr.bv.IntegerComparison) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) Comparator(org.evosuite.symbolic.expr.Comparator)

Aggregations

IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)43 Constraint (org.evosuite.symbolic.expr.Constraint)37 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)30 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)30 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)28 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)25 SolverResult (org.evosuite.symbolic.solver.SolverResult)25 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)24 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)9 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)8 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)7 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)7 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)6 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)4 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)3 LinkedList (java.util.LinkedList)2 Vector (java.util.Vector)2 Comparator (org.evosuite.symbolic.expr.Comparator)2 TestCaseStringAppendString (com.examples.with.different.packagename.solver.TestCaseStringAppendString)1