use of org.evosuite.continuous.project.ProjectStaticData.ClassInfo in project evosuite by EvoSuite.
the class ProjectAnalyzer method analyze.
/**
* Analyze the classes in the given target
* @return
*/
public ProjectStaticData analyze() {
ProjectStaticData data = new ProjectStaticData();
if (Properties.CTG_SCHEDULE.equals(AvailableSchedule.HISTORY)) {
data.initializeLocalHistory();
}
for (String className : getCutsToAnalyze()) {
Class<?> theClass = null;
int numberOfBranches = -1;
boolean hasCode = false;
Properties.TARGET_CLASS = className;
InstrumentingClassLoader instrumenting = new InstrumentingClassLoader();
BranchPool.getInstance(instrumenting).reset();
try {
/*
* to access number of branches, we need to use
* instrumenting class loader. But loading a class would
* execute its static code, and so we need to
* use a security manager.
*/
Sandbox.goingToExecuteUnsafeCodeOnSameThread();
instrumenting.loadClass(className);
numberOfBranches = BranchPool.getInstance(instrumenting).getBranchCounter();
hasCode = (numberOfBranches > 0) || (BranchPool.getInstance(instrumenting).getBranchlessMethods().size() > 0);
/*
* just to avoid possible issues with instrumenting classloader
*/
theClass = ClassLoader.getSystemClassLoader().loadClass(className);
// TODO kind
// if(theClass.isInterface()){
// kind = ClassKind.INTERFACE;
// } else if(theClass.is Modifier.isAbstract( someClass.getModifiers() );
} catch (Exception e) {
logger.warn("Cannot handle " + className + " due to: " + e.getClass() + " " + e.getMessage());
continue;
} finally {
Sandbox.doneWithExecutingUnsafeCodeOnSameThread();
BranchPool.getInstance(instrumenting).reset();
Properties.TARGET_CLASS = "";
}
ClassInfo ci = new ClassInfo(theClass, numberOfBranches, hasCode);
data.addNewClass(ci);
if (Properties.CTG_SCHEDULE == AvailableSchedule.HISTORY) {
ci.setChanged(data.hasChanged(theClass.getCanonicalName() + ".java"));
ci.isToTest(data.isToTest(theClass.getCanonicalName(), HistorySchedule.COMMIT_IMPROVEMENT));
}
}
return data;
}
use of org.evosuite.continuous.project.ProjectStaticData.ClassInfo in project evosuite by EvoSuite.
the class SimpleSchedule method createScheduleOnce.
@Override
protected List<JobDefinition> createScheduleOnce() {
assert enoughBudgetForAll();
ProjectStaticData data = scheduler.getProjectData();
int totalBudgetInSeconds = 60 * scheduler.getConfiguration().timeInMinutes * scheduler.getConfiguration().getNumberOfUsableCores();
List<JobDefinition> jobs = new LinkedList<JobDefinition>();
// simple case, distribute budget equally
int cores = scheduler.getConfiguration().getNumberOfUsableCores();
int cuts = data.getTotalNumberOfTestableCUTs();
int slots = (int) Math.round(cores * Math.ceil((double) cuts / (double) cores));
int budgetInSecondsPerCUT = totalBudgetInSeconds / slots;
for (ClassInfo info : data.getClassInfos()) {
if (!info.isTestable()) {
continue;
}
JobDefinition job = new JobDefinition(budgetInSecondsPerCUT, scheduler.getConfiguration().getConstantMemoryPerJob(), info.getClassName(), 0, null, null);
jobs.add(job);
}
return jobs;
}
use of org.evosuite.continuous.project.ProjectStaticData.ClassInfo in project evosuite by EvoSuite.
the class ProjectGraph method removeNonCUT.
private void removeNonCUT(Set<String> set) throws IllegalArgumentException {
Iterator<String> iter = set.iterator();
while (iter.hasNext()) {
String name = iter.next();
ClassInfo info = data.getClassInfo(name);
if (info == null) {
throw new IllegalArgumentException("Class " + name + " does not belong to the SUT");
}
if (!info.isTestable()) {
iter.remove();
}
}
}
use of org.evosuite.continuous.project.ProjectStaticData.ClassInfo in project evosuite by EvoSuite.
the class HistorySchedule method createScheduleOnce.
@Override
protected List<JobDefinition> createScheduleOnce() {
ProjectStaticData data = this.scheduler.getProjectData();
int maximumBudgetPerCore = 60 * this.scheduler.getConfiguration().timeInMinutes;
// the total budget we need to choose how to allocate
int totalBudget = maximumBudgetPerCore * this.scheduler.getConfiguration().getNumberOfUsableCores();
// a part of the budget is fixed, as each CUT needs a minimum of it
int minTime = 60 * this.scheduler.getConfiguration().minMinutesPerJob * data.getTotalNumberOfTestableCUTs();
// this is what left from the minimum allocation, and that now we can
// choose how best to allocate
int extraTime = totalBudget - minTime;
// check how much time we can give extra for each branch in a CUT
int number_of_branches = data.getTotalNumberOfBranches();
double timePerBranch = number_of_branches == 0.0 ? 0.0 : (double) extraTime / (double) number_of_branches;
List<ClassInfo> classesInfo = new ArrayList<ClassInfo>(data.getClassInfos());
// classes that have been changed first
Collections.sort(classesInfo, new Comparator<ClassInfo>() {
@Override
public int compare(ClassInfo a, ClassInfo b) {
if (a.hasChanged() && !b.hasChanged()) {
return -1;
} else if (!a.hasChanged() && b.hasChanged()) {
return 1;
}
// otherwise, get the most difficult classes first
return Integer.compare(b.numberOfBranches, a.numberOfBranches);
}
});
int totalLeftOver = 0;
int totalBudgetUsed = 0;
List<JobDefinition> jobs = new LinkedList<JobDefinition>();
for (ClassInfo c_info : classesInfo) {
if (!c_info.isTestable()) {
continue;
}
if (!c_info.hasChanged() && !c_info.isToTest()) {
LoggingUtils.getEvoLogger().info("- Skipping class " + c_info.getClassName() + " because it does not seem to be worth it");
continue;
}
double budget = 60.0 * scheduler.getConfiguration().minMinutesPerJob + (c_info.numberOfBranches * timePerBranch);
// classes that have been modified could get more time than 'normal' classes
budget *= c_info.hasChanged() ? HistorySchedule.MODIFIED : HistorySchedule.NOT_MODIFIED;
if (budget > maximumBudgetPerCore) {
/*
* Need to guarantee that no job has more than maximumBudgetPerCore regardless of number of
* cores
*/
totalLeftOver += (budget - maximumBudgetPerCore);
budget = maximumBudgetPerCore;
}
if ((totalBudgetUsed + budget) <= totalBudget) {
totalBudgetUsed += budget;
LoggingUtils.getEvoLogger().info("+ Going to generate test cases for " + c_info.getClassName() + " using a time budget of " + budget + " seconds. Status of it [" + (c_info.hasChanged() ? "modified" : "not modified") + "]");
jobs.add(new JobDefinition((int) budget, this.scheduler.getConfiguration().getConstantMemoryPerJob(), c_info.getClassName(), 0, null, null));
} else {
LoggingUtils.getEvoLogger().info("- There is not enough time budget to test " + c_info.getClassName() + ". Status of it [" + (c_info.hasChanged() ? "modified" : "not modified") + "]");
// mark this CUT as not tested. this is useful to later on distinguish
// classes that EvoSuite failed to generate test cases and classes that
// we didn't actually create any job for
c_info.isToTest(false);
}
}
totalLeftOver += (totalBudget - totalBudgetUsed);
/*
* do we still have some more budget to allocate? and is it less
* than totalBudget? (because if it is equal to totalBudget, means
* that we have skipped all classes, and therefore there is not point
* of distributing left over budget as all classes will be skipped)
*/
if (totalLeftOver > 0 && totalLeftOver < totalBudget) {
LoggingUtils.getEvoLogger().info("Distributing left budget (" + totalLeftOver + ")");
distributeExtraBudgetEvenly(jobs, totalLeftOver, maximumBudgetPerCore);
}
return jobs;
}
use of org.evosuite.continuous.project.ProjectStaticData.ClassInfo in project evosuite by EvoSuite.
the class ProjectGraphTest method testGetAllCUTsParents.
@Test
public void testGetAllCUTsParents() {
ProjectStaticData data = new ProjectStaticData();
data.addNewClass(new ClassInfo(A.class, 1, true));
data.addNewClass(new ClassInfo(B.class, 1, true));
data.addNewClass(new ClassInfo(C.class, 0, false));
data.addNewClass(new ClassInfo(D.class, 0, false));
data.addNewClass(new ClassInfo(E.class, 1, true));
data.addNewClass(new ClassInfo(F.class, 0, false));
data.addNewClass(new ClassInfo(G.class, 1, true));
ProjectGraph graph = data.getProjectGraph();
Set<String> forA = graph.getAllCUTsParents(A.class.getName());
Set<String> forB = graph.getAllCUTsParents(B.class.getName());
Set<String> forC = graph.getAllCUTsParents(C.class.getName());
Set<String> forD = graph.getAllCUTsParents(D.class.getName());
Set<String> forE = graph.getAllCUTsParents(E.class.getName());
Set<String> forF = graph.getAllCUTsParents(F.class.getName());
Set<String> forG = graph.getAllCUTsParents(G.class.getName());
Assert.assertEquals(0, forA.size());
Assert.assertEquals(1, forB.size());
Assert.assertEquals(0, forC.size());
Assert.assertEquals(0, forD.size());
Assert.assertEquals(0, forE.size());
Assert.assertEquals(0, forF.size());
Assert.assertEquals(1, forG.size());
}
Aggregations