Search in sources :

Example 6 with ReferenceConstant

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

the class SymbolicObserver method newIntegerReference.

private ReferenceConstant newIntegerReference(Integer conc_integer, IntegerValue symb_value) {
    ReferenceConstant integerRef = (ReferenceConstant) env.heap.getReference(conc_integer);
    env.heap.putField(Types.JAVA_LANG_INTEGER, SymbolicHeap.$INT_VALUE, conc_integer, integerRef, symb_value);
    return integerRef;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant)

Example 7 with ReferenceConstant

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

the class SymbolicObserver method writeField.

private void writeField(FieldReference lhs, ReferenceExpressionPair readResult, Scope scope) {
    Field field = lhs.getField().getField();
    String className = field.getDeclaringClass().getName().replace('.', '/');
    String fieldName = field.getName();
    Class<?> fieldClass = field.getType();
    Type fieldType = Type.getType(fieldClass);
    if (isValue(fieldType) || fieldType.equals(Type.getType(String.class))) {
        Expression<?> symb_value = readResult.getExpression();
        symb_value = castIfNeeded(fieldType, symb_value);
        VariableReference source = lhs.getSource();
        if (source != null) {
            /* write symbolic expression to instance field */
            String source_name = source.getName();
            Object conc_receiver;
            try {
                conc_receiver = source.getObject(scope);
            } catch (CodeUnderTestException e) {
                throw new RuntimeException(e);
            }
            ReferenceConstant symb_receiver = (ReferenceConstant) symb_references.get(source_name);
            env.heap.putField(className, fieldName, conc_receiver, symb_receiver, symb_value);
        } else {
            /* write symbolic expression to static field */
            env.heap.putStaticField(className, fieldName, symb_value);
        }
    } else {
    /*
			 * ignore writing of references (DSE does not store Reference
			 * fields)
			 */
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Field(java.lang.reflect.Field) Type(org.objectweb.asm.Type) VariableReference(org.evosuite.testcase.variable.VariableReference) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 8 with ReferenceConstant

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

the class SymbolicObserver method newStringReference.

private ReferenceConstant newStringReference(String conc_string, StringValue str_expr) {
    ReferenceConstant stringRef = (ReferenceConstant) env.heap.getReference(conc_string);
    env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_string, stringRef, str_expr);
    return stringRef;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant)

Example 9 with ReferenceConstant

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

the class SymbolicObserver method after.

private void after(ShortPrimitiveStatement statement, Scope scope) {
    short valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Short.MIN_VALUE, Short.MAX_VALUE);
    symb_expressions.put(varRefName, integerVariable);
    Short short_instance;
    try {
        short_instance = (Short) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant shortRef = newShortReference(short_instance, integerVariable);
    symb_references.put(varRefName, shortRef);
}
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 10 with ReferenceConstant

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

the class SymbolicObserver method pushParameterList.

private void pushParameterList(List<VariableReference> parameters, Scope scope, String desc) {
    Type[] argTypes = Type.getArgumentTypes(desc);
    for (int i = 0; i < parameters.size(); i++) {
        VariableReference varRef = parameters.get(i);
        Type argType = argTypes[i];
        ReferenceExpressionPair readResult = this.read(varRef, scope);
        Expression<?> symb_expr = readResult.getExpression();
        ReferenceExpression symb_ref = readResult.getReference();
        if (isValue(argType)) {
            if (symb_expr instanceof RealValue) {
                RealValue realExpr = (RealValue) symb_expr;
                if (isFp32(argType)) {
                    env.topFrame().operandStack.pushFp32(realExpr);
                } else if (isFp64(argType)) {
                    env.topFrame().operandStack.pushFp64(realExpr);
                } else if (isBv32(argType)) {
                    int concV = realExpr.getConcreteValue().intValue();
                    RealToIntegerCast castExpr = new RealToIntegerCast(realExpr, (long) concV);
                    env.topFrame().operandStack.pushBv32(castExpr);
                } else if (isBv64(argType)) {
                    long concV = realExpr.getConcreteValue().longValue();
                    RealToIntegerCast castExpr = new RealToIntegerCast(realExpr, concV);
                    env.topFrame().operandStack.pushBv64(castExpr);
                } else {
                /* unreachable code */
                }
            } else if (symb_expr instanceof IntegerValue) {
                IntegerValue integerExpr = (IntegerValue) symb_expr;
                if (isBv32(argType)) {
                    env.topFrame().operandStack.pushBv32(integerExpr);
                } else if (isBv64(argType)) {
                    env.topFrame().operandStack.pushBv64(integerExpr);
                } else if (isFp32(argType)) {
                    float concV = integerExpr.getConcreteValue().floatValue();
                    IntegerToRealCast castExpr = new IntegerToRealCast(integerExpr, (double) concV);
                    env.topFrame().operandStack.pushFp32(castExpr);
                } else if (isFp64(argType)) {
                    double concV = integerExpr.getConcreteValue().doubleValue();
                    IntegerToRealCast castExpr = new IntegerToRealCast(integerExpr, concV);
                    env.topFrame().operandStack.pushFp64(castExpr);
                } else {
                /* unreachable code */
                }
            } else {
                if (symb_ref.getConcreteValue() == null) {
                    // although this will lead in the JVM to a NPE, we push
                    // a dummy
                    // value to prevent the DSE VM from crashing
                    pushDummyValue(argType);
                } else {
                    // auto unboxing reference
                    ReferenceConstant non_null_symb_ref = (ReferenceConstant) symb_ref;
                    Object conc_object = scope.getObject(varRef);
                    Expression<?> unboxed_expr = unboxReference(argType, conc_object, non_null_symb_ref);
                    pushValue(argType, unboxed_expr);
                }
            }
        } else {
            ReferenceExpression ref = readResult.getReference();
            env.topFrame().operandStack.pushRef(ref);
        }
    }
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) VariableReference(org.evosuite.testcase.variable.VariableReference) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) RealToIntegerCast(org.evosuite.symbolic.expr.bv.RealToIntegerCast) ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) IntegerToRealCast(org.evosuite.symbolic.expr.fp.IntegerToRealCast) 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)

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