Search in sources :

Example 11 with VariableReference

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

the class SymbolicObserver method after.

private void after(FloatPrimitiveStatement statement, Scope scope) {
    float valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    RealVariable realVariable = buildRealVariable(varRefName, valueOf, -Float.MAX_VALUE, Float.MAX_VALUE);
    symb_expressions.put(varRefName, realVariable);
    Float float_instance;
    try {
        float_instance = (Float) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant floatRef = newFloatReference(float_instance, realVariable);
    symb_references.put(varRefName, floatRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 12 with VariableReference

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

the class SymbolicObserver method call_vm_caller_stack_params.

private void call_vm_caller_stack_params(boolean needThis, List<VariableReference> parameters, Scope scope, String desc) {
    int calleeLocalsIndex = 0;
    if (needThis)
        calleeLocalsIndex++;
    for (int i = 0; i < parameters.size(); i++) {
        VariableReference p = parameters.get(i);
        calleeLocalsIndex += getSize(p.getType());
    }
    Type[] argTypes = Type.getArgumentTypes(desc);
    for (int i = parameters.size() - 1; i >= 0; i--) {
        Type argType = argTypes[i];
        VariableReference p = parameters.get(i);
        try {
            Object param_object = p.getObject(scope);
            calleeLocalsIndex -= getSize(p.getType());
            if (argType.equals(Type.INT_TYPE)) {
                int intValue = getIntValue(param_object);
                VM.CALLER_STACK_PARAM(intValue, i, calleeLocalsIndex);
            } else if (argType.equals(Type.CHAR_TYPE)) {
                char charValue = getCharValue(param_object);
                VM.CALLER_STACK_PARAM(charValue, i, calleeLocalsIndex);
            } else if (argType.equals(Type.BYTE_TYPE)) {
                byte byteValue = getByteValue(param_object);
                VM.CALLER_STACK_PARAM(byteValue, i, calleeLocalsIndex);
            } else if (argType.equals(Type.BOOLEAN_TYPE)) {
                boolean booleanValue = getBooleanValue(param_object);
                VM.CALLER_STACK_PARAM(booleanValue, i, calleeLocalsIndex);
            } else if (argType.equals(Type.SHORT_TYPE)) {
                short shortValue = getShortValue(param_object);
                VM.CALLER_STACK_PARAM(shortValue, i, calleeLocalsIndex);
            } else if (argType.equals(Type.LONG_TYPE)) {
                long longValue = getLongValue(param_object);
                VM.CALLER_STACK_PARAM(longValue, i, calleeLocalsIndex);
            } else if (argType.equals(Type.FLOAT_TYPE)) {
                float floatValue = getFloatValue(param_object);
                VM.CALLER_STACK_PARAM(floatValue, i, calleeLocalsIndex);
            } else if (argType.equals(Type.DOUBLE_TYPE)) {
                double doubleValue = getDoubleValue(param_object);
                VM.CALLER_STACK_PARAM(doubleValue, i, calleeLocalsIndex);
            } else {
                VM.CALLER_STACK_PARAM(param_object, i, calleeLocalsIndex);
            }
        } catch (CodeUnderTestException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Type(org.objectweb.asm.Type) VariableReference(org.evosuite.testcase.variable.VariableReference) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 13 with VariableReference

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

the class SymbolicObserver method after.

private void after(BooleanPrimitiveStatement statement, Scope scope) {
    boolean valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf ? 1 : 0, 0, 1);
    Boolean boolean_instance;
    try {
        boolean_instance = (Boolean) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    symb_expressions.put(varRefName, integerVariable);
    ReferenceConstant booleanRef = newBooleanReference(boolean_instance, integerVariable);
    symb_references.put(varRefName, booleanRef);
}
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 14 with VariableReference

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

the class SymbolicObserver method after.

private void after(DoublePrimitiveStatement statement, Scope scope) {
    double valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    RealVariable realVariable = buildRealVariable(varRefName, valueOf, -Double.MAX_VALUE, Double.MAX_VALUE);
    symb_expressions.put(varRefName, realVariable);
    Double double_instance;
    try {
        double_instance = (Double) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant doubleRef = newDoubleReference(double_instance, realVariable);
    symb_references.put(varRefName, doubleRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 15 with VariableReference

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

the class SymbolicObserver method after.

private void after(LocalAddressPrimitiveStatement s, Scope scope) {
    EvoSuiteLocalAddress conc_local_address = s.getValue();
    VariableReference varRef = s.getReturnValue();
    String varRefName = varRef.getName();
    ReferenceExpression addressRef;
    if (conc_local_address == null) {
        addressRef = env.heap.getReference(null);
        if (addressRef.getConcreteValue() != null) {
            throw new IllegalStateException("Expected null concrete object");
        }
    } else {
        addressRef = env.heap.getReference(conc_local_address);
        if (addressRef.getConcreteValue() == null) {
            throw new IllegalStateException("Expected non-null concrete object");
        }
    }
    symb_references.put(varRefName, addressRef);
}
Also used : EvoSuiteLocalAddress(org.evosuite.runtime.testdata.EvoSuiteLocalAddress) 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