Search in sources :

Example 6 with JobDefinition

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

the class SeedingScheduleTest method testSortingPostponedDependencies.

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

Example 7 with JobDefinition

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

the class SeedingScheduleTest method testSortingTwoDependencies.

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

Example 8 with JobDefinition

use of org.evosuite.continuous.job.JobDefinition 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;
}
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 9 with JobDefinition

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

the class SeedingSchedule method addDependenciesForSeeding.

/**
 * For each input job, identify all the others jobs we want to generate
 * test cases first.
 * The scheduler will use this information to first try to generate
 * the test cases for the "dependency" jobs.
 *
 * <p>
 * There can be different strategies to define a dependency:
 * - ancestor, non-interface classes
 * - classes used as input objects
 * - subtypes of classes used as input objects
 *
 * @param jobs
 * @return a copy given input list, but with new jobs objects
 */
protected List<JobDefinition> addDependenciesForSeeding(List<JobDefinition> jobs) {
    List<JobDefinition> list = new ArrayList<JobDefinition>(jobs.size());
    for (int i = 0; i < jobs.size(); i++) {
        JobDefinition job = jobs.get(i);
        Set<String> inputs = calculateInputClasses(job);
        Set<String> parents = calculateAncestors(job);
        list.add(job.getByAddingDependencies(inputs, parents));
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) JobDefinition(org.evosuite.continuous.job.JobDefinition)

Example 10 with JobDefinition

use of org.evosuite.continuous.job.JobDefinition 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;
}
Also used : JobScheduler(org.evosuite.continuous.job.JobScheduler) JobExecutor(org.evosuite.continuous.job.JobExecutor) StorageManager(org.evosuite.continuous.persistency.StorageManager) IOException(java.io.IOException) ProjectAnalyzer(org.evosuite.continuous.project.ProjectAnalyzer) ProjectStaticData(org.evosuite.continuous.project.ProjectStaticData) JobDefinition(org.evosuite.continuous.job.JobDefinition)

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