use of org.evosuite.continuous.project.ProjectStaticData 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 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 in project evosuite by EvoSuite.
the class JobSchedulerTest method testNonExceedingBudget.
@Test
public void testNonExceedingBudget() {
String[] cuts = new String[] { NoBranches.class.getName(), Trivial.class.getName(), MoreBranches.class.getName() };
ProjectAnalyzer analyzer = new ProjectAnalyzer(cuts);
ProjectStaticData data = analyzer.analyze();
int cores = 2;
int memory = 1400;
int budget = 10;
CtgConfiguration conf = new CtgConfiguration(memory, cores, budget, 1, false, AvailableSchedule.BUDGET);
JobScheduler scheduler = new JobScheduler(data, conf);
List<JobDefinition> jobs = scheduler.createNewSchedule();
Assert.assertNotNull(jobs);
Assert.assertEquals(3, jobs.size());
for (JobDefinition job : jobs) {
Assert.assertEquals(700, job.memoryInMB);
}
Assert.assertEquals(MoreBranches.class.getName(), jobs.get(0).cut);
Assert.assertEquals(Trivial.class.getName(), jobs.get(1).cut);
Assert.assertEquals(NoBranches.class.getName(), jobs.get(2).cut);
long dif01 = jobs.get(0).seconds - jobs.get(1).seconds;
long dif12 = jobs.get(1).seconds - jobs.get(2).seconds;
Assert.assertTrue("" + dif01, dif01 > 0);
Assert.assertTrue("" + dif12, dif12 > 0);
int sum = jobs.get(0).seconds + jobs.get(1).seconds + jobs.get(2).seconds;
Assert.assertTrue("wrong value " + sum, sum <= (cores * budget * 60));
for (JobDefinition job : jobs) {
Assert.assertTrue("wrong " + job.seconds, job.seconds <= budget * 60);
}
}
use of org.evosuite.continuous.project.ProjectStaticData in project evosuite by EvoSuite.
the class JobSchedulerTest method testSeedingAndBudget.
@Test
public void testSeedingAndBudget() {
String[] cuts = new String[] { Trivial.class.getName(), UsingSimpleAndTrivial.class.getName(), Simple.class.getName() };
ProjectAnalyzer analyzer = new ProjectAnalyzer(cuts);
ProjectStaticData data = analyzer.analyze();
int cores = 2;
int memory = 1800;
int budget = 3;
CtgConfiguration conf = new CtgConfiguration(memory, cores, budget, 1, false, AvailableSchedule.BUDGET_AND_SEEDING);
JobScheduler scheduler = new JobScheduler(data, conf);
List<JobDefinition> jobs = scheduler.createNewSchedule();
Assert.assertNotNull(jobs);
Assert.assertEquals("Wrong number of jobs: " + jobs.toString(), 3, jobs.size());
// UsingSimpleAndTrivial should be the last in the schedule, as it depends on the other 2
JobDefinition seeding = jobs.get(2);
Assert.assertNotNull(seeding);
Assert.assertEquals(UsingSimpleAndTrivial.class.getName(), seeding.cut);
Set<String> in = seeding.inputClasses;
Assert.assertNotNull(in);
System.out.println(in.toString());
Assert.assertTrue(in.contains(Simple.class.getName()));
Assert.assertTrue(in.contains(Trivial.class.getName()));
Assert.assertEquals(2, in.size());
// should be the first, as it has the highest number of branches among the jobs with no depencencies
JobDefinition simple = jobs.get(0);
Assert.assertNotNull(simple);
Assert.assertEquals(Simple.class.getName(), simple.cut);
int simpleTime = jobs.get(0).seconds;
int trivialTime = jobs.get(1).seconds;
int seedingTime = jobs.get(2).seconds;
System.out.println("Ordered times: " + simpleTime + ", " + trivialTime + ", " + seedingTime);
Assert.assertTrue(simpleTime > trivialTime);
// seeding, even if last, it should have more time, as it has most branches
Assert.assertTrue(simpleTime < seedingTime);
Assert.assertTrue(trivialTime < seedingTime);
}
use of org.evosuite.continuous.project.ProjectStaticData in project evosuite by EvoSuite.
the class JobSchedulerTest method testSeeding.
@Test
public void testSeeding() {
String[] cuts = new String[] { BaseForSeeding.class.getName(), NoBranches.class.getName(), MoreBranches.class.getName(), SomeInterface.class.getName(), SomeInterfaceImpl.class.getName(), SomeBranches.class.getName(), OnlyAbstract.class.getName(), OnlyAbstractImpl.class.getName(), Trivial.class.getName() };
ProjectAnalyzer analyzer = new ProjectAnalyzer(cuts);
ProjectStaticData data = analyzer.analyze();
int cores = 3;
int memory = 1800;
int budget = 3;
CtgConfiguration conf = new CtgConfiguration(memory, cores, budget, 1, false, AvailableSchedule.SEEDING);
JobScheduler scheduler = new JobScheduler(data, conf);
List<JobDefinition> jobs = scheduler.createNewSchedule();
Assert.assertNotNull(jobs);
for (JobDefinition job : jobs) {
Assert.assertEquals(600, job.memoryInMB);
}
/*
* FIXME: in the long run, abstract class with no code should be skipped.
* at the moment, they are not, because there is default constructor that
* is automatically added
*/
// we have 9 classes, but 2 have no code
// FIXME should be 7
Assert.assertEquals("Wrong number of jobs: " + jobs.toString(), 8, jobs.size());
JobDefinition seeding = null;
for (JobDefinition job : jobs) {
if (job.cut.equals(BaseForSeeding.class.getName())) {
seeding = job;
break;
}
}
Assert.assertNotNull(seeding);
Set<String> in = seeding.inputClasses;
Assert.assertNotNull(in);
System.out.println(in.toString());
Assert.assertTrue(in.contains(NoBranches.class.getName()));
Assert.assertTrue(in.contains(SomeBranches.class.getName()));
Assert.assertTrue(in.contains(SomeInterfaceImpl.class.getName()));
Assert.assertTrue(in.contains(OnlyAbstractImpl.class.getName()));
// FIXME should be 4
Assert.assertEquals(5, in.size());
}
Aggregations