Search in sources :

Example 11 with SolverResult

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);
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) SolverErrorException(org.evosuite.symbolic.solver.SolverErrorException) SolverParseException(org.evosuite.symbolic.solver.SolverParseException) SolverResult(org.evosuite.symbolic.solver.SolverResult)

Example 12 with SolverResult

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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Test(org.junit.Test)

Example 13 with SolverResult

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;
}
Also used : Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) SolverResult(org.evosuite.symbolic.solver.SolverResult) Constraint(org.evosuite.symbolic.expr.Constraint) LinkedList(java.util.LinkedList)

Example 14 with 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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) SolverResult(org.evosuite.symbolic.solver.SolverResult) Test(org.junit.Test)

Example 15 with SolverResult

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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Aggregations

SolverResult (org.evosuite.symbolic.solver.SolverResult)50 Test (org.junit.Test)37 Constraint (org.evosuite.symbolic.expr.Constraint)36 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)34 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)31 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)27 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)26 ArrayList (java.util.ArrayList)24 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)14 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)7 HashMap (java.util.HashMap)6 Variable (org.evosuite.symbolic.expr.Variable)4 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 Solver (org.evosuite.symbolic.solver.Solver)3 SolverCache (org.evosuite.symbolic.solver.SolverCache)3 SolverEmptyQueryException (org.evosuite.symbolic.solver.SolverEmptyQueryException)3 SolverErrorException (org.evosuite.symbolic.solver.SolverErrorException)3