Search in sources :

Example 76 with IntegerValue

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

the class ArithmeticVM method IREM.

/**
 * Modulo -- Remainder -- %
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#irem
 */
@Override
public void IREM(int rhsValue) {
    IntegerValue right = env.topFrame().operandStack.popBv32();
    IntegerValue left = env.topFrame().operandStack.popBv32();
    if (zeroViolation(right, rhsValue))
        return;
    int left_concrete_value = ((Long) left.getConcreteValue()).intValue();
    int right_concrete_value = ((Long) right.getConcreteValue()).intValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewIntegerConstant(right_concrete_value);
    }
    int con = left_concrete_value % right_concrete_value;
    IntegerValue intExpr = ExpressionFactory.rem(left, right, (long) con);
    env.topFrame().operandStack.pushBv32(intExpr);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 77 with IntegerValue

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

the class ArithmeticVM method I2L.

/**
 * int --> long
 *
 * This conversion is exact = preserve all information.
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#i2l
 */
@Override
public void I2L() {
    IntegerValue intExpr = env.topFrame().operandStack.popBv32();
    env.topFrame().operandStack.pushBv64(intExpr);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 78 with IntegerValue

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

the class ArithmeticVM method IXOR.

/**
 * bitwise XOR
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#ixor
 */
@Override
public void IXOR() {
    IntegerValue right = env.topFrame().operandStack.popBv32();
    IntegerValue left = env.topFrame().operandStack.popBv32();
    int left_concrete_value = ((Long) left.getConcreteValue()).intValue();
    int right_concrete_value = ((Long) right.getConcreteValue()).intValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewIntegerConstant(right_concrete_value);
    }
    int con = left_concrete_value ^ right_concrete_value;
    IntegerValue intExpr = new IntegerBinaryExpression(left, Operator.IXOR, right, (long) con);
    env.topFrame().operandStack.pushBv32(intExpr);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 79 with IntegerValue

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

the class ArithmeticVM method LCMP.

/**
 * <pre>
 * (a > b)  ==>  1
 * (a == b) ==>  0
 * (a < b)  ==> -1
 * </pre>
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc8.html#lcmp
 */
@Override
public void LCMP() {
    IntegerValue right = env.topFrame().operandStack.popBv64();
    IntegerValue left = env.topFrame().operandStack.popBv64();
    long left_concrete_value = (Long) left.getConcreteValue();
    long right_concrete_value = (Long) right.getConcreteValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewIntegerConstant(right_concrete_value);
    }
    int concrete_value = 0;
    if (left_concrete_value == right_concrete_value) {
        concrete_value = 0;
    } else if (left_concrete_value > right_concrete_value) {
        concrete_value = 1;
    } else {
        assert left_concrete_value < right_concrete_value;
        concrete_value = -1;
    }
    IntegerComparison intComp = new IntegerComparison(left, right, (long) concrete_value);
    env.topFrame().operandStack.pushBv32(intComp);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerComparison(org.evosuite.symbolic.expr.bv.IntegerComparison) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 80 with IntegerValue

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

the class HeapVM method GETSTATIC.

/**
 * GetStatic mypackage/MyClass fieldName FieldType
 *
 * @param owner
 *            name of a class or interface.
 * @param fieldName
 *            name of the field to be read. The owner class or interface
 *            itself my have declared this field. If owner is a class, then
 *            this field may also be declared by a - super-class of the
 *            owner class, or by a - interface implemented by (a super-class
 *            of) the owner class.
 *
 *            http://java.sun.com/docs/books/jvms/second_edition/html/
 *            Instructions2.doc5.html#getstatic
 */
@Override
public void GETSTATIC(String owner, String fieldName, String desc) {
    /**
     * Prepare Class
     */
    // type name given in
    Class<?> claz = env.ensurePrepared(owner);
    // bytecode
    // field may be
    Field concrete_field = resolveField(claz, fieldName);
    // declared by
    // interface
    Class<?> declaringClass = concrete_field.getDeclaringClass();
    if (declaringClass.isInterface()) {
        /*
			 * Unlikely that we ever get here. Java compiler probably computes
			 * value of this (final) field and replaces any
			 * "getstatic MyInterface myField" by "sipush fieldValue" or such.
			 * Even if we get here, there should be no need to prepare this
			 * field, as there has to be an explicit initialization, hence a
			 * <clinit>().
			 */
        logger.debug("Do we have to prepare the static fields of an interface?");
        env.ensurePrepared(declaringClass);
    }
    boolean isAccessible = concrete_field.isAccessible();
    if (!isAccessible) {
        concrete_field.setAccessible(true);
    }
    /**
     * First, Get symbolic expression. If no symbolic expression exists, use
     * concrete value. Then, update operand stack according to type
     */
    Type type = Type.getType(desc);
    try {
        if (type.equals(Type.INT_TYPE)) {
            int value = concrete_field.getInt(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.CHAR_TYPE)) {
            char value = concrete_field.getChar(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.SHORT_TYPE)) {
            short value = concrete_field.getShort(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.BOOLEAN_TYPE)) {
            boolean booleanValue = concrete_field.getBoolean(null);
            int value = booleanValue ? 1 : 0;
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.BYTE_TYPE)) {
            byte value = concrete_field.getByte(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.LONG_TYPE)) {
            long value = concrete_field.getLong(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, value);
            env.topFrame().operandStack.pushBv64(intExpr);
        } else if (type.equals(Type.FLOAT_TYPE)) {
            float value = concrete_field.getFloat(null);
            RealValue fp32 = (RealValue) env.heap.getStaticField(owner, fieldName, (double) value);
            env.topFrame().operandStack.pushFp32(fp32);
        } else if (type.equals(Type.DOUBLE_TYPE)) {
            double value = concrete_field.getDouble(null);
            RealValue fp64 = (RealValue) env.heap.getStaticField(owner, fieldName, value);
            env.topFrame().operandStack.pushFp64(fp64);
        } else {
            Object value = concrete_field.get(null);
            ReferenceExpression ref = env.heap.getReference(value);
            env.topFrame().operandStack.pushRef(ref);
        }
        if (!isAccessible) {
            concrete_field.setAccessible(false);
        }
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Field(java.lang.reflect.Field) Type(org.objectweb.asm.Type) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

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