use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class JumpVM method LOOKUPSWITCH.
/**
* <b>switch</b> statement whose cases may not be numbered consecutively.
* I.e., there may be holes (missing targets) between the lowest and highest
* target.
*
* <p>
* Very similar to {@link #TABLESWITCH}. The main difference is that here we
* are given a list of explicit goals. Tableswitch defines its goals
* implicitly, between min and max.
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc8.html#lookupswitch
*/
@Override
public void LOOKUPSWITCH(String className, String methName, int branchIndex, int goalConcrete, int[] targetsConcrete) {
// TODO: target array remains constant. Do we really need to create and
// pass
// this array every time as a paremeter?
final IntegerValue goal = env.topFrame().operandStack.popBv32();
Vector<IntegerConstraint> constraints = new Vector<IntegerConstraint>();
for (int targetConcrete : targetsConcrete) {
IntegerConstant integerConstant = ExpressionFactory.buildNewIntegerConstant(targetConcrete);
IntegerConstraint constraint;
if (goalConcrete == targetConcrete) {
constraint = ConstraintFactory.eq(goal, integerConstant);
constraints.add(constraint);
break;
} else {
constraint = ConstraintFactory.neq(goal, integerConstant);
constraints.add(constraint);
}
}
for (int i = 0; i < constraints.size() - 1; i++) {
IntegerConstraint cnstrnt = constraints.get(i);
if (cnstrnt.getLeftOperand().containsSymbolicVariable() || cnstrnt.getRightOperand().containsSymbolicVariable())
pc.addSupportingConstraint(cnstrnt);
}
// add branch condition iif local constraint is concrete
IntegerConstraint cnstr = constraints.get(constraints.size() - 1);
if (cnstr.getLeftOperand().containsSymbolicVariable() || cnstr.getRightOperand().containsSymbolicVariable()) {
pc.addBranchCondition(className, methName, branchIndex, cnstr);
}
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class LocalsVM method BIPUSH.
/**
* Bytecode instruction stream: ... ,0x10, byte, ...
*
* <p>
* Push the byte value that immediately follows this bytecode instruction
* (0x10) in the bytecode stream. The byte value is sign-extended to an int.
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc1.html#bipush
*/
@Override
public void BIPUSH(int value) {
IntegerConstant intConstant = ExpressionFactory.buildNewIntegerConstant(value);
env.topFrame().operandStack.pushBv32(intConstant);
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(ArrayStatement s, Scope scope) {
try {
ArrayReference arrayRef = (ArrayReference) s.getReturnValue();
Object conc_array;
conc_array = arrayRef.getObject(scope);
if (arrayRef.getArrayDimensions() == 1) {
int length = arrayRef.getArrayLength();
IntegerConstant lengthExpr = ExpressionFactory.buildNewIntegerConstant(length);
Class<?> component_class = arrayRef.getComponentClass();
env.topFrame().operandStack.pushBv32(lengthExpr);
if (component_class.equals(int.class)) {
VM.NEWARRAY(length, COMPONENT_TYPE_INT);
} else if (component_class.equals(char.class)) {
VM.NEWARRAY(length, COMPONENT_TYPE_CHAR);
} else if (component_class.equals(short.class)) {
VM.NEWARRAY(length, COMPONENT_TYPE_SHORT);
} else if (component_class.equals(byte.class)) {
VM.NEWARRAY(length, COMPONENT_TYPE_BYTE);
} else if (component_class.equals(float.class)) {
VM.NEWARRAY(length, COMPONENT_TYPE_FLOAT);
} else if (component_class.equals(long.class)) {
VM.NEWARRAY(length, COMPONENT_TYPE_LONG);
} else if (component_class.equals(boolean.class)) {
VM.NEWARRAY(length, COMPONENT_TYPE_BOOLEAN);
} else if (component_class.equals(double.class)) {
VM.NEWARRAY(length, COMPONENT_TYPE_DOUBLE);
} else {
// push arguments
String componentTypeName = component_class.getName().replace('.', '/');
VM.ANEWARRAY(length, componentTypeName);
}
} else {
// push dimensions
List<Integer> dimensions = arrayRef.getLengths();
for (int i = 0; i < arrayRef.getArrayDimensions(); i++) {
int length = dimensions.get(i);
IntegerConstant lengthExpr = ExpressionFactory.buildNewIntegerConstant(length);
env.topFrame().operandStack.pushBv32(lengthExpr);
}
String arrayTypeDesc = Type.getDescriptor(conc_array.getClass());
VM.MULTIANEWARRAY(arrayTypeDesc, arrayRef.getArrayDimensions());
}
ReferenceConstant symb_array = (ReferenceConstant) env.topFrame().operandStack.popRef();
env.heap.initializeReference(conc_array, symb_array);
String varRef_name = arrayRef.getName();
symb_references.put(varRef_name, symb_array);
} catch (CodeUnderTestException e) {
throw new RuntimeException(e);
}
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class DistanceCalculator method getDistanceIndexOfCEqualsK.
private static long getDistanceIndexOfCEqualsK(IntegerConstraint n, long leftVal, long rightVal) {
if (n.getLeftOperand() instanceof StringBinaryToIntegerExpression && n.getComparator() == Comparator.EQ && n.getRightOperand() instanceof IntegerConstant) {
IntegerConstant right_constant = (IntegerConstant) n.getRightOperand();
StringBinaryToIntegerExpression left_string_expr = (StringBinaryToIntegerExpression) n.getLeftOperand();
if (left_string_expr.getOperator() == Operator.INDEXOFC) {
Expression<?> theSymbolicString = left_string_expr.getLeftOperand();
Expression<?> theSymbolicChar = left_string_expr.getRightOperand();
Expression<?> theSymbolicIndex = right_constant;
// check theString.lenght>0
ExpressionExecutor exprExecutor = new ExpressionExecutor();
String theConcreteString = (String) theSymbolicString.accept(exprExecutor, null);
Long theConcreteIndex = (Long) theSymbolicIndex.accept(exprExecutor, null);
if (theConcreteIndex > theConcreteString.length() - 1) {
// there is no char at the index to modify
return Long.MAX_VALUE;
} else if (theConcreteIndex != -1) {
int theIndex = theConcreteIndex.intValue();
char theConcreteChar = (char) ((Long) theSymbolicChar.accept(exprExecutor, null)).longValue();
char theCurrentChar = theConcreteString.charAt(theIndex);
return Math.abs(theCurrentChar - theConcreteChar);
}
}
}
return -1;
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class DistanceCalculator method getDistanceIndexOfCFound.
private static long getDistanceIndexOfCFound(IntegerConstraint n, long leftVal, long rightVal) {
ExpressionExecutor exprExecutor = new ExpressionExecutor();
if (n.getLeftOperand() instanceof StringBinaryToIntegerExpression && n.getComparator() == Comparator.NE && n.getRightOperand() instanceof IntegerConstant) {
IntegerConstant right_constant = (IntegerConstant) n.getRightOperand();
StringBinaryToIntegerExpression left_string_expr = (StringBinaryToIntegerExpression) n.getLeftOperand();
if (left_string_expr.getOperator() == Operator.INDEXOFC && right_constant.getConcreteValue() == -1L) {
Expression<?> theSymbolicString = left_string_expr.getLeftOperand();
Expression<?> theSymbolicChar = left_string_expr.getRightOperand();
// check theString.lenght>0
String theConcreteString = (String) theSymbolicString.accept(exprExecutor, null);
if (theConcreteString.length() == 0) {
// no char can be modified to satisfy the constraint
return Long.MAX_VALUE;
} else {
char theConcreteChar = (char) ((Long) theSymbolicChar.accept(exprExecutor, null)).longValue();
char[] charArray = theConcreteString.toCharArray();
int min_distance_to_char = Integer.MAX_VALUE;
for (char c : charArray) {
if (Math.abs(c - theConcreteChar) < min_distance_to_char) {
min_distance_to_char = Math.abs(c - theConcreteChar);
}
}
return min_distance_to_char;
}
}
}
return -1;
}
Aggregations