Search in sources :

Example 1 with CtgConfiguration

use of org.evosuite.continuous.CtgConfiguration 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);
    }
}
Also used : MoreBranches(com.examples.with.different.packagename.continuous.MoreBranches) CtgConfiguration(org.evosuite.continuous.CtgConfiguration) ProjectStaticData(org.evosuite.continuous.project.ProjectStaticData) NoBranches(com.examples.with.different.packagename.continuous.NoBranches) UsingSimpleAndTrivial(com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial) Trivial(com.examples.with.different.packagename.continuous.Trivial) ProjectAnalyzer(org.evosuite.continuous.project.ProjectAnalyzer) Test(org.junit.Test)

Example 2 with CtgConfiguration

use of org.evosuite.continuous.CtgConfiguration in project evosuite by EvoSuite.

the class JobExecutorIntTest method testActualExecutionOfSchedule.

@Test(timeout = 90_000)
public void testActualExecutionOfSchedule() throws IOException {
    Properties.TEST_SCAFFOLDING = true;
    boolean storageOK = storage.isStorageOk();
    assertTrue(storageOK);
    storageOK = storage.createNewTmpFolders();
    assertTrue(storageOK);
    List<TestsOnDisk> data = storage.gatherGeneratedTestsOnDisk();
    Assert.assertEquals(0, data.size());
    ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
    String classpath = ClassPathHandler.getInstance().getTargetProjectClasspath();
    int cores = 1;
    int memory = 1000;
    int minutes = 1;
    CtgConfiguration conf = new CtgConfiguration(memory, cores, minutes, 1, false, AvailableSchedule.SIMPLE);
    JobExecutor exe = new JobExecutor(storage, classpath, conf);
    JobDefinition simple = new JobDefinition(30, memory, com.examples.with.different.packagename.continuous.Simple.class.getName(), 0, null, null);
    JobDefinition trivial = new JobDefinition(30, memory, com.examples.with.different.packagename.continuous.Trivial.class.getName(), 0, null, null);
    assertTrue(simple.jobID < trivial.jobID);
    List<JobDefinition> jobs = Arrays.asList(simple, trivial);
    exe.executeJobs(jobs, cores);
    exe.waitForJobs();
    data = storage.gatherGeneratedTestsOnDisk();
    // if Properties.TEST_SCAFFOLDING is enabled, we should have
    // 4 java files (2 test cases and 2 scaffolding files), however
    // 'storage' just returns the 2 test cases
    boolean areThereFiles = (data.size() == 2);
    boolean areThereTests = true;
    // check if indeed they have tests
    for (TestsOnDisk tod : data) {
        String content = FileUtils.readFileToString(tod.testSuite);
        areThereTests = areThereTests && content.contains("@Test") && !content.contains(TestSuiteWriter.NOT_GENERATED_TEST_NAME);
    }
    String msg = "Tmp folder: " + Properties.CTG_DIR + "\n";
    if (!areThereFiles || !areThereTests) {
        // build a better error message by looking at the log files
        File logDir = storage.getTmpLogs();
        msg += "Log folder: " + logDir.getAbsolutePath() + "\n";
        List<File> files = FileIOUtils.getRecursivelyAllFilesInAllSubfolders(logDir, ".log");
        msg += "# log files: " + files.size() + "\n";
        for (File log : files) {
            String content = null;
            try {
                content = FileUtils.readFileToString(log);
            } catch (IOException e) {
                msg += "Failed to read file " + log.getName() + " due to: " + e.toString() + "\n";
            }
            if (content != null) {
                msg += "Content for file: " + log.getName() + "\n";
                msg += "--------------------------------------------------" + "\n";
                msg += content;
                msg += "\n" + "--------------------------------------------------" + "\n";
            }
        }
    }
    Assert.assertEquals(msg, 2, data.size());
    Assert.assertTrue(msg, areThereTests);
    boolean deleted = storage.clean();
    Assert.assertTrue(deleted);
}
Also used : CtgConfiguration(org.evosuite.continuous.CtgConfiguration) TestsOnDisk(org.evosuite.continuous.persistency.StorageManager.TestsOnDisk) IOException(java.io.IOException) Simple(com.examples.with.different.packagename.continuous.Simple) UsingSimpleAndTrivial(com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial) Trivial(com.examples.with.different.packagename.continuous.Trivial) File(java.io.File) Test(org.junit.Test)

Example 3 with CtgConfiguration

use of org.evosuite.continuous.CtgConfiguration in project evosuite by EvoSuite.

the class JobExecutorIntTest method testEventSequenceWhenWrongSchedule.

@Test
public void testEventSequenceWhenWrongSchedule() throws InterruptedException {
    boolean storageOK = storage.isStorageOk();
    assertTrue(storageOK);
    storageOK = storage.createNewTmpFolders();
    assertTrue(storageOK);
    List<TestsOnDisk> data = storage.gatherGeneratedTestsOnDisk();
    Assert.assertEquals(0, data.size());
    // no need to specify it, as com.examples are compiled with EvoSuite
    String classpath = System.getProperty("java.class.path");
    int cores = 1;
    int memory = 1000;
    int minutes = 10000;
    CtgConfiguration conf = new CtgConfiguration(memory, cores, minutes, 1, false, AvailableSchedule.SIMPLE);
    final JobExecutor exe = new JobExecutor(storage, classpath, conf);
    JobDefinition simple = new JobDefinition(30, memory, Simple.class.getName(), 0, null, null);
    JobDefinition trivial = new JobDefinition(30, memory, Trivial.class.getName(), 0, null, null);
    JobDefinition ust = new JobDefinition(30, memory, UsingSimpleAndTrivial.class.getName(), 0, new HashSet<>(Arrays.asList(new String[] { Simple.class.getName(), Trivial.class.getName() })), null);
    /*
		 * ust is in the middle, instead of last element.
		 * still, even if the schedule is wrong, the executor should be able
		 * to properly handle it 
		 */
    final List<JobDefinition> jobs = Arrays.asList(simple, ust, trivial);
    exe.initExecution(jobs);
    Thread t = new Thread() {

        @Override
        public void run() {
            exe.execute(jobs);
        }
    };
    try {
        t.start();
        exe.doneWithJob(exe.pollJob());
        exe.doneWithJob(exe.pollJob());
        JobDefinition last = exe.pollJob();
        exe.doneWithJob(last);
        Assert.assertEquals(ust.cut, last.cut);
    } finally {
        t.interrupt();
    }
    storage.clean();
}
Also used : CtgConfiguration(org.evosuite.continuous.CtgConfiguration) TestsOnDisk(org.evosuite.continuous.persistency.StorageManager.TestsOnDisk) Simple(com.examples.with.different.packagename.continuous.Simple) UsingSimpleAndTrivial(com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial) Trivial(com.examples.with.different.packagename.continuous.Trivial) UsingSimpleAndTrivial(com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial) Test(org.junit.Test)

Example 4 with CtgConfiguration

use of org.evosuite.continuous.CtgConfiguration 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);
}
Also used : CtgConfiguration(org.evosuite.continuous.CtgConfiguration) UsingSimpleAndTrivial(com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial) ProjectAnalyzer(org.evosuite.continuous.project.ProjectAnalyzer) ProjectStaticData(org.evosuite.continuous.project.ProjectStaticData) Simple(com.examples.with.different.packagename.continuous.Simple) Test(org.junit.Test)

Example 5 with CtgConfiguration

use of org.evosuite.continuous.CtgConfiguration 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());
}
Also used : BaseForSeeding(com.examples.with.different.packagename.continuous.BaseForSeeding) CtgConfiguration(org.evosuite.continuous.CtgConfiguration) ProjectAnalyzer(org.evosuite.continuous.project.ProjectAnalyzer) ProjectStaticData(org.evosuite.continuous.project.ProjectStaticData) Test(org.junit.Test)

Aggregations

CtgConfiguration (org.evosuite.continuous.CtgConfiguration)8 Test (org.junit.Test)8 ProjectAnalyzer (org.evosuite.continuous.project.ProjectAnalyzer)6 ProjectStaticData (org.evosuite.continuous.project.ProjectStaticData)6 UsingSimpleAndTrivial (com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial)5 Simple (com.examples.with.different.packagename.continuous.Simple)3 Trivial (com.examples.with.different.packagename.continuous.Trivial)3 MoreBranches (com.examples.with.different.packagename.continuous.MoreBranches)2 NoBranches (com.examples.with.different.packagename.continuous.NoBranches)2 TestsOnDisk (org.evosuite.continuous.persistency.StorageManager.TestsOnDisk)2 BaseForSeeding (com.examples.with.different.packagename.continuous.BaseForSeeding)1 SomeBranches (com.examples.with.different.packagename.continuous.SomeBranches)1 File (java.io.File)1 IOException (java.io.IOException)1