use of org.evosuite.continuous.project.ProjectStaticData in project evosuite by EvoSuite.
the class JobSchedulerTest method testBudget.
@Test
public void testBudget() {
String[] cuts = new String[] { SomeInterface.class.getName(), NoBranches.class.getName(), SomeBranches.class.getName(), MoreBranches.class.getName() };
ProjectAnalyzer analyzer = new ProjectAnalyzer(cuts);
ProjectStaticData data = analyzer.analyze();
int cores = 2;
int memory = 1400;
int budget = 2;
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);
// we have 4 classes, but one is an interface
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(SomeBranches.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));
}
use of org.evosuite.continuous.project.ProjectStaticData in project evosuite by EvoSuite.
the class JobSchedulerTest method testSimple.
@Test
public void testSimple() {
String[] cuts = new String[] { SomeInterface.class.getName(), NoBranches.class.getName(), SomeBranches.class.getName(), MoreBranches.class.getName() };
ProjectAnalyzer analyzer = new ProjectAnalyzer(cuts);
ProjectStaticData data = analyzer.analyze();
int cores = 2;
int memory = 1400;
int budget = 2;
CtgConfiguration conf = new CtgConfiguration(memory, cores, budget, 1, false, AvailableSchedule.SIMPLE);
JobScheduler scheduler = new JobScheduler(data, conf);
List<JobDefinition> jobs = scheduler.createNewSchedule();
Assert.assertNotNull(jobs);
// we have 4 classes, but one is an interface
Assert.assertEquals(3, jobs.size());
for (JobDefinition job : jobs) {
Assert.assertEquals(700, job.memoryInMB);
}
Assert.assertEquals(jobs.get(0).seconds, jobs.get(1).seconds);
Assert.assertEquals(jobs.get(2).seconds, jobs.get(1).seconds);
int sum = jobs.get(0).seconds + jobs.get(1).seconds + jobs.get(2).seconds;
Assert.assertTrue("wrong value " + sum, sum <= (cores * budget * 60));
}
use of org.evosuite.continuous.project.ProjectStaticData in project evosuite by EvoSuite.
the class JobSchedulerTest method testSeedingOrder.
@Test
public void testSeedingOrder() {
String[] cuts = new String[] { Simple.class.getName(), UsingSimpleAndTrivial.class.getName(), Trivial.class.getName() };
ProjectAnalyzer analyzer = new ProjectAnalyzer(cuts);
ProjectStaticData data = analyzer.analyze();
int cores = 3;
int memory = 1800;
int budget = 2;
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);
Assert.assertEquals("Wrong number of jobs: " + jobs.toString(), 3, jobs.size());
// UsingSimpleAndTrivial should be the last in the schedule, as it depends on the first 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());
}
use of org.evosuite.continuous.project.ProjectStaticData in project evosuite by EvoSuite.
the class BudgetSchedule method createScheduleOnce.
@Override
protected List<JobDefinition> createScheduleOnce() {
ProjectStaticData data = scheduler.getProjectData();
if (data.getTotalNumberOfBranches() == 0) {
return new SimpleSchedule(scheduler).createScheduleOnce();
}
int maximumBudgetPerCore = 60 * scheduler.getConfiguration().timeInMinutes;
/*
* the total budget we need to choose how to allocate
*/
int totalBudget = maximumBudgetPerCore * scheduler.getConfiguration().getNumberOfUsableCores();
/*
* a part of the budget is fixed, as each CUT needs a minimum
* of it.
*/
int minTime = 60 * 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
*/
double timePerBranch = (double) extraTime / (double) data.getTotalNumberOfBranches();
int totalLeftOver = 0;
List<JobDefinition> jobs = new LinkedList<>();
for (ClassInfo info : data.getClassInfos()) {
if (!info.isTestable()) {
continue;
}
/*
* there is a minimum that is equal to all jobs,
* plus extra time based on number of branches
*/
int budget = 60 * scheduler.getConfiguration().minMinutesPerJob + (int) (timePerBranch * info.numberOfBranches);
if (budget > maximumBudgetPerCore) {
/*
* Need to guarantee that no job has more than
* maximumBudgetPerCore regardless of number of cores
*/
totalLeftOver += (budget - maximumBudgetPerCore);
budget = maximumBudgetPerCore;
}
JobDefinition job = new JobDefinition(budget, scheduler.getConfiguration().getConstantMemoryPerJob(), info.getClassName(), 0, null, null);
jobs.add(job);
}
if (totalLeftOver > 0) {
/*
* we still have some more budget to allocate
*/
distributeExtraBudgetEvenly(jobs, totalLeftOver, maximumBudgetPerCore);
}
/*
* using scheduling theory, there could be different
* best orders to maximize CPU usage.
* Here, at least for the time being, for simplicity
* we just try to execute the most expensive jobs
* as soon as possible
*/
Collections.sort(jobs, (a, b) -> {
/*
* the job with takes most time will be "lower".
* recall that sorting is in ascending order
*/
return b.seconds - a.seconds;
});
return jobs;
}
use of org.evosuite.continuous.project.ProjectStaticData in project evosuite by EvoSuite.
the class ContinuousTestGeneration method execute.
/**
* Apply CTG, and return a string with some summary
*
* @return
*/
public String execute() {
// init the local storage manager
StorageManager storage = new StorageManager();
if (!storage.isStorageOk()) {
return "Failed to initialize local storage system";
}
if (Properties.CTG_DELETE_OLD_TMP_FOLDERS) {
storage.deleteAllOldTmpFolders();
}
if (!storage.createNewTmpFolders()) {
return "Failed to create tmp folders";
}
// check project
ProjectAnalyzer analyzer = new ProjectAnalyzer(target, prefix, cuts);
ProjectStaticData data = analyzer.analyze();
if (data.getTotalNumberOfTestableCUTs() == 0) {
return "There is no class to test in the chosen project\n" + "Target: " + target + "\n" + "Prefix: '" + prefix + "'\n";
}
if (Properties.CTG_DEBUG_PORT != null && data.getTotalNumberOfTestableCUTs() != 1) {
throw new IllegalStateException("Cannot debug CTG when more than one CUT is selected");
}
if (Properties.CTG_TIME_PER_CLASS != null) {
configuration = configuration.getWithChangedTime(Properties.CTG_TIME_PER_CLASS, data.getTotalNumberOfTestableCUTs());
}
JobScheduler scheduler = new JobScheduler(data, configuration);
JobExecutor executor = new JobExecutor(storage, projectClassPath, configuration);
// loop: define (partial) schedule
while (scheduler.canExecuteMore()) {
List<JobDefinition> jobs = scheduler.createNewSchedule();
executor.executeJobs(jobs, configuration.getNumberOfUsableCores());
executor.waitForJobs();
}
String description = storage.mergeAndCommitChanges(data, cuts);
if (exportFolder != null) {
try {
exportToFolder(".", exportFolder);
} catch (IOException e) {
return "Failed to export tests: " + e.getMessage();
}
}
// call home
if (configuration.callHome) {
// TODO
}
return description;
}
Aggregations