Search in sources :

Example 1 with JobDefinition

use of org.evosuite.continuous.job.JobDefinition in project evosuite by EvoSuite.

the class OneTimeSchedule method distributeExtraBudgetEvenly.

protected void distributeExtraBudgetEvenly(List<JobDefinition> jobs, int totalLeftOver, int maximumBudgetPerCore) {
    int counter = 0;
    for (int i = 0; i < jobs.size(); i++) {
        JobDefinition job = jobs.get(i);
        assert job.seconds <= maximumBudgetPerCore;
        if (job.seconds < maximumBudgetPerCore) {
            counter++;
        }
    }
    if (totalLeftOver < counter || counter == 0) {
        /*
			 * no point in adding complex code to handle so little budget left.
			 * here we lost at most only one second per job...
			 * 
			 *  furthermore, it could happen that budget is left, but
			 *  all jobs have maximum. this happens if there are more
			 *  cores than CUTs
			 */
        return;
    }
    int extraPerJob = totalLeftOver / counter;
    for (int i = 0; i < jobs.size(); i++) {
        JobDefinition job = jobs.get(i);
        int toAdd = Math.min(extraPerJob, (maximumBudgetPerCore - job.seconds));
        if (toAdd > 0) {
            totalLeftOver -= toAdd;
            jobs.set(i, job.getByAddingBudget(toAdd));
        }
    }
    if (totalLeftOver > 0 && totalLeftOver >= counter) {
        // recursion
        distributeExtraBudgetEvenly(jobs, totalLeftOver, maximumBudgetPerCore);
    }
}
Also used : JobDefinition(org.evosuite.continuous.job.JobDefinition)

Example 2 with JobDefinition

use of org.evosuite.continuous.job.JobDefinition in project evosuite by EvoSuite.

the class SeedingSchedule method getSortedToSatisfyDependencies.

/**
 * Try (best effort) to sort the jobs in a way in which dependent jobs
 * are executed first. Try to maintain the relative order of the input list.
 * Note: even if sorting is not precise, still the job executor will be able to handle it
 *
 * @param jobs  A sorted copy of the input list
 */
protected static List<JobDefinition> getSortedToSatisfyDependencies(List<JobDefinition> jobs) {
    Queue<JobDefinition> toAssign = new LinkedList<JobDefinition>(jobs);
    List<JobDefinition> postponed = new LinkedList<JobDefinition>();
    List<JobDefinition> out = new ArrayList<JobDefinition>(jobs.size());
    Set<String> assigned = new HashSet<String>();
    mainLoop: while (!toAssign.isEmpty() || !postponed.isEmpty()) {
        JobDefinition chosenJob = null;
        // postponed jobs have the priority
        if (!postponed.isEmpty()) {
            Iterator<JobDefinition> iterator = postponed.iterator();
            postponedLoop: while (iterator.hasNext()) {
                JobDefinition job = iterator.next();
                if (job.areDependenciesSatisfied(jobs, assigned)) {
                    chosenJob = job;
                    iterator.remove();
                    break postponedLoop;
                }
            }
        }
        if (chosenJob == null && toAssign.isEmpty()) {
            /*
				 * nothing satisfied in 'postponed', and nothing left in 'toAssign'.
				 * so just pick up one (the oldest)
				 */
            assert !postponed.isEmpty();
            chosenJob = postponed.remove((int) 0);
        }
        if (chosenJob == null) {
            assert !toAssign.isEmpty();
            toExecuteLoop: while (!toAssign.isEmpty()) {
                JobDefinition job = toAssign.poll();
                if (job.areDependenciesSatisfied(jobs, assigned)) {
                    chosenJob = job;
                    break toExecuteLoop;
                } else {
                    postponed.add(job);
                }
            }
            if (chosenJob == null) {
                assert !postponed.isEmpty() && toAssign.isEmpty();
                continue mainLoop;
            }
        }
        out.add(chosenJob);
        assigned.add(chosenJob.cut);
    }
    return out;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JobDefinition(org.evosuite.continuous.job.JobDefinition) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with JobDefinition

use of org.evosuite.continuous.job.JobDefinition 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;
}
Also used : ProjectStaticData(org.evosuite.continuous.project.ProjectStaticData) JobDefinition(org.evosuite.continuous.job.JobDefinition) LinkedList(java.util.LinkedList) ClassInfo(org.evosuite.continuous.project.ProjectStaticData.ClassInfo)

Example 4 with JobDefinition

use of org.evosuite.continuous.job.JobDefinition 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;
}
Also used : ArrayList(java.util.ArrayList) ProjectStaticData(org.evosuite.continuous.project.ProjectStaticData) JobDefinition(org.evosuite.continuous.job.JobDefinition) LinkedList(java.util.LinkedList) ClassInfo(org.evosuite.continuous.project.ProjectStaticData.ClassInfo)

Example 5 with JobDefinition

use of org.evosuite.continuous.job.JobDefinition in project evosuite by EvoSuite.

the class SeedingScheduleTest method testSortingOneDependency.

@Test
public void testSortingOneDependency() {
    Set<String> dep1 = new HashSet<String>(Arrays.asList("e"));
    JobDefinition a = new JobDefinition(1, 1, "a", 0, dep1, null);
    JobDefinition b = new JobDefinition(1, 1, "b", 0, null, null);
    JobDefinition c = new JobDefinition(1, 1, "c", 0, null, null);
    JobDefinition d = new JobDefinition(1, 1, "d", 0, null, null);
    JobDefinition e = new JobDefinition(1, 1, "e", 0, null, null);
    List<JobDefinition> jobs = Arrays.asList(a, b, c, d, e);
    jobs = SeedingSchedule.getSortedToSatisfyDependencies(jobs);
    Assert.assertEquals("b", jobs.get(0).cut);
    Assert.assertEquals("c", jobs.get(1).cut);
    Assert.assertEquals("d", jobs.get(2).cut);
    Assert.assertEquals("e", jobs.get(3).cut);
    Assert.assertEquals("a", jobs.get(4).cut);
}
Also used : JobDefinition(org.evosuite.continuous.job.JobDefinition) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

JobDefinition (org.evosuite.continuous.job.JobDefinition)11 LinkedList (java.util.LinkedList)5 ProjectStaticData (org.evosuite.continuous.project.ProjectStaticData)5 HashSet (java.util.HashSet)4 ClassInfo (org.evosuite.continuous.project.ProjectStaticData.ClassInfo)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 JobExecutor (org.evosuite.continuous.job.JobExecutor)1 JobScheduler (org.evosuite.continuous.job.JobScheduler)1 StorageManager (org.evosuite.continuous.persistency.StorageManager)1 ProjectAnalyzer (org.evosuite.continuous.project.ProjectAnalyzer)1