Search in sources :

Example 56 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.

the class StrongMutationTestFitness method runTest.

/**
 * {@inheritDoc}
 */
public static ExecutionResult runTest(TestCase test, Mutation mutant) {
    ExecutionResult result = new ExecutionResult(test, mutant);
    try {
        if (mutant != null)
            logger.debug("Executing test for mutant " + mutant.getId() + ": \n" + test.toCode());
        else
            logger.debug("Executing test without mutant");
        if (mutant != null)
            MutationObserver.activateMutation(mutant);
        result = TestCaseExecutor.getInstance().execute(test);
        if (mutant != null)
            MutationObserver.deactivateMutation(mutant);
        int num = test.size();
        if (!result.noThrownExceptions()) {
            num = result.getFirstPositionOfThrownException();
        }
        // if (mutant == null)
        MaxStatementsStoppingCondition.statementsExecuted(num);
        int i = 0;
        for (AssertionTraceObserver<?> observer : observers) {
            result.setTrace(observer.getTrace(), observerClasses[i++]);
        }
    } catch (Exception e) {
        throw new Error(e);
    }
    return result;
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 57 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.

the class StrongMutationTestFitness method ensureExecutionResultHasTraces.

private void ensureExecutionResultHasTraces(TestChromosome individual, ExecutionResult result) {
    if (result.getTraces().isEmpty() && observerClasses.length > 0) {
        ExecutionResult newResult = runTest(individual.getTestCase());
        for (Class<?> observerClass : observerClasses) {
            OutputTrace<?> trace = newResult.getTrace(observerClass);
            result.setTrace(trace, observerClass);
        }
    }
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 58 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.

the class RhoCoverageSuiteFitness method getFitness.

protected double getFitness(AbstractTestSuiteChromosome<? extends ExecutableChromosome> suite, boolean updateFitness) {
    Set<Set<Integer>> tmp_coverage_matrix = new LinkedHashSet<Set<Integer>>(this.coverage_matrix_generated_so_far);
    double fitness = 1.0;
    int number_of_goals = RhoCoverageFactory.getNumberGoals();
    int number_of_ones = RhoCoverageFactory.getNumber_of_Ones() + this.previous_number_of_ones;
    int number_of_test_cases = RhoCoverageFactory.getNumber_of_Test_Cases() + this.previous_number_of_test_cases;
    List<ExecutionResult> results = runTestSuite(suite);
    for (int i = 0; i < results.size(); i++) {
        // Execute test cases and collect the covered lines
        ExecutionResult result = results.get(i);
        Set<Integer> coveredLines = result.getTrace().getCoveredLines();
        if (Properties.STRATEGY == Properties.Strategy.ENTBUG) {
            // order set
            List<Integer> l_coveredLines = new ArrayList<Integer>(coveredLines);
            Collections.sort(l_coveredLines);
            Set<Integer> coveredLinesOrdered = new LinkedHashSet<Integer>();
            for (Integer coveredLine : l_coveredLines) {
                coveredLinesOrdered.add(coveredLine);
            }
            // no coverage
            if (coveredLinesOrdered.size() == 0) {
                continue;
            } else // already exists locally
            if (tmp_coverage_matrix.add(coveredLinesOrdered) == false) {
                continue;
            } else // already exists on the original test suite
            if (RhoCoverageFactory.exists(l_coveredLines)) {
                continue;
            } else // good
            {
                number_of_ones += coveredLinesOrdered.size();
                number_of_test_cases++;
            }
        } else {
            number_of_ones += coveredLines.size();
            number_of_test_cases++;
        }
    }
    // was not possible to generate new test cases
    if (number_of_test_cases == 0.0) {
        // penalise this suite
        fitness = 1.0;
    } else {
        fitness = ((double) number_of_ones) / ((double) number_of_test_cases) / ((double) number_of_goals);
        fitness = Math.abs(0.5 - fitness);
    }
    if (updateFitness) {
        updateIndividual(this, suite, fitness);
    }
    return fitness;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 59 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.

the class CoverageArchive method addToArchive.

private void addToArchive(F target, T solution) {
    this.uncovered.remove(target);
    this.covered.put(target, solution);
    this.removeNonCoveredTargetOfAMethod(target);
    this.hasBeenUpdated = true;
    ExecutionResult result = solution.getLastExecutionResult();
    if (result != null && (result.hasTimeout() || result.hasTestException())) {
        AtMostOnceLogger.warn(logger, "A solution with a timeout/exception result has been added to the archive. The covered goal was " + target.toString());
    }
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 60 with ExecutionResult

use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.

the class IntegerLocalSearch method iterate.

private boolean iterate(long delta, LocalSearchObjective<TestChromosome> objective, TestChromosome test, NumericalPrimitiveStatement<T> p, int statement) {
    boolean improvement = false;
    T oldValue = p.getValue();
    ExecutionResult oldResult = test.getLastExecutionResult();
    p.increment(delta);
    logger.info("Trying increment " + delta + " of " + p.getCode());
    while (objective.hasImproved(test)) {
        oldValue = p.getValue();
        oldResult = test.getLastExecutionResult();
        improvement = true;
        delta = 2 * delta;
        p.increment(delta);
        logger.info("Trying increment " + delta + " of " + p.getCode());
    }
    logger.info("No improvement on " + p.getCode());
    p.setValue(oldValue);
    test.setLastExecutionResult(oldResult);
    test.setChanged(false);
    logger.info("Final value of this iteration: " + p.getValue());
    return improvement;
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Aggregations

ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)93 TestChromosome (org.evosuite.testcase.TestChromosome)33 HashSet (java.util.HashSet)15 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)15 ArrayList (java.util.ArrayList)11 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)10 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)9 TestCase (org.evosuite.testcase.TestCase)9 VariableReference (org.evosuite.testcase.variable.VariableReference)9 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)7 ArrayReference (org.evosuite.testcase.variable.ArrayReference)7 Set (java.util.Set)6 AbstractTestSuiteChromosome (org.evosuite.testsuite.AbstractTestSuiteChromosome)6 Map (java.util.Map)4 Entry (java.util.Map.Entry)3 ExecutionTrace (org.evosuite.testcase.execution.ExecutionTrace)3