@Override public void collectBestSolutions(Set<? extends Chromosome> solutions) throws RemoteException { logger.debug(ClientProcess.getPrettyPrintIdentifier() + "added solution to set"); bestSolutions.add(solutions); }
@Override public void sendBestSolution(Set<? extends Chromosome> solutions) { try { logger.debug(ClientProcess.getPrettyPrintIdentifier() + "sending best solutions to " + ClientProcess.DEFAULT_CLIENT_NAME); masterNode.evosuite_collectBestSolutions(clientRmiIdentifier, solutions); } catch (RemoteException e) { logger.error(ClientProcess.getPrettyPrintIdentifier() + "Cannot send best solution to master", e); } }
@Override public void emigrate(Set<? extends Chromosome> immigrants) { try { logger.debug(ClientProcess.getPrettyPrintIdentifier() + "Sending " + immigrants.size() + " immigrants"); masterNode.evosuite_migrate(clientRmiIdentifier, immigrants); } catch (RemoteException e) { logger.error(ClientProcess.getPrettyPrintIdentifier() + "Cannot send immigrating individuals to master", e); } }
@Override public void immigrate(Set<? extends Chromosome> migrants) throws RemoteException { logger.debug(ClientProcess.getPrettyPrintIdentifier() + "receiving " + (migrants != null ? migrants.size() : 0) + " immigrants"); fireEvent(migrants); }
static void printTestCriterion() { if (Properties.CRITERION.length > 1) { LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Test criteria:"); } else { LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier()+ "Test criterion:"); } for (int i = 0; i < Properties.CRITERION.length; i++) { printTestCriterion(Properties.CRITERION[i]); } }
/** * Prints out all information regarding this GAs stopping conditions * * So far only used for testing purposes in TestSuiteGenerator */ public void printBudget(GeneticAlgorithm<?> algorithm) { LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Search Budget:"); for (StoppingCondition sc : algorithm.getStoppingConditions()) LoggingUtils.getEvoLogger().info("\t- " + sc.toString()); }
private void writeObjectPool(TestSuiteChromosome suite) { if (!Properties.WRITE_POOL.isEmpty()) { LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Writing sequences to pool"); ObjectPool pool = ObjectPool.getPoolFromTestSuite(suite); pool.writePool(Properties.WRITE_POOL); } }
private static List<Class<?>> getTestClasses() { List<Class<?>> testClasses = new ArrayList<Class<?>>(); logger.debug("JUNIT: "+Properties.JUNIT); for(String prefix : Properties.JUNIT.split(":")) { LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Analyzing entry: "+prefix); // If the target name is a path analyze it File path = new File(prefix); if (path.exists()) { if (Properties.JUNIT.endsWith(".jar")) testClasses.addAll(getTestClassesJar(path)); else testClasses.addAll(getTestClasses(path)); } else { try { Class<?> clazz = Class.forName(prefix, true, TestGenerationContext.getInstance().getClassLoaderForSUT()); testClasses.add(clazz); } catch (ClassNotFoundException e) { // Second, try if the target name is a package name testClasses.addAll(getTestClassesFromClasspath()); } } } return testClasses; }
@Override public void changeState(ClientState state, ClientStateInformation information) { if (this.state != state){ logger.info(ClientProcess.getPrettyPrintIdentifier() + "Client changing state from " + this.state + " to " + state); } this.state = state; TimeController.getInstance().updateState(state); try { masterNode.evosuite_informChangeOfStateInClient(clientRmiIdentifier, state,information); } catch (RemoteException e) { logger.error("Cannot inform master of change of state", e); } if (this.state.equals(ClientState.DONE)) { doneLatch.countDown(); } if (this.state.equals(ClientState.FINISHED)) { finishedLatch.countDown(); } }
ClassPathHandler.getInstance().getTargetProjectClasspath(), prefix, false); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Found " + suts.size() + " classes with prefix '" + prefix + "'"); if (!suts.isEmpty()) {
private static List<JUnitResult> executeTests(Class<?>... testClasses) { ExecutionTracer.enable(); ExecutionTracer.setCheckCallerThread(false); ExecutionTracer.getExecutionTracer().clear(); List<JUnitResult> results = new ArrayList<JUnitResult>(); for (Class<?> testClass : testClasses) { LoggingUtils.getEvoLogger().info(" Executing " + testClass.getSimpleName()); // Set the context classloader in case the SUT requests it Thread.currentThread().setContextClassLoader(testClass.getClassLoader()); JUnitRunner jR = new JUnitRunner(testClass); jR.run(); results.addAll(jR.getTestResults()); } ExecutionTracer.disable(); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Executed " + results.size() + " unit " + "test(s)"); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Tests_Executed, results.size()); return results; }
logger.error(getPrettyPrintIdentifier() + "Error when generating tests for: " + Properties.TARGET_CLASS + " with seed " + Randomness.getSeed()+". Configuration id : "+Properties.CONFIGURATION_ID, t); t.printStackTrace();
private void initializeTargetClass() throws Throwable { String cp = ClassPathHandler.getInstance().getTargetProjectClasspath(); // Here is where the <clinit> code should be invoked for the first time DefaultTestCase test = buildLoadTargetClassTestCase(Properties.TARGET_CLASS); ExecutionResult execResult = TestCaseExecutor.getInstance().execute(test, Integer.MAX_VALUE); if (hasThrownInitializerError(execResult)) { // create single test suite with Class.forName() writeJUnitTestSuiteForFailedInitialization(); ExceptionInInitializerError ex = getInitializerError(execResult); throw ex; } else if (!execResult.getAllThrownExceptions().isEmpty()) { // some other exception has been thrown during initialization Throwable t = execResult.getAllThrownExceptions().iterator().next(); throw t; } DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator))); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Finished analyzing classpath"); }
LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Target class " + Properties.TARGET_CLASS); ClientServices.getInstance().getClientNode().updateProperty("TARGET_CLASS", Properties.TARGET_CLASS); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Total number of covered goals: " + totalCoveredGoals + " / " + "" + totalGoals); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Total_Goals, totalGoals); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Total coverage: " + NumberFormat.getPercentInstance().format(coverage)); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Coverage, coverage);
try { InheritanceTree tree = readInheritanceTree(Properties.INHERITANCE_FILE); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Inheritance tree loaded from {}", Properties.INHERITANCE_FILE); return tree; LoggingUtils.getEvoLogger().warn("* " + ClientProcess.getPrettyPrintIdentifier() + "Error loading inheritance tree: {}", e);
/** * <p> * If Properties.JUNIT_TESTS is set, this method writes the given test cases * to the default directory Properties.TEST_DIR. * * <p> * The name of the test will be equal to the SUT followed by the given * suffix * * @param testSuite * a test suite. */ public static TestGenerationResult writeJUnitTestsAndCreateResult(TestSuiteChromosome testSuite, String suffix) { List<TestCase> tests = testSuite.getTests(); if (Properties.JUNIT_TESTS) { ClientServices.getInstance().getClientNode().changeState(ClientState.WRITING_TESTS); TestSuiteWriter suiteWriter = new TestSuiteWriter(); suiteWriter.insertTests(tests); String name = Properties.TARGET_CLASS.substring(Properties.TARGET_CLASS.lastIndexOf(".") + 1); String testDir = Properties.TEST_DIR; LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Writing JUnit test case '" + (name + suffix) + "' to " + testDir); suiteWriter.writeTestSuite(name + suffix, testDir, testSuite.getLastExecutionResults()); } return TestGenerationResultBuilder.buildSuccessResult(); }
public void writeJUnitFailingTests() { if (!Properties.CHECK_CONTRACTS) return; FailingTestSet.sendStatistics(); if (Properties.JUNIT_TESTS) { TestSuiteWriter suiteWriter = new TestSuiteWriter(); //suiteWriter.insertTests(FailingTestSet.getFailingTests()); TestSuiteChromosome suite = new TestSuiteChromosome(); for(TestCase test : FailingTestSet.getFailingTests()) { test.setFailing(); suite.addTest(test); } String name = Properties.TARGET_CLASS.substring(Properties.TARGET_CLASS.lastIndexOf(".") + 1); String testDir = Properties.TEST_DIR; LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Writing failing test cases '" + (name + Properties.JUNIT_SUFFIX) + "' to " + testDir); suiteWriter.insertAllTests(suite.getTests()); FailingTestSet.writeJUnitTestSuite(suiteWriter); suiteWriter.writeTestSuite(name + Properties.JUNIT_FAILED_SUFFIX, testDir, suite.getLastExecutionResults()); } }
LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Total number of test goals for {}: {}", Properties.ALGORITHM.name(), fitnessFunctions.size()); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Using seed {}", Randomness.getSeed()); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Starting evolution"); ClientServices.getInstance().getClientNode().changeState(ClientState.SEARCH); LoggingUtils.getEvoLogger().warn(ClientProcess.getPrettyPrintIdentifier() + "Could not generate any test case"); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Search finished after " + (endTime - startTime) + "s and "
logger.debug(ClientProcess.getPrettyPrintIdentifier() + "Sending " + solutionsSet.size() + " solutions to " + ClientProcess.DEFAULT_CLIENT_NAME); ClientServices.getInstance().getClientNode().sendBestSolution(solutionsSet);
LoggingUtils.getEvoLogger().info("* " + getPrettyPrintIdentifier() + "Connecting to master process on port " + Properties.PROCESS_COMMUNICATION_PORT); result = TestGenerationResultBuilder.buildErrorResult("Could not connect to master process on port " + Properties.PROCESS_COMMUNICATION_PORT); throw new RuntimeException(getPrettyPrintIdentifier() + "Could not connect to master process on port " + Properties.PROCESS_COMMUNICATION_PORT);