Search in sources :

Example 61 with ReferenceConstant

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

the class BigInteger_Ctor method executeFunction.

@Override
public Object executeFunction() {
    String conc_string = (String) this.getConcArgument(0);
    ReferenceConstant str_ref = (ReferenceConstant) this.getSymbArgument(0);
    StringValue symb_string = this.env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_string, str_ref, conc_string);
    if (symb_string.containsSymbolicVariable()) {
        ReferenceConstant symb_big_integer = (ReferenceConstant) env.topFrame().operandStack.peekRef();
        BigInteger bigInteger = new BigInteger(conc_string);
        long concVal = bigInteger.longValue();
        StringToIntegerCast big_integer_value = new StringToIntegerCast(symb_string, concVal);
        env.heap.putField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, null, /* conc_big_integer */
        symb_big_integer, big_integer_value);
    }
    // return void
    return null;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringToIntegerCast(org.evosuite.symbolic.expr.bv.StringToIntegerCast) BigInteger(java.math.BigInteger) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 62 with ReferenceConstant

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

the class CallVM method METHOD_BEGIN.

/**
 * Pop operands off caller stack
 *
 * Method methName is about to start execution.
 *
 * At this point we have either already seen (observed InvokeXXX) or missed
 * this invocation of the methName method.
 *
 * We miss any of the following: - invoke <clinit> (as there are no such
 * statements) - invoke <init> (as we do not add instrumentation code for
 * these)
 *
 * User code cannot call the <clinit>() method directly. Instead, the JVM
 * invokes a class's initializer implicitly, upon the first use of the
 * class.
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html
 * #32316
 * http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc
 * .html#19075
 * http://java.sun.com/docs/books/jvms/second_edition/html/Overview
 * .doc.html#16262
 */
@Override
public void METHOD_BEGIN(int access, String className, String methName, String methDesc) {
    if (conf.CLINIT.equals(methName)) {
        CLINIT_BEGIN(className);
        return;
    }
    if (env.topFrame().weInvokedInstrumentedCode() == false) {
    // An uninstrumented caller has called instrumented code
    // This is problemtatic
    }
    prepareStackIfNeeded(className, methName, methDesc);
    /* Begin of a method or constructor */
    // guy who (transitively)
    final Frame callerFrame = env.topFrame();
    // called us
    Frame frame;
    boolean calleeNeedsThis = false;
    if (conf.INIT.equals(methName)) {
        Constructor<?> constructor = resolveConstructorOverloading(className, methDesc);
        int maxLocals = conf.MAX_LOCALS_DEFAULT;
        MemberInfo memberInfo = memberInfos.get(constructor);
        if (memberInfo != null)
            maxLocals = memberInfo.maxLocals;
        frame = new ConstructorFrame(constructor, maxLocals);
        calleeNeedsThis = true;
        if (callerFrame.weInvokedInstrumentedCode() == false) {
            /**
             * Since this is a constructor called from un-instrumented code,
             * we need to "simulate" the missing NEW. This means 1) create a
             * new object reference 2) populate the localstable with the new
             * reference
             */
            Class<?> clazz = classLoader.getClassForName(className);
            Type objectType = Type.getType(clazz);
            ReferenceConstant newObject = this.env.heap.buildNewReferenceConstant(objectType);
            frame.localsTable.setRefLocal(0, newObject);
        }
    } else {
        Method method = resolveMethodOverloading(className, methName, methDesc);
        int maxLocals = conf.MAX_LOCALS_DEFAULT;
        MemberInfo memberInfo = memberInfos.get(method);
        if (memberInfo != null)
            maxLocals = memberInfo.maxLocals;
        frame = new MethodFrame(method, maxLocals);
        calleeNeedsThis = !Modifier.isStatic(method.getModifiers());
    }
    /*
		 * If our caller called uninstrumented code then we should not ruin his
		 * operand stack! Instead, METHOD_BEGIN_PARAM will supply the concrete
		 * parameter values and create corresponding symbolic constants.
		 */
    if (callerFrame.weInvokedInstrumentedCode() == false) {
        env.pushFrame(frame);
        return;
    }
    /*
		 * Our caller directly called us. We should take our parameters from his
		 * stack.
		 */
    Class<?>[] paramTypes = getArgumentClasses(methDesc);
    final Deque<Operand> params = new LinkedList<Operand>();
    Iterator<Operand> it = env.topFrame().operandStack.iterator();
    for (int i = paramTypes.length - 1; i >= 0; i--) {
        // read parameters from caller operand srack
        Operand param = it.next();
        params.push(param);
    }
    int index = 0;
    for (Operand param : params) {
        frame.localsTable.setOperand(index + (calleeNeedsThis ? 1 : 0), param);
        if (param instanceof SingleWordOperand)
            index += 1;
        else if (param instanceof DoubleWordOperand)
            index += 2;
        else {
            throw new IllegalStateException("Unknown operand type " + param.getClass().getName());
        }
    }
    if (calleeNeedsThis) {
        // "this" instance
        Operand param = it.next();
        ReferenceOperand refOperand = (ReferenceOperand) param;
        frame.localsTable.setRefLocal(0, refOperand.getReference());
    }
    env.pushFrame(frame);
}
Also used : Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type)

Example 63 with ReferenceConstant

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

the class ExpressionFactory method buildNewNullExpression.

public static ReferenceConstant buildNewNullExpression() {
    final Type objectType = Type.getType(Object.class);
    final ReferenceConstant referenceConstant = new ReferenceConstant(objectType, 0);
    referenceConstant.initializeReference(null);
    return referenceConstant;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type)

Example 64 with ReferenceConstant

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

the class StringBuffer_ToString method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_str_buffer = this.getSymbReceiver();
    StringBuffer conc_str_buffer = (StringBuffer) this.getConcReceiver();
    // retrieve symbolic value from heap
    String conc_value = conc_str_buffer.toString();
    StringValue symb_value = env.heap.getField(Types.JAVA_LANG_STRING_BUFFER, SymbolicHeap.$STRING_BUFFER_CONTENTS, conc_str_buffer, symb_str_buffer, conc_value);
    String conc_ret_val = (String) this.getConcRetVal();
    ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
    env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, symb_value);
    // return symbolic value
    return symb_ret_val;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 65 with ReferenceConstant

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

the class StringBuilder_Append method executeFunction.

@Override
public final Object executeFunction() {
    // string builder
    StringBuilder conc_str_builder = (StringBuilder) this.getConcReceiver();
    ReferenceConstant symb_str_builder = (ReferenceConstant) this.getSymbReceiver();
    // return value
    StringBuilder res = (StringBuilder) this.getConcRetVal();
    ReferenceConstant symb_res = (ReferenceConstant) this.getSymbRetVal();
    StringValue leftExpr = this.env.heap.getField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, conc_str_builder, symb_str_builder, conc_str_builder_to_string_pre);
    // append string expression
    StringValue newStrExpr = appendExpression(leftExpr, res);
    // store to symbolic heap
    env.heap.putField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, conc_str_builder, symb_res, newStrExpr);
    return symb_res;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) 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