use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.
the class JumpVM method IF_ICMPEQ.
/**
* (left == right). (left != right) is just (not (left == right)).
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc6.html#if_icmpcond
*/
@Override
public void IF_ICMPEQ(String className, String methName, int branchIndex, int left, int right) {
IntegerValue rightOp = env.topFrame().operandStack.popBv32();
IntegerValue leftOp = env.topFrame().operandStack.popBv32();
IntegerConstraint cnstr;
if (left == right)
// "True" branch
cnstr = ConstraintFactory.eq(leftOp, rightOp);
else
// "False" branch
cnstr = ConstraintFactory.neq(leftOp, rightOp);
// add branch condition iif local constraint is concrete
if (cnstr.getLeftOperand().containsSymbolicVariable() || cnstr.getRightOperand().containsSymbolicVariable())
pc.addBranchCondition(className, methName, branchIndex, cnstr);
}
use of org.evosuite.symbolic.expr.IntegerConstraint 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.IntegerConstraint in project evosuite by EvoSuite.
the class JumpVM method IF_ICMPLT.
/**
* (left < right). (left >= right) is just (not (left < right)).
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc6.html#if_icmpcond
*/
@Override
public void IF_ICMPLT(String className, String methName, int branchIndex, int left, int right) {
IntegerValue rightBv = env.topFrame().operandStack.popBv32();
IntegerValue leftBv = env.topFrame().operandStack.popBv32();
IntegerConstraint cnstr;
if (left < right)
// True Branch
cnstr = ConstraintFactory.lt(leftBv, rightBv);
else
// False branch
cnstr = ConstraintFactory.gte(leftBv, rightBv);
// add branch condition iif local constraint is concrete
if (cnstr.getLeftOperand().containsSymbolicVariable() || cnstr.getRightOperand().containsSymbolicVariable())
pc.addBranchCondition(className, methName, branchIndex, cnstr);
}
use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.
the class PathConditionCollector method addBranchCondition.
/**
* Add a new constraint to a branch condition
*
* @param className
* the class name where the branch is
* @param methName
* the method where the branch is
* @param branchIndex
* the branch index
* @param c
* the constraint for the branch condition
*/
public void addBranchCondition(String className, String methName, int branchIndex, IntegerConstraint c) {
Constraint<?> normalizedConstraint = normalizeConstraint(c);
LinkedList<Constraint<?>> branch_supporting_constraints = new LinkedList<Constraint<?>>(currentSupportingConstraints);
BranchCondition new_branch = new BranchCondition(className, methName, branchIndex, normalizedConstraint, branch_supporting_constraints);
branchConditions.add(new_branch);
currentSupportingConstraints.clear();
}
use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.
the class DistanceEstimator method getDistance.
/**
* <p>
* getDistance
* </p>
*
* @param constraints
* a {@link java.util.Collection} object.
* @return normalized distance in [0,1]
*/
public static double getDistance(Collection<Constraint<?>> constraints) {
double result = 0;
DistanceCalculator distanceCalculator = new DistanceCalculator();
try {
for (Constraint<?> c : constraints) {
if (c instanceof StringConstraint) {
StringConstraint string_constraint = (StringConstraint) c;
try {
double strD = (double) string_constraint.accept(distanceCalculator, null);
result += normalize(strD);
log.debug("S: " + string_constraint + " strDist " + strD);
} catch (Throwable t) {
log.debug("S: " + string_constraint + " strDist " + t);
result += 1.0;
}
} else if (c instanceof IntegerConstraint) {
IntegerConstraint integer_constraint = (IntegerConstraint) c;
long intD = (long) integer_constraint.accept(distanceCalculator, null);
result += normalize(intD);
log.debug("C: " + integer_constraint + " intDist " + intD);
} else if (c instanceof RealConstraint) {
RealConstraint real_constraint = (RealConstraint) c;
double realD = (double) real_constraint.accept(distanceCalculator, null);
result += normalize(realD);
log.debug("C: " + real_constraint + " realDist " + realD);
} else {
throw new IllegalArgumentException("DistanceCalculator: got an unknown constraint: " + c);
}
}
log.debug("Resulting distance: " + result);
return Math.abs(result);
} catch (Exception e) {
return Double.MAX_VALUE;
}
}
Aggregations