Search in sources :

Example 1 with LocalsVM

use of org.evosuite.symbolic.vm.LocalsVM 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

ArrayList (java.util.ArrayList)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 ExecutionObserver (org.evosuite.testcase.execution.ExecutionObserver)1 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)1