use of org.evosuite.rmi.service.ClientStateInformation in project evosuite by EvoSuite.
the class SimpleMutationAssertionGenerator method addAssertions.
@Override
public void addAssertions(TestSuiteChromosome suite) {
setupClassLoader(suite);
if (!Properties.hasTargetClassBeenLoaded()) {
// Need to load class explicitly since it was re-instrumented
Properties.getTargetClassAndDontInitialise();
if (!Properties.hasTargetClassBeenLoaded()) {
logger.warn("Could not initialize SUT before Assertion generation");
}
}
Set<Integer> tkilled = new HashSet<>();
int numTest = 0;
boolean timeIsShort = false;
for (TestCase test : suite.getTests()) {
if (!TimeController.getInstance().isThereStillTimeInThisPhase()) {
logger.warn("Reached maximum time to generate assertions, aborting assertion generation");
break;
}
// If at 50% of the time we have only done X% of the tests, then don't minimise
if (!timeIsShort && TimeController.getInstance().getPhasePercentage() > Properties.ASSERTION_MINIMIZATION_FALLBACK_TIME) {
if (numTest < Properties.ASSERTION_MINIMIZATION_FALLBACK * suite.size()) {
logger.warn("Assertion minimization is taking too long ({}% of time used, but only {}/{} tests minimized), falling back to using all assertions", TimeController.getInstance().getPhasePercentage(), numTest, suite.size());
timeIsShort = true;
}
}
if (timeIsShort) {
CompleteAssertionGenerator generator = new CompleteAssertionGenerator();
generator.addAssertions(test);
numTest++;
} else {
// Set<Integer> killed = new HashSet<Integer>();
addAssertions(test, tkilled);
// progressMonitor.updateStatus((100 * numTest++) / tests.size());
ClientState state = ClientState.ASSERTION_GENERATION;
ClientStateInformation information = new ClientStateInformation(state);
information.setProgress((100 * numTest++) / suite.size());
ClientServices.getInstance().getClientNode().changeState(state, information);
}
}
calculateMutationScore(tkilled);
restoreCriterion(suite);
}
use of org.evosuite.rmi.service.ClientStateInformation in project evosuite by EvoSuite.
the class ProgressMonitor method updateStatus.
/**
* <p>
* updateStatus
* </p>
*
* @param percent
* a int.
*/
public void updateStatus(int percent) {
ClientState state = ClientState.SEARCH;
ClientStateInformation information = new ClientStateInformation(state);
information.setCoverage(currentCoverage);
information.setProgress(percent);
information.setIteration(iteration);
// LoggingUtils.getEvoLogger().info("Setting to: "+state.getNumPhase()+": "+information.getCoverage()+"/"+information.getProgress());
ClientServices.getInstance().getClientNode().changeState(state, information);
lastProgress = percent;
lastCoverage = currentCoverage;
// out.writeInt(percent);
// out.writeInt(currentPhase);
// out.writeInt(phases);
// out.writeInt(currentCoverage);
// out.writeObject(currentTask);
}
use of org.evosuite.rmi.service.ClientStateInformation in project evosuite by EvoSuite.
the class TestGenerationJob method runEvoSuite.
protected ArrayList<TestGenerationResult> runEvoSuite(final IProgressMonitor monitor) {
monitor.beginTask("EvoSuite test suite generation", 100);
ArrayList<TestGenerationResult> tgrs = new ArrayList<TestGenerationResult>();
try {
List<String> commands = createCommand();
commands.addAll(getAdditionalParameters());
String[] command = new String[commands.size()];
commands.toArray(command);
System.out.println("* EvoSuite command: " + Arrays.asList(command));
setupRMI();
Thread progressMonitor = new Thread() {
@Override
public void run() {
int percent = 0;
int last = 0;
String subTask = "";
// try {
while (percent != -1 && !isInterrupted()) {
MasterNodeLocal masterNode = MasterServices.getInstance().getMasterNode();
if (masterNode != null) {
Collection<ClientStateInformation> currentStates = MasterServices.getInstance().getMasterNode().getCurrentStateInformation();
if (currentStates.size() == 1) {
ClientStateInformation currentState = currentStates.iterator().next();
lastState = currentState;
percent = currentState.getOverallProgress();
if (percent >= 100 && currentState.getState() == ClientState.NOT_STARTED)
continue;
String currentTask = currentState.getState().getDescription();
// + "%]";
if (percent > last || !subTask.equals(currentTask)) {
subTask = currentTask;
monitor.worked(percent - last);
monitor.subTask(subTask);
last = percent;
}
}
}
try {
// TODO - should use observer pattern
sleep(250);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("* Shut down progress monitor");
}
// } catch (Exception e) {
// System.err.println(this.getClass().getCanonicalName() + ": Exception while reading output of client process " + e);
// System.err.println(e.getStackTrace().toString());
// }
}
}
};
progressMonitor.start();
tgrs = launchProcess(command);
progressMonitor.interrupt();
try {
target.getProject().refreshLocal(IProject.DEPTH_INFINITE, null);
} catch (CoreException e) {
e.printStackTrace();
}
System.out.println("Job returned normally");
monitor.done();
/*
GenerationResult result = new GenerationResult(shell, SWT.DIALOG_TRIM
| SWT.APPLICATION_MODAL);
result.open();
return Status.OK_STATUS;
*/
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
return tgrs;
}
use of org.evosuite.rmi.service.ClientStateInformation in project evosuite by EvoSuite.
the class TestSuiteMinimizer method updateClientStatus.
private void updateClientStatus(int progress) {
ClientState state = ClientState.MINIMIZATION;
ClientStateInformation information = new ClientStateInformation(state);
information.setProgress(progress);
ClientServices.getInstance().getClientNode().changeState(state, information);
}
use of org.evosuite.rmi.service.ClientStateInformation in project evosuite by EvoSuite.
the class TestSuiteMinimizer method minimizeTests.
/**
* Minimize test suite with respect to the isCovered Method of the goals
* defined by the supplied TestFitnessFactory
*
* @param suite a {@link org.evosuite.testsuite.TestSuiteChromosome} object.
*/
private void minimizeTests(TestSuiteChromosome suite) {
logger.info("Minimizing per test");
ExecutionTracer.enableTraceCalls();
for (TestChromosome test : suite.getTestChromosomes()) {
// implies test.clearCachedResults();
test.setChanged(true);
}
List<TestFitnessFunction> goals = new ArrayList<TestFitnessFunction>();
for (TestFitnessFactory<?> ff : testFitnessFactories) {
goals.addAll(ff.getCoverageGoals());
}
filterJUnitCoveredGoals(goals);
int currentGoal = 0;
int numGoals = goals.size();
if (Properties.MINIMIZE_SORT)
Collections.sort(goals);
Set<TestFitnessFunction> covered = new LinkedHashSet<TestFitnessFunction>();
List<TestChromosome> minimizedTests = new ArrayList<TestChromosome>();
TestSuiteWriter minimizedSuite = new TestSuiteWriter();
for (TestFitnessFunction goal : goals) {
updateClientStatus(numGoals > 0 ? 100 * currentGoal / numGoals : 100);
currentGoal++;
if (isTimeoutReached()) {
/*
* FIXME: if timeout, this algorithm should be changed in a way that the modifications
* done so far are not lost
*/
logger.warn("Minimization timeout. Roll back to original test suite");
return;
}
logger.info("Considering goal: " + goal);
if (Properties.MINIMIZE_SKIP_COINCIDENTAL) {
for (TestChromosome test : minimizedTests) {
if (isTimeoutReached()) {
logger.warn("Minimization timeout. Roll back to original test suite");
return;
}
if (goal.isCovered(test)) {
logger.info("Covered by minimized test: " + goal);
covered.add(goal);
// test.getTestCase().addCoveredGoal(goal); // FIXME why? goal.isCovered(test) is already adding the goal
break;
}
}
}
if (covered.contains(goal)) {
logger.info("Already covered: " + goal);
logger.info("Now the suite covers " + covered.size() + "/" + goals.size() + " goals");
continue;
}
List<TestChromosome> coveringTests = new ArrayList<TestChromosome>();
for (TestChromosome test : suite.getTestChromosomes()) {
if (goal.isCovered(test)) {
coveringTests.add(test);
}
}
Collections.sort(coveringTests);
if (!coveringTests.isEmpty()) {
TestChromosome test = coveringTests.get(0);
org.evosuite.testcase.TestCaseMinimizer minimizer = new org.evosuite.testcase.TestCaseMinimizer(goal);
TestChromosome copy = (TestChromosome) test.clone();
minimizer.minimize(copy);
if (isTimeoutReached()) {
logger.warn("Minimization timeout. Roll back to original test suite");
return;
}
// TODO: Need proper list of covered goals
copy.getTestCase().clearCoveredGoals();
// Add ALL goals covered by the minimized test
for (TestFitnessFunction g : goals) {
if (g.isCovered(copy)) {
// isCovered(copy) adds the goal
covered.add(g);
logger.info("Goal covered by minimized test: " + g);
}
}
minimizedTests.add(copy);
minimizedSuite.insertTest(copy.getTestCase());
logger.info("After new test the suite covers " + covered.size() + "/" + goals.size() + " goals");
} else {
logger.info("Goal is not covered: " + goal);
}
}
logger.info("Minimized suite covers " + covered.size() + "/" + goals.size() + " goals");
suite.tests.clear();
for (TestCase test : minimizedSuite.getTestCases()) {
suite.addTest(test);
}
if (Properties.MINIMIZE_SECOND_PASS) {
removeRedundantTestCases(suite, goals);
}
double suiteCoverage = suite.getCoverage();
logger.info("Setting coverage to: " + suiteCoverage);
ClientState state = ClientState.MINIMIZATION;
ClientStateInformation information = new ClientStateInformation(state);
information.setProgress(100);
information.setCoverage((int) (Math.round(suiteCoverage * 100)));
ClientServices.getInstance().getClientNode().changeState(state, information);
for (TestFitnessFunction goal : goals) {
if (!covered.contains(goal))
logger.info("Failed to cover: " + goal);
}
// suite.tests = minimizedTests;
}
Aggregations