use of org.evosuite.symbolic.expr.ExpressionExecutor in project evosuite by EvoSuite.
the class ConcolicExecution method logNrOfConstraints.
private static void logNrOfConstraints(List<BranchCondition> branches) {
int nrOfConstraints = 0;
ExpressionExecutor exprExecutor = new ExpressionExecutor();
for (BranchCondition branchCondition : branches) {
for (Constraint<?> supporting_constraint : branchCondition.getSupportingConstraints()) {
supporting_constraint.getLeftOperand().accept(exprExecutor, null);
supporting_constraint.getRightOperand().accept(exprExecutor, null);
nrOfConstraints++;
}
Constraint<?> constraint = branchCondition.getConstraint();
constraint.getLeftOperand().accept(exprExecutor, null);
constraint.getRightOperand().accept(exprExecutor, null);
nrOfConstraints++;
}
logger.debug("nrOfConstraints=" + nrOfConstraints);
}
use of org.evosuite.symbolic.expr.ExpressionExecutor in project evosuite by EvoSuite.
the class StringAVM method applyAVM.
/**
* <p>
* strLocalSearch
* </p>
*
* @return a boolean.
*/
public boolean applyAVM() throws SolverTimeoutException {
ExpressionExecutor exprExecutor = new ExpressionExecutor();
// try to remove each
log.debug("Trying to remove characters");
boolean improvement = false;
checkpointVar(DistanceEstimator.getDistance(cnstr));
// First chop characters from the back until distance doesn't improve
String oldString = strVar.getConcreteValue();
boolean improved = true;
while (improved && oldString.length() > 0) {
if (isFinished()) {
throw new SolverTimeoutException();
}
String newStr = oldString.substring(0, oldString.length() - 1);
strVar.setConcreteValue(newStr);
log.debug("Current attempt: " + newStr);
improved = false;
double newDist = DistanceEstimator.getDistance(cnstr);
// if (distImpr(newDist)) {
if (newDist <= checkpointDistance) {
log.debug("Distance improved or did not increase, keeping change");
checkpointVar(newDist);
improvement = true;
improved = true;
oldString = newStr;
if (newDist == 0) {
return true;
}
} else {
log.debug("Distance did not improve, reverting change");
restoreVar();
}
}
// next try to replace each character using AVM
log.debug("Trying to replace characters");
// Backup is done internally
if (doStringAVM(oldString)) {
improvement = true;
oldString = strVar.getConcreteValue();
}
if (checkpointDistance == 0.0) {
return true;
}
// try to add at the end
log.debug("Trying to add characters");
checkpointVar(DistanceEstimator.getDistance(cnstr));
// Finally add new characters at the end of the string
improved = true;
while (improved) {
if (isFinished()) {
throw new SolverTimeoutException();
}
improved = false;
char charToInsert = Randomness.nextChar();
String newStr = oldString + charToInsert;
strVar.setConcreteValue(newStr);
double newDist = DistanceEstimator.getDistance(cnstr);
log.debug("Adding: " + newStr + ": " + newDist);
if (distImpr(newDist)) {
improvement = true;
improved = true;
checkpointVar(newDist);
if (checkpointDistance == 0.0) {
log.debug("Search seems successful, stopping at " + checkpointDistance + "/" + newDist);
return true;
}
doCharacterAVM(newStr.length() - 1);
oldString = strVar.getConcreteValue();
} else {
restoreVar();
}
}
// try to insert delimiters (if any)
Set<StringValue> delimiters = getTokenDelimiters(cnstr);
for (StringValue delimiter : delimiters) {
if (isFinished()) {
throw new SolverTimeoutException();
}
improved = true;
String delimiterStr = (String) delimiter.accept(exprExecutor, null);
while (improved) {
if (isFinished()) {
throw new SolverTimeoutException();
}
improved = false;
char charToInsert = Randomness.nextChar();
String newStr = oldString + delimiterStr + charToInsert;
strVar.setConcreteValue(newStr);
double newDist = DistanceEstimator.getDistance(cnstr);
log.debug("Adding: " + newStr + ": " + newDist);
if (distImpr(newDist)) {
improvement = true;
improved = true;
checkpointVar(newDist);
if (checkpointDistance == 0.0) {
log.debug("Search seems successful, stopping at " + checkpointDistance + "/" + newDist);
return true;
}
doCharacterAVM(newStr.length() - 1);
oldString = strVar.getConcreteValue();
} else {
restoreVar();
}
}
}
return improvement;
}
Aggregations