Search in sources :

Example 1 with ExecutionObserver

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

the class CoverageGoalTestNameGenerationStrategy method getUpdatedResults.

/**
 * Some criteria require re-execution with observers. Make sure the results are up-to-date
 *
 * @param requiredCriteria
 * @param origResults
 * @return
 */
private List<ExecutionResult> getUpdatedResults(List<Properties.Criterion> requiredCriteria, List<ExecutionResult> origResults) {
    List<ExecutionObserver> newObservers = new ArrayList<ExecutionObserver>();
    if (requiredCriteria.contains(Properties.Criterion.INPUT)) {
        newObservers.add(new InputObserver());
    }
    if (requiredCriteria.contains(Properties.Criterion.OUTPUT)) {
        newObservers.add(new OutputObserver());
    }
    if (newObservers.isEmpty()) {
        return origResults;
    }
    for (ExecutionObserver observer : newObservers) TestCaseExecutor.getInstance().addObserver(observer);
    List<ExecutionResult> newResults = new ArrayList<ExecutionResult>();
    for (ExecutionResult result : origResults) {
        ExecutionResult newResult = TestCaseExecutor.getInstance().runTest(result.test);
        newResults.add(newResult);
    }
    for (ExecutionObserver observer : newObservers) TestCaseExecutor.getInstance().removeObserver(observer);
    return newResults;
}
Also used : ExecutionObserver(org.evosuite.testcase.execution.ExecutionObserver) OutputObserver(org.evosuite.coverage.io.output.OutputObserver) InputObserver(org.evosuite.coverage.io.input.InputObserver) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 2 with ExecutionObserver

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

the class ConcolicExecution method executeConcolic.

public static List<BranchCondition> executeConcolic(DefaultTestCase defaultTestCase) {
    logger.debug("Preparing concolic execution");
    /**
     * Prepare DSC configuration
     */
    MainConfig.setInstance();
    /**
     * Path constraint and symbolic environment
     */
    SymbolicEnvironment env = new SymbolicEnvironment(classLoader);
    PathConditionCollector pc = new PathConditionCollector();
    /**
     * VM listeners
     */
    List<IVM> listeners = new ArrayList<IVM>();
    listeners.add(new CallVM(env, classLoader));
    listeners.add(new JumpVM(env, pc));
    listeners.add(new HeapVM(env, pc, classLoader));
    listeners.add(new LocalsVM(env));
    listeners.add(new ArithmeticVM(env, pc));
    listeners.add(new OtherVM(env));
    listeners.add(new SymbolicFunctionVM(env, pc));
    VM.getInstance().setListeners(listeners);
    VM.getInstance().prepareConcolicExecution();
    defaultTestCase.changeClassLoader(classLoader);
    SymbolicObserver symbolicExecObserver = new SymbolicObserver(env);
    Set<ExecutionObserver> originalExecutionObservers = TestCaseExecutor.getInstance().getExecutionObservers();
    TestCaseExecutor.getInstance().newObservers();
    TestCaseExecutor.getInstance().addObserver(symbolicExecObserver);
    logger.info("Starting concolic execution");
    ExecutionResult result = new ExecutionResult(defaultTestCase, null);
    try {
        logger.debug("Executing test");
        long startConcolicExecutionTime = System.currentTimeMillis();
        result = TestCaseExecutor.getInstance().execute(defaultTestCase, Properties.CONCOLIC_TIMEOUT);
        long estimatedConcolicExecutionTime = System.currentTimeMillis() - startConcolicExecutionTime;
        DSEStats.getInstance().reportNewConcolicExecutionTime(estimatedConcolicExecutionTime);
        MaxStatementsStoppingCondition.statementsExecuted(result.getExecutedStatements());
    } catch (Exception e) {
        logger.error("Exception during concolic execution {}", e);
        return new ArrayList<BranchCondition>();
    } finally {
        logger.debug("Cleaning concolic execution");
        TestCaseExecutor.getInstance().setExecutionObservers(originalExecutionObservers);
    }
    // ignore all callbacks from now on
    VM.disableCallBacks();
    List<BranchCondition> branches = pc.getPathCondition();
    logger.info("Concolic execution ended with " + branches.size() + " branches collected");
    if (!result.noThrownExceptions()) {
        int idx = result.getFirstPositionOfThrownException();
        logger.info("Exception thrown: " + result.getExceptionThrownAtPosition(idx));
    }
    logNrOfConstraints(branches);
    logger.debug("Cleaning concolic execution");
    TestCaseExecutor.getInstance().setExecutionObservers(originalExecutionObservers);
    return branches;
}
Also used : OtherVM(org.evosuite.symbolic.vm.OtherVM) ExecutionObserver(org.evosuite.testcase.execution.ExecutionObserver) IVM(org.evosuite.dse.IVM) ArithmeticVM(org.evosuite.symbolic.vm.ArithmeticVM) SymbolicFunctionVM(org.evosuite.symbolic.vm.SymbolicFunctionVM) ArrayList(java.util.ArrayList) SymbolicEnvironment(org.evosuite.symbolic.vm.SymbolicEnvironment) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) CallVM(org.evosuite.symbolic.vm.CallVM) Constraint(org.evosuite.symbolic.expr.Constraint) JumpVM(org.evosuite.symbolic.vm.JumpVM) PathConditionCollector(org.evosuite.symbolic.vm.PathConditionCollector) LocalsVM(org.evosuite.symbolic.vm.LocalsVM) HeapVM(org.evosuite.symbolic.vm.HeapVM)

Aggregations

ExecutionObserver (org.evosuite.testcase.execution.ExecutionObserver)2 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)2 ArrayList (java.util.ArrayList)1 InputObserver (org.evosuite.coverage.io.input.InputObserver)1 OutputObserver (org.evosuite.coverage.io.output.OutputObserver)1 IVM (org.evosuite.dse.IVM)1 Constraint (org.evosuite.symbolic.expr.Constraint)1 ArithmeticVM (org.evosuite.symbolic.vm.ArithmeticVM)1 CallVM (org.evosuite.symbolic.vm.CallVM)1 HeapVM (org.evosuite.symbolic.vm.HeapVM)1 JumpVM (org.evosuite.symbolic.vm.JumpVM)1 LocalsVM (org.evosuite.symbolic.vm.LocalsVM)1 OtherVM (org.evosuite.symbolic.vm.OtherVM)1 PathConditionCollector (org.evosuite.symbolic.vm.PathConditionCollector)1 SymbolicEnvironment (org.evosuite.symbolic.vm.SymbolicEnvironment)1 SymbolicFunctionVM (org.evosuite.symbolic.vm.SymbolicFunctionVM)1