Search in sources :

Example 1 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.

the class RegionMatches5 method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_receiver = (ReferenceConstant) this.getSymbReceiver();
    String conc_receiver = (String) this.getConcReceiver();
    StringValue stringReceiverExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, conc_receiver);
    IntegerValue ignoreCaseExpr = new IntegerConstant(0);
    IntegerValue toffsetExpr = this.getSymbIntegerArgument(0);
    ReferenceConstant symb_other = (ReferenceConstant) this.getSymbArgument(1);
    String conc_other = (String) this.getConcArgument(1);
    StringValue otherExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_other, symb_other, conc_other);
    IntegerValue ooffsetExpr = this.getSymbIntegerArgument(2);
    IntegerValue lenExpr = this.getSymbIntegerArgument(3);
    boolean res = this.getConcBooleanRetVal();
    if (stringReceiverExpr.containsSymbolicVariable() || ignoreCaseExpr.containsSymbolicVariable() || toffsetExpr.containsSymbolicVariable() || otherExpr.containsSymbolicVariable() || ooffsetExpr.containsSymbolicVariable() || lenExpr.containsSymbolicVariable()) {
        ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
        other.add(toffsetExpr);
        other.add(ooffsetExpr);
        other.add(lenExpr);
        other.add(ignoreCaseExpr);
        int conV = res ? 1 : 0;
        StringMultipleComparison strComp = new StringMultipleComparison(stringReceiverExpr, Operator.REGIONMATCHES, otherExpr, other, (long) conV);
        return strComp;
    }
    return this.getSymbIntegerRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringMultipleComparison(org.evosuite.symbolic.expr.bv.StringMultipleComparison) Expression(org.evosuite.symbolic.expr.Expression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ArrayList(java.util.ArrayList) StringValue(org.evosuite.symbolic.expr.str.StringValue) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 2 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.

the class StringBuffer_SetLength method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_str_buffer = this.getSymbReceiver();
    StringBuffer conc_str_buffer = (StringBuffer) this.getConcReceiver();
    IntegerValue newSymbLength = this.getSymbIntegerArgument(0);
    int newConcLength = this.getConcIntArgument(0);
    // 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, pre_conc_value);
    if (symb_value.containsSymbolicVariable() || newSymbLength.containsSymbolicVariable()) {
        StringValue new_symb_value = null;
        if (!newSymbLength.containsSymbolicVariable() && newConcLength == 0) {
            // StringBuffer contents equals to "" string
            new_symb_value = new StringConstant("");
        } else {
            // StringBuffer contents equ
            new_symb_value = new StringMultipleExpression(symb_value, Operator.SUBSTRING, new IntegerConstant(0), new ArrayList<Expression<?>>(Collections.singletonList(newSymbLength)), conc_value);
        }
        env.heap.putField(Types.JAVA_LANG_STRING_BUFFER, SymbolicHeap.$STRING_BUFFER_CONTENTS, conc_str_buffer, symb_str_buffer, new_symb_value);
    }
    // return void
    return null;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringMultipleExpression(org.evosuite.symbolic.expr.str.StringMultipleExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ArrayList(java.util.ArrayList) StringValue(org.evosuite.symbolic.expr.str.StringValue) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 3 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.

the class CallVM method CALL_RESULT.

/**
 * Our chance to capture the value returned by a native or un-instrumented
 * method.
 */
@Override
public void CALL_RESULT(boolean res, String owner, String name, String desc) {
    CALL_RESULT(owner, name, desc);
    if (env.topFrame().weInvokedInstrumentedCode()) {
        // it
        return;
    } else {
        /**
         * We are returning from uninstrumented code. This is the only way
         * of storing the uninstrumented return value to the symbolic state.
         */
        int i = res ? 1 : 0;
        IntegerConstant value = ExpressionFactory.buildNewIntegerConstant(i);
        env.topFrame().operandStack.pushBv32(value);
    }
}
Also used : IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 4 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.

the class CallVM method METHOD_BEGIN_PARAM.

@Override
public void METHOD_BEGIN_PARAM(int nr, int index, int value) {
    if (!env.callerFrame().weInvokedInstrumentedCode()) {
        IntegerConstant literal_value = ExpressionFactory.buildNewIntegerConstant(value);
        env.topFrame().localsTable.setBv32Local(index, literal_value);
    }
}
Also used : IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 5 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.

the class CallVM method CALL_RESULT.

/**
 * int, short, byte all map to a BitVec32
 *
 * TODO: Will this work for char?
 */
@Override
public void CALL_RESULT(int res, String owner, String name, String desc) {
    CALL_RESULT(owner, name, desc);
    if (env.topFrame().weInvokedInstrumentedCode()) {
        // it
        return;
    } else {
        /**
         * We are returning from uninstrumented code. This is the only way
         * of storing the uninstrumented return value to the symbolic state.
         */
        IntegerConstant value = ExpressionFactory.buildNewIntegerConstant(res);
        env.topFrame().operandStack.pushBv32(value);
    }
}
Also used : IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Aggregations

IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)65 Constraint (org.evosuite.symbolic.expr.Constraint)42 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)42 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)36 Test (org.junit.Test)36 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)35 ArrayList (java.util.ArrayList)34 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)29 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)26 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)23 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)17 SolverResult (org.evosuite.symbolic.solver.SolverResult)14 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)13 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)12 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)7 Expression (org.evosuite.symbolic.expr.Expression)6 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)5 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)5 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)3