use of org.evosuite.rmi.service.ClientState 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.ClientState 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.ClientState 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.ClientState in project evosuite by EvoSuite.
the class ExternalProcessHandler method startExternalProcessPrinter.
/**
* <p>
* startExternalProcessPrinter
* </p>
*/
protected void startExternalProcessPrinter() {
if (output_printer == null || !output_printer.isAlive()) {
output_printer = new Thread() {
@Override
public void run() {
try {
BufferedReader proc_in = new BufferedReader(new InputStreamReader(process.getInputStream()));
int data = 0;
while (data != -1 && !isInterrupted()) {
data = proc_in.read();
if (data != -1 && Properties.PRINT_TO_SYSTEM) {
System.out.print((char) data);
}
}
} catch (Exception e) {
if (MasterServices.getInstance().getMasterNode() == null)
return;
boolean finished = true;
for (ClientState state : MasterServices.getInstance().getMasterNode().getCurrentState()) {
if (state != ClientState.DONE) {
finished = false;
break;
}
}
if (!finished)
logger.error("Exception while reading output of client process. " + e.getMessage());
else
logger.debug("Exception while reading output of client process. " + e.getMessage());
}
}
};
output_printer.start();
}
if (error_printer == null || !error_printer.isAlive()) {
error_printer = new Thread() {
@Override
public void run() {
try {
BufferedReader proc_in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
int data = 0;
String errorLine = "";
while (data != -1 && !isInterrupted()) {
data = proc_in.read();
if (data != -1 && Properties.PRINT_TO_SYSTEM) {
System.err.print((char) data);
errorLine += (char) data;
if ((char) data == '\n') {
logger.error(errorLine);
errorLine = "";
}
}
}
} catch (Exception e) {
if (MasterServices.getInstance().getMasterNode() == null)
return;
boolean finished = true;
for (ClientState state : MasterServices.getInstance().getMasterNode().getCurrentState()) {
if (state != ClientState.DONE) {
finished = false;
break;
}
}
if (!finished)
logger.error("Exception while reading output of client process. " + e.getMessage());
else
logger.debug("Exception while reading output of client process. " + e.getMessage());
}
}
};
error_printer.start();
}
if (Properties.SHOW_PROGRESS && (Properties.LOG_LEVEL == null || (!Properties.LOG_LEVEL.equals("info") && !Properties.LOG_LEVEL.equals("debug") && !Properties.LOG_LEVEL.equals("trace")))) {
ConsoleProgressBar.startProgressBar();
}
}
use of org.evosuite.rmi.service.ClientState 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