Search in sources :

Example 21 with VariableReference

use of org.evosuite.testcase.variable.VariableReference 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)

Example 22 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(FunctionalMockStatement statement, Scope scope) {
    Type returnType = Type.getType(statement.getReturnClass());
    VariableReference varRef = statement.getReturnValue();
    String varName = varRef.getName();
    try {
        if (varRef.getType().equals(void.class)) {
        } else if (returnType.equals(Type.INT_TYPE) || returnType.equals(Type.BOOLEAN_TYPE) || returnType.equals(Type.DOUBLE_TYPE) || returnType.equals(Type.FLOAT_TYPE) || returnType.equals(Type.LONG_TYPE) || returnType.equals(Type.SHORT_TYPE) || returnType.equals(Type.BYTE_TYPE) || returnType.equals(Type.CHAR_TYPE)) {
            throw new EvosuiteError("mocking of primitive types is not supported!");
        } else {
            Object res = varRef.getObject(scope);
            ReferenceExpression ref = env.heap.getReference(res);
            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);
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) 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) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 23 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(StringPrimitiveStatement statement, Scope scope) {
    String valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    StringVariable stringVariable = buildStringVariable(varRefName, valueOf);
    symb_expressions.put(varRefName, stringVariable);
    String string_instance;
    try {
        String string_interned = (String) varRef.getObject(scope);
        string_instance = new String(string_interned);
        scope.setObject(varRef, string_instance);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant stringRef = newStringReference(string_instance, stringVariable);
    symb_references.put(varRefName, stringRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 24 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(AssignmentStatement s, Scope scope) {
    VariableReference lhs = s.getReturnValue();
    VariableReference rhs = s.getValue();
    ReferenceExpressionPair readResult = read(rhs, scope);
    if (lhs instanceof FieldReference) {
        writeField((FieldReference) lhs, readResult, scope);
    } else if (lhs instanceof ArrayIndex) {
        writeArray((ArrayIndex) lhs, readResult, scope);
    } else {
        writeVariable(lhs, readResult);
    }
}
Also used : FieldReference(org.evosuite.testcase.variable.FieldReference) VariableReference(org.evosuite.testcase.variable.VariableReference) ArrayIndex(org.evosuite.testcase.variable.ArrayIndex)

Example 25 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(ClassPrimitiveStatement s, Scope scope) {
    VariableReference varRef = s.getReturnValue();
    Class<?> concrete_reference = s.getValue();
    String varName = varRef.getName();
    ReferenceExpression symb_ref = env.heap.getReference(concrete_reference);
    symb_references.put(varName, symb_ref);
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Aggregations

VariableReference (org.evosuite.testcase.variable.VariableReference)472 Method (java.lang.reflect.Method)289 TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)143 Test (org.junit.Test)73 GenericMethod (org.evosuite.utils.generic.GenericMethod)68 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)55 MethodStatement (org.evosuite.testcase.statements.MethodStatement)44 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)38 ArrayList (java.util.ArrayList)31 GenericClass (org.evosuite.utils.generic.GenericClass)27 TestCase (org.evosuite.testcase.TestCase)26 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)26 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)25 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)19 Type (java.lang.reflect.Type)17 Statement (org.evosuite.testcase.statements.Statement)17 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)15 ArrayReference (org.evosuite.testcase.variable.ArrayReference)15 VariableReferenceImpl (org.evosuite.testcase.variable.VariableReferenceImpl)15 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)14