use of com.examples.with.different.packagename.continuous.Simple 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);
}
use of com.examples.with.different.packagename.continuous.Simple 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();
}
use of com.examples.with.different.packagename.continuous.Simple 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 com.examples.with.different.packagename.continuous.Simple in project evosuite by EvoSuite.
the class ProjectAnalyzerIntTest method testBranches.
@Test
public void testBranches() {
String[] cuts = new String[] { Simple.class.getName(), Trivial.class.getName() };
ProjectAnalyzer pa = new ProjectAnalyzer(cuts);
ProjectStaticData data = pa.analyze();
Assert.assertEquals(2, data.getTotalNumberOfClasses());
ClassInfo simple = data.getClassInfo(Simple.class.getName());
Assert.assertNotNull(simple);
Assert.assertEquals(2, simple.numberOfBranches);
ClassInfo trivial = data.getClassInfo(Trivial.class.getName());
Assert.assertNotNull(trivial);
Assert.assertEquals(1, trivial.numberOfBranches);
}
Aggregations