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;
}
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;
}
Aggregations