Search in sources :

Example 51 with IntegerValue

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

the class HeapVM method IASTORE.

/**
 * Store the top operand stack value into an array
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#iastore
 */
@Override
public void IASTORE(Object conc_array, int conc_index) {
    // pop arguments
    IntegerValue symb_value = env.topFrame().operandStack.popBv32();
    IntegerValue symb_index = env.topFrame().operandStack.popBv32();
    ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
    /* check reference initialization */
    env.heap.initializeReference(conc_array, array_ref);
    /* null-check */
    if (nullReferenceViolation(array_ref, conc_array)) {
        return;
    }
    /* negative index */
    if (negativeIndexViolation(conc_index, symb_index)) {
        return;
    }
    /* out of bound index */
    ReferenceExpression symb_array = array_ref;
    int conc_array_length = Array.getLength(conc_array);
    IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
    if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
        return;
    env.heap.array_store(conc_array, symb_array, conc_index, symb_value);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 52 with IntegerValue

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

the class HeapVM method ARRAYLENGTH.

@Override
public void ARRAYLENGTH(Object conc_array) {
    /* get symbolic arguments */
    ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
    /* check reference initialization */
    env.heap.initializeReference(conc_array, array_ref);
    /* null-check */
    if (nullReferenceViolation(array_ref, conc_array)) {
        return;
    }
    int conc_array_length = Array.getLength(conc_array);
    ReferenceExpression symb_array_ref = (ReferenceExpression) array_ref;
    IntegerValue symb_array_length = (IntegerValue) env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array_ref, conc_array_length);
    env.topFrame().operandStack.pushBv32(symb_array_length);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 53 with IntegerValue

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

the class JumpVM method TABLESWITCH.

/* switch */
/**
 * <b>switch</b> statement that has consecutively numbered cases. I.e.,
 * there are no holes (missing targets) between the lowest and highest
 * target. Hence the compiler does not need to translate the case values to
 * offsets.
 *
 * <p>
 * We treat the switch statement as a nested if in order lowest to highest
 * index as follows.
 *
 * <pre>
 * if (x==lowest) ..
 * else
 * {
 *   if (x==second_lowest) ..
 *   else
 *   {
 *     if ..
 * </pre>
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc14.html#tableswitch
 */
@Override
public void TABLESWITCH(String className, String methName, int branchIndex, int goalConcrete, int min, int max) {
    final IntegerValue value = env.topFrame().operandStack.popBv32();
    Vector<IntegerConstraint> constraints = new Vector<IntegerConstraint>();
    // process each time in the same order: lowest to highest target
    for (int i = min; i <= max; i++) {
        IntegerConstant literal = ExpressionFactory.buildNewIntegerConstant(i);
        IntegerConstraint constraint;
        if (goalConcrete == i) {
            constraint = ConstraintFactory.eq(value, literal);
            constraints.add(constraint);
            break;
        } else {
            constraint = ConstraintFactory.neq(value, literal);
            constraints.add(constraint);
        }
    }
    for (int i = 0; i < constraints.size() - 1; i++) {
        IntegerConstraint cnstrt = constraints.get(i);
        if (cnstrt.getLeftOperand().containsSymbolicVariable() || cnstrt.getRightOperand().containsSymbolicVariable())
            pc.addSupportingConstraint(cnstrt);
    }
    // add branch condition iif local constraint is concrete
    IntegerConstraint cnstr = constraints.get(constraints.size() - 1);
    if (cnstr.getLeftOperand().containsSymbolicVariable() || cnstr.getRightOperand().containsSymbolicVariable())
        pc.addBranchCondition(className, methName, branchIndex, cnstr);
}
Also used : IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) Vector(java.util.Vector) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 54 with IntegerValue

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

the class SymbolicHeap method array_load.

public IntegerValue array_load(ReferenceExpression symb_array, int conc_index, long conc_value) {
    Map<Integer, Expression<?>> symb_array_contents = getOrCreateSymbolicArray(symb_array);
    IntegerValue symb_value = (IntegerValue) symb_array_contents.get(conc_index);
    if (symb_value == null || ((Long) symb_value.getConcreteValue()).longValue() != conc_value) {
        symb_value = ExpressionFactory.buildNewIntegerConstant(conc_value);
        symb_array_contents.remove(conc_index);
    }
    return symb_value;
}
Also used : Expression(org.evosuite.symbolic.expr.Expression) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 55 with IntegerValue

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

the class SymbolicHeap method getStaticField.

public IntegerValue getStaticField(String owner, String name, long conc_value) {
    FieldKey k = new FieldKey(owner, name);
    IntegerValue symb_value = (IntegerValue) symb_static_fields.get(k);
    if (symb_value == null || ((Long) symb_value.getConcreteValue()).longValue() != conc_value) {
        symb_value = ExpressionFactory.buildNewIntegerConstant(conc_value);
        symb_static_fields.remove(k);
    }
    return symb_value;
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Aggregations

IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)117 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)48 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)32 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)27 RealValue (org.evosuite.symbolic.expr.fp.RealValue)22 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)14 Expression (org.evosuite.symbolic.expr.Expression)8 StringValue (org.evosuite.symbolic.expr.str.StringValue)8 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)7 Type (org.objectweb.asm.Type)7 RealToIntegerCast (org.evosuite.symbolic.expr.bv.RealToIntegerCast)6 IntegerToRealCast (org.evosuite.symbolic.expr.fp.IntegerToRealCast)6 IntegerUnaryExpression (org.evosuite.symbolic.expr.bv.IntegerUnaryExpression)5 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)4 ArrayList (java.util.ArrayList)3 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)3 Field (java.lang.reflect.Field)2 BigInteger (java.math.BigInteger)2 Vector (java.util.Vector)2 Constraint (org.evosuite.symbolic.expr.Constraint)2