Search in sources :

Example 11 with ReferenceExpression

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

the class SymbolicObserver method after.

private void after(FieldStatement s, Scope scope) {
    ReferenceExpressionPair readResult;
    if (s.getSource() != null) {
        readResult = readInstanceField(s.getSource(), s.getField().getField(), scope);
    } else {
        readResult = readStaticField(s.getField().getField());
    }
    String lhs_name = s.getReturnValue().getName();
    Expression<?> expr = readResult.getExpression();
    ReferenceExpression ref = readResult.getReference();
    if (expr != null)
        symb_expressions.put(lhs_name, expr);
    if (ref != null)
        symb_references.put(lhs_name, ref);
}
Also used : ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 12 with ReferenceExpression

use of org.evosuite.symbolic.expr.ref.ReferenceExpression 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)

Example 13 with ReferenceExpression

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

the class SymbolicObserver method writeArray.

private void writeArray(ArrayIndex lhs, ReferenceExpressionPair readResult, Scope scope) {
    ArrayReference arrayReference = lhs.getArray();
    int conc_index = lhs.getArrayIndex();
    Object conc_array;
    try {
        conc_array = arrayReference.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    Type arrayType = Type.getType(conc_array.getClass());
    Type elementType = arrayType.getElementType();
    if (isValue(elementType) || elementType.equals(Type.getType(String.class))) {
        Expression<?> symb_value = readResult.getExpression();
        symb_value = castIfNeeded(elementType, symb_value);
        String array_name = arrayReference.getName();
        ReferenceExpression symb_ref = symb_references.get(array_name);
        ReferenceConstant symb_array = (ReferenceConstant) symb_ref;
        env.heap.array_store(conc_array, symb_array, conc_index, symb_value);
    } else {
    /* ignore storing references (we use objects to find them) */
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) ArrayReference(org.evosuite.testcase.variable.ArrayReference) Type(org.objectweb.asm.Type) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 14 with ReferenceExpression

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

the class SymbolicEnvironment method prepareStack.

/**
 * Prepare stack of function invocation frames.
 *
 * Clear function invocation stack, push a frame that pretends to call the
 * method under test. We push variables for our method onto the
 * pseudo-callers stack, so our method can pop them from there.
 */
public void prepareStack(Method mainMethod) {
    stackFrame.clear();
    // bottom of the stack trace
    this.pushFrame(new FakeBottomFrame());
    // frame for argument purposes
    final FakeMainCallerFrame fakeMainCallerFrame = new FakeMainCallerFrame(mainMethod, // fake caller
    MainConfig.get().MAX_LOCALS_DEFAULT);
    if (mainMethod != null) {
        boolean isInstrumented = isInstrumented(mainMethod);
        fakeMainCallerFrame.invokeInstrumentedCode(isInstrumented);
        String[] emptyStringArray = new String[] {};
        ReferenceExpression emptyStringRef = heap.getReference(emptyStringArray);
        fakeMainCallerFrame.operandStack.pushRef(emptyStringRef);
    }
    this.pushFrame(fakeMainCallerFrame);
}
Also used : ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 15 with ReferenceExpression

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

the class SymbolicHeap method getField.

/**
 * Returns a stored symbolic expression for an int field or created one
 *
 * @param owner
 * @param name
 * @param conc_receiver
 * @param symb_receiver
 * @param conc_value
 * @return
 */
public IntegerValue getField(String owner, String name, Object conc_receiver, ReferenceExpression symb_receiver, long conc_value) {
    Map<ReferenceExpression, Expression<?>> symb_field = getOrCreateSymbolicField(owner, name);
    IntegerValue symb_value = (IntegerValue) symb_field.get(symb_receiver);
    if (symb_value == null || ((Long) symb_value.getConcreteValue()).longValue() != conc_value) {
        symb_value = ExpressionFactory.buildNewIntegerConstant(conc_value);
        symb_field.remove(symb_receiver);
    }
    return symb_value;
}
Also used : Expression(org.evosuite.symbolic.expr.Expression) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Aggregations

ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)73 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)19 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)18 StringValue (org.evosuite.symbolic.expr.str.StringValue)16 Expression (org.evosuite.symbolic.expr.Expression)13 RealValue (org.evosuite.symbolic.expr.fp.RealValue)13 VariableReference (org.evosuite.testcase.variable.VariableReference)11 Type (org.objectweb.asm.Type)9 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)6 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)5 Field (java.lang.reflect.Field)3 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)3 Method (java.lang.reflect.Method)2 StringMultipleExpression (org.evosuite.symbolic.expr.str.StringMultipleExpression)2 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)2 ArrayReference (org.evosuite.testcase.variable.ArrayReference)2 BigInteger (java.math.BigInteger)1 Matcher (java.util.regex.Matcher)1 EvoSuiteFile (org.evosuite.runtime.testdata.EvoSuiteFile)1