Search in sources :

Example 91 with IntegerValue

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

the class HeapVM method IALOAD.

/**
 * Load an int value from an array and push it on the stack
 *
 * ..., arrayref, index ==> ..., value
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#iaload
 */
@Override
public void IALOAD(Object conc_array, int conc_index) {
    // pop symbolic arguments
    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 = (ReferenceExpression) 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;
    int bv32 = Array.getInt(conc_array, conc_index);
    IntegerValue c = env.heap.array_load(symb_array, conc_index, (long) bv32);
    env.topFrame().operandStack.pushBv32(c);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 92 with IntegerValue

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

the class JumpVM method IF_ICMPEQ.

/**
 * (left == right). (left != right) is just (not (left == right)).
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#if_icmpcond
 */
@Override
public void IF_ICMPEQ(String className, String methName, int branchIndex, int left, int right) {
    IntegerValue rightOp = env.topFrame().operandStack.popBv32();
    IntegerValue leftOp = env.topFrame().operandStack.popBv32();
    IntegerConstraint cnstr;
    if (left == right)
        // "True" branch
        cnstr = ConstraintFactory.eq(leftOp, rightOp);
    else
        // "False" branch
        cnstr = ConstraintFactory.neq(leftOp, rightOp);
    // add branch condition iif local constraint is concrete
    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)

Example 93 with IntegerValue

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

the class JumpVM method IF_ICMPGT.

/**
 * (left > right) is just (right < left). (left <= right) is just (not (left
 * > right)).
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#if_icmpcond
 */
@Override
public void IF_ICMPGT(String className, String methName, int branchIndex, int left, int right) {
    // FIXME: Replace following five instructions with SWAP
    IntegerValue rightBv = env.topFrame().operandStack.popBv32();
    IntegerValue leftBv = env.topFrame().operandStack.popBv32();
    env.topFrame().operandStack.pushBv32(rightBv);
    env.topFrame().operandStack.pushBv32(leftBv);
    IF_ICMPLT(className, methName, branchIndex, right, left);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 94 with IntegerValue

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

the class JumpVM method LOOKUPSWITCH.

/**
 * <b>switch</b> statement whose cases may not be numbered consecutively.
 * I.e., there may be holes (missing targets) between the lowest and highest
 * target.
 *
 * <p>
 * Very similar to {@link #TABLESWITCH}. The main difference is that here we
 * are given a list of explicit goals. Tableswitch defines its goals
 * implicitly, between min and max.
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc8.html#lookupswitch
 */
@Override
public void LOOKUPSWITCH(String className, String methName, int branchIndex, int goalConcrete, int[] targetsConcrete) {
    // TODO: target array remains constant. Do we really need to create and
    // pass
    // this array every time as a paremeter?
    final IntegerValue goal = env.topFrame().operandStack.popBv32();
    Vector<IntegerConstraint> constraints = new Vector<IntegerConstraint>();
    for (int targetConcrete : targetsConcrete) {
        IntegerConstant integerConstant = ExpressionFactory.buildNewIntegerConstant(targetConcrete);
        IntegerConstraint constraint;
        if (goalConcrete == targetConcrete) {
            constraint = ConstraintFactory.eq(goal, integerConstant);
            constraints.add(constraint);
            break;
        } else {
            constraint = ConstraintFactory.neq(goal, integerConstant);
            constraints.add(constraint);
        }
    }
    for (int i = 0; i < constraints.size() - 1; i++) {
        IntegerConstraint cnstrnt = constraints.get(i);
        if (cnstrnt.getLeftOperand().containsSymbolicVariable() || cnstrnt.getRightOperand().containsSymbolicVariable())
            pc.addSupportingConstraint(cnstrnt);
    }
    // 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 95 with IntegerValue

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

the class JumpVM method IF_ICMPLT.

/**
 * (left < right). (left >= right) is just (not (left < right)).
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#if_icmpcond
 */
@Override
public void IF_ICMPLT(String className, String methName, int branchIndex, int left, int right) {
    IntegerValue rightBv = env.topFrame().operandStack.popBv32();
    IntegerValue leftBv = env.topFrame().operandStack.popBv32();
    IntegerConstraint cnstr;
    if (left < right)
        // True Branch
        cnstr = ConstraintFactory.lt(leftBv, rightBv);
    else
        // False branch
        cnstr = ConstraintFactory.gte(leftBv, rightBv);
    // add branch condition iif local constraint is concrete
    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)

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