use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class CVC4ResultParser method parse.
public SolverResult parse(String cvc4ResultStr) throws SolverParseException, SolverErrorException, SolverTimeoutException {
if (cvc4ResultStr.startsWith("sat")) {
logger.debug("CVC4 outcome was SAT");
SolverResult satResult = parseModel(cvc4ResultStr);
return satResult;
} else if (cvc4ResultStr.startsWith("unsat")) {
logger.debug("CVC4 outcome was UNSAT");
SolverResult unsatResult = SolverResult.newUNSAT();
return unsatResult;
} else if (cvc4ResultStr.startsWith("unknown")) {
logger.debug("CVC4 outcome was UNKNOWN (probably due to timeout)");
throw new SolverTimeoutException();
} else if (cvc4ResultStr.startsWith("(error")) {
logger.debug("CVC4 output was the following " + cvc4ResultStr);
throw new SolverErrorException("An error (probably an invalid input) occurred while executing CVC4");
} else {
logger.debug("The following CVC4 output could not be parsed " + cvc4ResultStr);
throw new SolverParseException("CVC4 output is unknown. We are unable to parse it to a proper solution!", cvc4ResultStr);
}
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestConstraintSolver method testCase2.
@Test
public void testCase2() throws SecurityException, NoSuchMethodException, SolverEmptyQueryException {
DefaultTestCase tc = buildTestCase2();
// build patch condition
List<BranchCondition> branch_conditions = executeTest(tc);
assertEquals(57, branch_conditions.size());
// keep only 2 top-most branch conditions
List<BranchCondition> sublist = new ArrayList<BranchCondition>();
sublist.add(branch_conditions.get(0));
sublist.add(branch_conditions.get(1));
// invoke seeker
try {
SolverResult solverResult = executeSolver(sublist);
assertNotNull(solverResult);
assertTrue(solverResult.isSAT());
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestConstraintSolver method executeSolver.
private SolverResult executeSolver(List<BranchCondition> branch_conditions) throws SolverTimeoutException, SolverEmptyQueryException {
final int lastBranchIndex = branch_conditions.size() - 1;
BranchCondition last_branch = branch_conditions.get(lastBranchIndex);
List<Constraint<?>> constraints = new LinkedList<Constraint<?>>();
for (int i = 0; i < lastBranchIndex; i++) {
BranchCondition c = branch_conditions.get(i);
constraints.addAll(c.getSupportingConstraints());
constraints.add(c.getConstraint());
}
constraints.addAll(last_branch.getSupportingConstraints());
Constraint<?> lastConstraint = last_branch.getConstraint();
Constraint<?> targetConstraint = lastConstraint.negate();
constraints.add(targetConstraint);
System.out.println("Target constraints");
printConstraints(constraints);
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
if (solverResult.isUNSAT())
System.out.println("No new model was found");
else {
Map<String, Object> model = solverResult.getModel();
System.out.println(model.toString());
}
return solverResult;
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestConstraintSolver2 method test.
@Test
public void test() throws SolverEmptyQueryException {
// 5000000000000L; TODO - ??
Properties.LOCAL_SEARCH_BUDGET = 100;
Properties.LOCAL_SEARCH_BUDGET_TYPE = LocalSearchBudgetType.FITNESS_EVALUATIONS;
Collection<Constraint<?>> constraints = buildConstraintSystem();
System.out.println("Constraints:");
for (Constraint<?> c : constraints) {
System.out.println(c.toString());
}
System.out.println("");
System.out.println("Initial: " + INIT_STRING);
EvoSuiteSolver solver = new EvoSuiteSolver();
try {
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
assertNotNull(model);
Object var0 = model.get("var0");
System.out.println("Expected: " + EXPECTED_STRING);
System.out.println("Found: " + var0);
assertEquals(EXPECTED_STRING, var0);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testEQVariable.
@Test
public void testEQVariable() throws SolverEmptyQueryException {
int var1 = 0;
int var2 = 1;
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.EQ, new IntegerVariable("test2", var2, -1000000, 1000000)));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
if (model.containsKey("test1"))
var1 = ((Number) model.get("test1")).intValue();
if (model.containsKey("test2"))
var2 = ((Number) model.get("test2")).intValue();
assertEquals(var1, var2);
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations