Search in sources :

Example 16 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class SymbolicObserver method readArray.

private ReferenceExpressionPair readArray(ArrayIndex rhs, Scope scope) {
    ArrayReference arrayReference = rhs.getArray();
    ReferenceConstant symb_array = (ReferenceConstant) symb_references.get(arrayReference.getName());
    int conc_index = rhs.getArrayIndex();
    Class<?> componentClass = arrayReference.getComponentClass();
    try {
        Object conc_array = arrayReference.getObject(scope);
        if (componentClass.equals(int.class)) {
            int conc_value = Array.getInt(conc_array, conc_index);
            IntegerValue expr = env.heap.array_load(symb_array, conc_index, conc_value);
            ReferenceConstant newIntegerRef = newIntegerReference(conc_value, expr);
            return new ReferenceExpressionPair(newIntegerRef, expr);
        } else if (componentClass.equals(char.class)) {
            char conc_value = Array.getChar(conc_array, conc_index);
            IntegerValue expr = env.heap.array_load(symb_array, conc_index, conc_value);
            ReferenceConstant newCharacterRef = newCharacterReference(conc_value, expr);
            return new ReferenceExpressionPair(newCharacterRef, expr);
        } else if (componentClass.equals(boolean.class)) {
            boolean conc_value = Array.getBoolean(conc_array, conc_index);
            IntegerValue expr = env.heap.array_load(symb_array, conc_index, conc_value ? 1 : 0);
            ReferenceConstant newBooleanRef = newBooleanReference(conc_value, expr);
            return new ReferenceExpressionPair(newBooleanRef, expr);
        } else if (componentClass.equals(byte.class)) {
            byte conc_value = Array.getByte(conc_array, conc_index);
            IntegerValue expr = env.heap.array_load(symb_array, conc_index, conc_value);
            ReferenceConstant newByteRef = newByteReference(conc_value, expr);
            return new ReferenceExpressionPair(newByteRef, expr);
        } else if (componentClass.equals(short.class)) {
            short conc_value = Array.getShort(conc_array, conc_index);
            IntegerValue expr = env.heap.array_load(symb_array, conc_index, conc_value);
            ReferenceConstant newShortRef = newShortReference(conc_value, expr);
            return new ReferenceExpressionPair(newShortRef, expr);
        } else if (componentClass.equals(long.class)) {
            long conc_value = Array.getLong(conc_array, conc_index);
            IntegerValue expr = env.heap.array_load(symb_array, conc_index, conc_value);
            ReferenceConstant newLongRef = newLongReference(conc_value, expr);
            return new ReferenceExpressionPair(newLongRef, expr);
        } else if (componentClass.equals(float.class)) {
            float conc_value = Array.getFloat(conc_array, conc_index);
            RealValue expr = env.heap.array_load(symb_array, conc_index, conc_value);
            ReferenceConstant newFloatRef = newFloatReference(conc_value, expr);
            return new ReferenceExpressionPair(newFloatRef, expr);
        } else if (componentClass.equals(double.class)) {
            double conc_value = Array.getDouble(conc_array, conc_index);
            RealValue expr = env.heap.array_load(symb_array, conc_index, conc_value);
            ReferenceConstant newDoubleRef = newDoubleReference(conc_value, expr);
            return new ReferenceExpressionPair(newDoubleRef, expr);
        } else {
            Object conc_value = Array.get(conc_array, conc_index);
            if (conc_value instanceof String) {
                StringValue expr = env.heap.array_load(symb_array, conc_index, (String) conc_value);
                ReferenceConstant newStringRef = newStringReference((String) conc_value, expr);
                return new ReferenceExpressionPair(newStringRef, expr);
            } else {
                ReferenceExpression ref = env.heap.getReference(conc_value);
                if (conc_value != null && isWrapper(conc_value)) {
                    ReferenceConstant nonNullRef = (ReferenceConstant) ref;
                    Expression<?> expr = findOrCreate(conc_value, nonNullRef);
                    return new ReferenceExpressionPair(ref, expr);
                } else {
                    return new ReferenceExpressionPair(ref, null);
                }
            }
        }
    } catch (CodeUnderTestException e) {
        throw new RuntimeException(e);
    }
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) ArrayReference(org.evosuite.testcase.variable.ArrayReference) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException) ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) PrimitiveExpression(org.evosuite.testcase.statements.PrimitiveExpression) Expression(org.evosuite.symbolic.expr.Expression) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 17 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(IntPrimitiveStatement statement, Scope scope) {
    int valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Integer.MIN_VALUE, Integer.MAX_VALUE);
    symb_expressions.put(varRefName, integerVariable);
    Integer integer_instance;
    try {
        integer_instance = (Integer) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant integerRef = newIntegerReference(integer_instance, integerVariable);
    symb_references.put(varRefName, integerRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 18 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class SymbolicObserver method newByteReference.

private ReferenceConstant newByteReference(Byte conc_byte, IntegerValue symb_value) {
    ReferenceConstant byteRef = (ReferenceConstant) env.heap.getReference(conc_byte);
    env.heap.putField(Types.JAVA_LANG_BYTE, SymbolicHeap.$BYTE_VALUE, conc_byte, byteRef, symb_value);
    return byteRef;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant)

Example 19 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class SymbolicObserver method newBooleanReference.

private ReferenceConstant newBooleanReference(Boolean conc_boolean, IntegerValue symb_value) {
    ReferenceConstant booleanRef = (ReferenceConstant) env.heap.getReference(conc_boolean);
    env.heap.putField(Types.JAVA_LANG_BOOLEAN, SymbolicHeap.$BOOLEAN_VALUE, conc_boolean, booleanRef, symb_value);
    return booleanRef;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant)

Example 20 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(MethodStatement statement, Scope scope) {
    String owner = statement.getMethod().getDeclaringClass().getName().replace('.', '/');
    String name = statement.getMethod().getName();
    String desc = Type.getMethodDescriptor(statement.getMethod().getMethod());
    Type returnType = Type.getReturnType(statement.getMethod().getMethod());
    VariableReference varRef = statement.getReturnValue();
    String varName = varRef.getName();
    try {
        if (varRef.getType().equals(void.class)) {
            VM.CALL_RESULT(owner, name, desc);
        } else if (returnType.equals(Type.INT_TYPE)) {
            Integer res = (Integer) varRef.getObject(scope);
            VM.CALL_RESULT(res.intValue(), owner, name, desc);
            IntegerValue intExpr = env.topFrame().operandStack.popBv32();
            ReferenceConstant newIntegerRef = newIntegerReference(res, intExpr);
            symb_references.put(varName, newIntegerRef);
            symb_expressions.put(varName, intExpr);
        } else if (returnType.equals(Type.BOOLEAN_TYPE)) {
            Boolean res = (Boolean) varRef.getObject(scope);
            VM.CALL_RESULT(res.booleanValue(), owner, name, desc);
            IntegerValue intExpr = env.topFrame().operandStack.popBv32();
            ReferenceConstant newBooleanRef = newBooleanReference(res, intExpr);
            symb_references.put(varName, newBooleanRef);
            symb_expressions.put(varName, intExpr);
        } else if (returnType.equals(Type.DOUBLE_TYPE)) {
            Double res = (Double) varRef.getObject(scope);
            VM.CALL_RESULT(res.doubleValue(), owner, name, desc);
            RealValue realExpr = env.topFrame().operandStack.popFp64();
            ReferenceConstant newDoubleRef = newDoubleReference(res, realExpr);
            symb_references.put(varName, newDoubleRef);
            symb_expressions.put(varName, realExpr);
        } else if (returnType.equals(Type.FLOAT_TYPE)) {
            Float res = (Float) varRef.getObject(scope);
            VM.CALL_RESULT(res.floatValue(), owner, name, desc);
            RealValue realExpr = env.topFrame().operandStack.popFp32();
            ReferenceConstant newFloatRef = newFloatReference(res, realExpr);
            symb_references.put(varName, newFloatRef);
            symb_expressions.put(varName, realExpr);
        } else if (returnType.equals(Type.LONG_TYPE)) {
            Long res = (Long) varRef.getObject(scope);
            VM.CALL_RESULT(res.longValue(), owner, name, desc);
            IntegerValue intExpr = env.topFrame().operandStack.popBv64();
            ReferenceConstant newBooleanRef = newLongReference(res, intExpr);
            symb_references.put(varName, newBooleanRef);
            symb_expressions.put(varName, intExpr);
        } else if (returnType.equals(Type.SHORT_TYPE)) {
            Short res = (Short) varRef.getObject(scope);
            VM.CALL_RESULT(res.shortValue(), owner, name, desc);
            IntegerValue intExpr = env.topFrame().operandStack.popBv32();
            ReferenceConstant newShortRef = newShortReference(res, intExpr);
            symb_references.put(varName, newShortRef);
            symb_expressions.put(varName, intExpr);
        } else if (returnType.equals(Type.BYTE_TYPE)) {
            Byte res = (Byte) varRef.getObject(scope);
            VM.CALL_RESULT(res.byteValue(), owner, name, desc);
            IntegerValue intExpr = env.topFrame().operandStack.popBv32();
            ReferenceConstant newByteRef = newByteReference(res, intExpr);
            symb_references.put(varName, newByteRef);
            symb_expressions.put(varName, intExpr);
        } else if (returnType.equals(Type.CHAR_TYPE)) {
            Character res = (Character) varRef.getObject(scope);
            VM.CALL_RESULT(res.charValue(), owner, name, desc);
            IntegerValue intExpr = env.topFrame().operandStack.popBv32();
            ReferenceConstant newCharacterRef = newCharacterReference(res, intExpr);
            symb_references.put(varName, newCharacterRef);
            symb_expressions.put(varName, intExpr);
        } else {
            Object res = varRef.getObject(scope);
            VM.CALL_RESULT(res, owner, name, desc);
            ReferenceExpression ref = env.topFrame().operandStack.peekRef();
            if (res != null && res instanceof String) {
                String string = (String) res;
                ReferenceConstant newStringRef = (ReferenceConstant) env.heap.getReference(string);
                StringValue str_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, string, newStringRef, string);
                symb_references.put(varName, newStringRef);
                symb_expressions.put(varName, str_expr);
            } else {
                symb_references.put(varName, ref);
                if (res != null && isWrapper(res)) {
                    ReferenceConstant nonNullRef = (ReferenceConstant) ref;
                    Expression<?> expr = findOrCreate(res, nonNullRef);
                    symb_expressions.put(varName, expr);
                }
            }
        }
    } catch (CodeUnderTestException e) {
        throw new RuntimeException(e);
    }
    // dispose all other arguments
    env.topFrame().operandStack.clearOperands();
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) VariableReference(org.evosuite.testcase.variable.VariableReference) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException) ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Aggregations

ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)99 StringValue (org.evosuite.symbolic.expr.str.StringValue)39 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)32 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)18 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)16 VariableReference (org.evosuite.testcase.variable.VariableReference)14 Type (org.objectweb.asm.Type)12 RealValue (org.evosuite.symbolic.expr.fp.RealValue)11 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)11 Expression (org.evosuite.symbolic.expr.Expression)9 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)8 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)6 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)5 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)4 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)3 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)3 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)3 StringReaderExpr (org.evosuite.symbolic.expr.reader.StringReaderExpr)3