Search in sources :

Example 56 with ReferenceConstant

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

the class HeapVM method MULTIANEWARRAY.

/**
 * MULTIANEWARRAY
 *
 * <pre>
 * boolean[] b1 = new boolean[1]; // NEWARRAY T_BOOLEAN
 * Boolean[] B1 = new Boolean[1]; // ANEWARRAY java/lang/Boolean
 * boolean[][] b2 = new boolean[1][2]; // MULTIANEWARRAY [[Z 2
 * Boolean[][] B2 = new Boolean[1][2]; // MULTIANEWARRAY [[Ljava/lang/Boolean; 2
 * </pre>
 */
@Override
public void MULTIANEWARRAY(String arrayTypeDesc, int nrDimensions) {
    // push negartive length constraints
    for (int i = 0; i < nrDimensions; i++) {
        IntegerValue symb_length = env.topFrame().operandStack.popBv32();
        int conc_length = ((Long) symb_length.getConcreteValue()).intValue();
        if (negativeArrayLengthViolation(conc_length, symb_length)) {
            return;
        }
    }
    Type multiArrayType = Type.getType(arrayTypeDesc);
    // push delayed object
    ReferenceConstant newMultiArray = this.env.heap.buildNewReferenceConstant(// @FIXME
    multiArrayType);
    env.topFrame().operandStack.pushRef(newMultiArray);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 57 with ReferenceConstant

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

the class HeapVM method NEWARRAY.

/* Arrays */
/**
 * Create a (one-dimensional) array of primitive componenet type, e.g., new
 * int[3]
 *
 * Allocate space on the heap and push a reference ref to it onto the stack.
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc10.html#newarray
 */
@Override
public void NEWARRAY(int conc_array_length, Class<?> componentType) {
    /**
     * Since this callback is invoked before the actual array creation, we
     * can only add negative index constraints.
     *
     * PRE: int (length)
     *
     * POST: arrayref (delayed)
     */
    // discard symbolic arguments
    IntegerValue symb_array_length = env.topFrame().operandStack.popBv32();
    /* negative index */
    if (negativeArrayLengthViolation(conc_array_length, symb_array_length))
        return;
    // create array class
    int[] lenghts = new int[] { 0 };
    Class<?> array_class = Array.newInstance(componentType, lenghts).getClass();
    Type arrayType = Type.getType(array_class);
    ReferenceConstant symb_array_ref = this.env.heap.buildNewReferenceConstant(arrayType);
    env.heap.putField("", ARRAY_LENGTH, null, symb_array_ref, symb_array_length);
    env.topFrame().operandStack.pushRef(symb_array_ref);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 58 with ReferenceConstant

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

the class HeapVM method ANEWARRAY.

/**
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc
 * .html#anewarray
 */
@Override
public void ANEWARRAY(int conc_array_length, String componentTypeName) {
    /**
     * Since this callback is invoked before the actual array creation, we
     * can only add negative index constraints.
     *
     * PRE: int (length)
     *
     * POST: arrayref (delayed)
     */
    // discard symbolic arguments
    IntegerValue symb_array_length = env.topFrame().operandStack.popBv32();
    /* negative index */
    if (negativeArrayLengthViolation(conc_array_length, symb_array_length))
        return;
    // create array class
    Type componentType = Type.getType(componentTypeName.replace('/', '.'));
    Class<?> componentClass = classLoader.getClassForType(componentType);
    int[] lenghts = new int[] { 0 };
    Class<?> array_class = Array.newInstance(componentClass, lenghts).getClass();
    Type arrayType = Type.getType(array_class);
    ReferenceConstant symb_array_ref = env.heap.buildNewReferenceConstant(arrayType);
    env.heap.putField("", ARRAY_LENGTH, null, symb_array_ref, symb_array_length);
    env.topFrame().operandStack.pushRef(symb_array_ref);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 59 with ReferenceConstant

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

the class SymbolicHeap method getReference.

/**
 * Returns a <code>ReferenceConstant</code> if the concrete reference is
 * null. Otherwise, it looks in the list of non-null symbolic references for
 * a symbolic reference with the concrete value. If it is found, that
 * symbolic reference is returned, otherwise a new reference constant is
 * created (and added ot the list of non-null symbolic references)
 *
 * @param conc_ref
 * @return
 */
public ReferenceExpression getReference(Object conc_ref) {
    if (conc_ref == null) {
        // null reference
        ReferenceConstant nullConstant = ExpressionFactory.buildNewNullExpression();
        return nullConstant;
    } else {
        int identityHashCode = System.identityHashCode(conc_ref);
        if (nonNullRefs.containsKey(identityHashCode)) {
            // already known object
            ReferenceExpression symb_ref = nonNullRefs.get(identityHashCode);
            return symb_ref;
        } else {
            // unknown object
            final Type type = Type.getType(conc_ref.getClass());
            ReferenceConstant ref_constant = new ReferenceConstant(type, newInstanceCount++);
            ref_constant.initializeReference(conc_ref);
            nonNullRefs.put(identityHashCode, ref_constant);
            return ref_constant;
        }
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 60 with ReferenceConstant

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

the class Perl5Matcher_Matches method executeFunction.

@Override
public Object executeFunction() {
    // Perl5Matcher conc_matcher = (Perl5Matcher) this.getConcReceiver();
    // NonNullReference symb_matcher = (NonNullReference) this
    // .getSymbReceiver();
    boolean res = this.getConcBooleanRetVal();
    ReferenceConstant symb_string_ref = (ReferenceConstant) this.getSymbArgument(0);
    // Reference symb_pattern_ref = this.getSymbArgument(1);
    String conc_string = (String) this.getConcArgument(0);
    Pattern conc_pattern = (Pattern) this.getConcArgument(1);
    StringValue symb_string_value = env.heap.getField(org.evosuite.symbolic.vm.regex.Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_string, symb_string_ref, conc_string);
    if (symb_string_value != null && symb_string_value.containsSymbolicVariable()) {
        int concrete_value = res ? 1 : 0;
        String pattern_str = conc_pattern.getPattern();
        StringConstant symb_pattern_value = ExpressionFactory.buildNewStringConstant(pattern_str);
        StringBinaryComparison strComp = new StringBinaryComparison(symb_pattern_value, Operator.APACHE_ORO_PATTERN_MATCHES, symb_string_value, (long) concrete_value);
        return strComp;
    } else {
        return this.getSymbIntegerRetVal();
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Pattern(org.apache.oro.text.regex.Pattern) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue) StringConstant(org.evosuite.symbolic.expr.str.StringConstant)

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