Search in sources :

Example 1 with LoggingUtils

use of org.evosuite.utils.LoggingUtils in project evosuite by EvoSuite.

the class MeasureCoverage method measureCoverage.

private static void measureCoverage(String targetClass, List<String> args) {
    String classPath = ClassPathHandler.getInstance().getEvoSuiteClassPath();
    String projectCP = ClassPathHandler.getInstance().getTargetProjectClasspath();
    classPath += !classPath.isEmpty() ? File.pathSeparator + projectCP : projectCP;
    ExternalProcessHandler handler = new ExternalProcessHandler();
    int port = handler.openServer();
    List<String> cmdLine = new ArrayList<String>();
    cmdLine.add(JavaExecCmdUtil.getJavaBinExecutablePath(true));
    cmdLine.add("-cp");
    cmdLine.add(classPath);
    cmdLine.add("-Dprocess_communication_port=" + port);
    if (Properties.HEADLESS_MODE) {
        cmdLine.add("-Djava.awt.headless=true");
    }
    cmdLine.add("-Dlogback.configurationFile=" + LoggingUtils.getLogbackFileName());
    cmdLine.add("-Djava.library.path=lib");
    cmdLine.add(projectCP.isEmpty() ? "-DCP=" + classPath : "-DCP=" + projectCP);
    for (String arg : args) {
        if (!arg.startsWith("-DCP=")) {
            cmdLine.add(arg);
        }
    }
    cmdLine.add("-DTARGET_CLASS=" + targetClass);
    cmdLine.add("-Djunit=" + Properties.JUNIT);
    if (Properties.PROJECT_PREFIX != null) {
        cmdLine.add("-DPROJECT_PREFIX=" + Properties.PROJECT_PREFIX);
    }
    cmdLine.add("-Dclassloader=true");
    cmdLine.add(ClientProcess.class.getName());
    /*
		 * TODO: here we start the client with several properties that are set through -D. These properties are not visible to the master process (ie
		 * this process), when we access the Properties file. At the moment, we only need few parameters, so we can hack them
		 */
    // should force the load, just to be sure
    Properties.getInstance();
    Properties.TARGET_CLASS = targetClass;
    Properties.PROCESS_COMMUNICATION_PORT = port;
    LoggingUtils logUtils = new LoggingUtils();
    if (!Properties.CLIENT_ON_THREAD) {
        /*
			 * We want to completely mute the SUT. So, we block all outputs from client, and use a remote logging
			 */
        boolean logServerStarted = logUtils.startLogServer();
        if (!logServerStarted) {
            logger.error("Cannot start the log server");
            return;
        }
        // 
        int logPort = logUtils.getLogServerPort();
        cmdLine.add(1, "-Dmaster_log_port=" + logPort);
        cmdLine.add(1, "-Devosuite.log.appender=CLIENT");
    }
    String[] newArgs = cmdLine.toArray(new String[cmdLine.size()]);
    for (String entry : ClassPathHandler.getInstance().getClassPathElementsForTargetProject()) {
        try {
            ClassPathHacker.addFile(entry);
        } catch (IOException e) {
            LoggingUtils.getEvoLogger().info("* Error while adding classpath entry: " + entry);
        }
    }
    handler.setBaseDir(EvoSuite.base_dir_path);
    if (handler.startProcess(newArgs)) {
        Set<ClientNodeRemote> clients = null;
        try {
            clients = MasterServices.getInstance().getMasterNode().getClientsOnceAllConnected(10000);
        } catch (InterruptedException e) {
        }
        if (clients == null) {
            logger.error("Not possible to access to clients");
        } else {
            /*
				 * The clients have started, and connected back to Master.
				 * So now we just need to tell them to start a search
				 */
            for (ClientNodeRemote client : clients) {
                try {
                    client.doCoverageAnalysis();
                } catch (RemoteException e) {
                    logger.error("Error in starting clients", e);
                }
            }
            int time = TimeController.getInstance().calculateForHowLongClientWillRunInSeconds();
            handler.waitForResult(time * 1000);
        }
        // 100 seconds?
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        if (Properties.NEW_STATISTICS) {
            if (MasterServices.getInstance().getMasterNode() == null) {
                logger.error("Cannot write results as RMI master node is not running");
            } else {
                LoggingUtils.getEvoLogger().info("* Writing statistics");
                SearchStatistics.getInstance().writeStatisticsForAnalysis();
            }
        }
        handler.killProcess();
    } else {
        LoggingUtils.getEvoLogger().info("* Could not connect to client process");
    }
    handler.closeServer();
    if (!Properties.CLIENT_ON_THREAD) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        logUtils.closeLogServer();
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClientNodeRemote(org.evosuite.rmi.service.ClientNodeRemote) LoggingUtils(org.evosuite.utils.LoggingUtils) RemoteException(java.rmi.RemoteException) ExternalProcessHandler(org.evosuite.utils.ExternalProcessHandler)

Example 2 with LoggingUtils

use of org.evosuite.utils.LoggingUtils in project evosuite by EvoSuite.

the class PrintStats method printStats.

private static void printStats(String targetClass, List<String> args) {
    if (!BytecodeInstrumentation.checkIfCanInstrument(targetClass)) {
        throw new IllegalArgumentException("Cannot consider " + targetClass + " because it belongs to one of the packages EvoSuite cannot currently handle");
    }
    String classPath = ClassPathHandler.getInstance().getEvoSuiteClassPath();
    String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
    classPath += File.pathSeparator + cp;
    ExternalProcessHandler handler = new ExternalProcessHandler();
    int port = handler.openServer();
    List<String> cmdLine = new ArrayList<String>();
    cmdLine.add(JavaExecCmdUtil.getJavaBinExecutablePath(true));
    cmdLine.add("-cp");
    cmdLine.add(classPath);
    cmdLine.add("-Dprocess_communication_port=" + port);
    cmdLine.add("-Djava.awt.headless=true");
    cmdLine.add("-Dlogback.configurationFile=" + LoggingUtils.getLogbackFileName());
    cmdLine.add("-Djava.library.path=lib");
    cmdLine.add("-DCP=" + cp);
    for (String arg : args) {
        if (!arg.startsWith("-DCP=")) {
            cmdLine.add(arg);
        }
    }
    cmdLine.add("-DTARGET_CLASS=" + targetClass);
    if (Properties.PROJECT_PREFIX != null) {
        cmdLine.add("-DPROJECT_PREFIX=" + Properties.PROJECT_PREFIX);
    }
    cmdLine.add("-Dclassloader=true");
    cmdLine.add(ClientProcess.class.getName());
    /*
		 * TODO: here we start the client with several properties that are set through -D. These properties are not visible to the master process (ie
		 * this process), when we access the Properties file. At the moment, we only need few parameters, so we can hack them
		 */
    // should force the load, just to be sure
    Properties.getInstance();
    Properties.TARGET_CLASS = targetClass;
    Properties.PROCESS_COMMUNICATION_PORT = port;
    LoggingUtils logUtils = new LoggingUtils();
    if (!Properties.CLIENT_ON_THREAD) {
        /*
			 * We want to completely mute the SUT. So, we block all outputs from client, and use a remote logging
			 */
        boolean logServerStarted = logUtils.startLogServer();
        if (!logServerStarted) {
            logger.error("Cannot start the log server");
            return;
        }
        // 
        int logPort = logUtils.getLogServerPort();
        cmdLine.add(1, "-Dmaster_log_port=" + logPort);
        cmdLine.add(1, "-Devosuite.log.appender=CLIENT");
    }
    String[] newArgs = cmdLine.toArray(new String[cmdLine.size()]);
    for (String entry : ClassPathHandler.getInstance().getClassPathElementsForTargetProject()) {
        try {
            ClassPathHacker.addFile(entry);
        } catch (IOException e) {
            LoggingUtils.getEvoLogger().info("* Error while adding classpath entry: " + entry);
        }
    }
    handler.setBaseDir(EvoSuite.base_dir_path);
    if (handler.startProcess(newArgs)) {
        Set<ClientNodeRemote> clients = null;
        try {
            clients = MasterServices.getInstance().getMasterNode().getClientsOnceAllConnected(10000);
        } catch (InterruptedException e) {
        }
        if (clients == null) {
            logger.error("Not possible to access to clients");
        } else {
            /*
				 * The clients have started, and connected back to Master.
				 * So now we just need to tell them to start a search
				 */
            for (ClientNodeRemote client : clients) {
                try {
                    client.printClassStatistics();
                } catch (RemoteException e) {
                    logger.error("Error in starting clients", e);
                }
            }
            handler.waitForResult((Properties.GLOBAL_TIMEOUT + Properties.MINIMIZATION_TIMEOUT + Properties.EXTRA_TIMEOUT) * // FIXXME: search
            1000);
        }
        // 100 seconds?
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        handler.killProcess();
    } else {
        LoggingUtils.getEvoLogger().info("* Could not connect to client process");
    }
    handler.closeServer();
    if (!Properties.CLIENT_ON_THREAD) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        logUtils.closeLogServer();
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClientNodeRemote(org.evosuite.rmi.service.ClientNodeRemote) LoggingUtils(org.evosuite.utils.LoggingUtils) RemoteException(java.rmi.RemoteException) ClientProcess(org.evosuite.ClientProcess) ExternalProcessHandler(org.evosuite.utils.ExternalProcessHandler)

Example 3 with LoggingUtils

use of org.evosuite.utils.LoggingUtils in project evosuite by EvoSuite.

the class TestGeneration method generateTests.

private static List<List<TestGenerationResult>> generateTests(Properties.Strategy strategy, String target, List<String> args) {
    LoggingUtils.getEvoLogger().info("* Going to generate test cases for class: " + target);
    if (!findTargetClass(target)) {
        return Arrays.asList(Arrays.asList(new TestGenerationResult[] { TestGenerationResultBuilder.buildErrorResult("Could not find target class") }));
    }
    if (!BytecodeInstrumentation.checkIfCanInstrument(target)) {
        throw new IllegalArgumentException("Cannot consider " + target + " because it belongs to one of the packages EvoSuite cannot currently handle");
    }
    List<String> cmdLine = new ArrayList<>();
    cmdLine.add(JavaExecCmdUtil.getJavaBinExecutablePath(true));
    handleClassPath(cmdLine);
    if (Properties.SPAWN_PROCESS_MANAGER_PORT != null) {
        cmdLine.add("-Dspawn_process_manager_port=" + Properties.SPAWN_PROCESS_MANAGER_PORT);
    }
    ExternalProcessHandler handler = new ExternalProcessHandler();
    int port = handler.openServer();
    if (port <= 0) {
        throw new RuntimeException("Not possible to start RMI service");
    }
    cmdLine.add("-Dprocess_communication_port=" + port);
    cmdLine.add("-Dinline=true");
    if (Properties.HEADLESS_MODE == true) {
        cmdLine.add("-Djava.awt.headless=true");
    }
    cmdLine.add("-Dlogback.configurationFile=" + LoggingUtils.getLogbackFileName());
    cmdLine.add("-Dlog4j.configuration=SUT.log4j.properties");
    /*
		 * FIXME: following 3 should be refactored, as not particularly clean.
		 * First 2 does not work for master, as logback is read
		 * before Properties is initialized
		 */
    if (Properties.LOG_LEVEL != null) {
        cmdLine.add("-Dlog.level=" + Properties.LOG_LEVEL);
    }
    if (Properties.LOG_TARGET != null) {
        cmdLine.add("-Dlog.target=" + Properties.LOG_TARGET);
    }
    String logDir = System.getProperty("evosuite.log.folder");
    if (logDir != null) {
        // this parameter is for example used in logback-ctg.xml
        cmdLine.add(" -Devosuite.log.folder=" + logDir);
    }
    // ------------------------------------------------
    cmdLine.add("-Djava.library.path=lib");
    if (Properties.DEBUG) {
        // enabling debugging mode to e.g. connect the eclipse remote debugger to the given port
        cmdLine.add("-Ddebug=true");
        cmdLine.add("-Xdebug");
        cmdLine.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + Properties.PORT);
        LoggingUtils.getEvoLogger().info("* Waiting for remote debugger to connect on port " + Properties.PORT + // TODO find the right
        "...");
    // place for this
    }
    if (!Properties.PROFILE.isEmpty()) {
        // enabling debugging mode to e.g. connect the eclipse remote debugger to the given port
        File agentFile = new File(Properties.PROFILE);
        if (!agentFile.exists()) {
            LoggingUtils.getEvoLogger().info("* Error: " + Properties.PROFILE + " not found");
        } else {
            cmdLine.add("-agentpath:" + Properties.PROFILE);
            LoggingUtils.getEvoLogger().info("* Using profiling agent " + Properties.PROFILE);
        }
    }
    if (Properties.JMC) {
        // FIXME: does not seem to work, at least on Mac. Looks like some RMI conflict
        cmdLine.add("-XX:+UnlockCommercialFeatures");
        cmdLine.add("-XX:+FlightRecorder");
        cmdLine.add("-Dcom.sun.management.jmxremote");
        cmdLine.add("-Dcom.sun.management.jmxremote.autodiscovery");
        cmdLine.add("-Dcom.sun.management.jmxremote.authenticate=false");
        cmdLine.add("-Dcom.sun.management.jmxremote.ssl=false");
    }
    cmdLine.add("-XX:MaxJavaStackTraceDepth=1000000");
    cmdLine.add("-XX:+StartAttachListener");
    for (String arg : args) {
        if (!arg.startsWith("-DCP=")) {
            cmdLine.add(arg);
        }
    }
    switch(strategy) {
        case EVOSUITE:
            cmdLine.add("-Dstrategy=EvoSuite");
            break;
        case ONEBRANCH:
            cmdLine.add("-Dstrategy=OneBranch");
            break;
        case RANDOM:
            cmdLine.add("-Dstrategy=Random");
            break;
        case RANDOM_FIXED:
            cmdLine.add("-Dstrategy=Random_Fixed");
            break;
        case REGRESSION:
            cmdLine.add("-Dstrategy=Regression");
            break;
        case ENTBUG:
            cmdLine.add("-Dstrategy=EntBug");
            break;
        case MOSUITE:
            cmdLine.add("-Dstrategy=MOSuite");
            break;
        case DSE:
            cmdLine.add("-Dstrategy=Dynamic_Symbolic_Execution");
            break;
        case NOVELTY:
            cmdLine.add("-Dstrategy=Novelty");
            break;
        default:
            throw new RuntimeException("Unsupported strategy: " + strategy);
    }
    cmdLine.add("-DTARGET_CLASS=" + target);
    if (Properties.PROJECT_PREFIX != null) {
        cmdLine.add("-DPROJECT_PREFIX=" + Properties.PROJECT_PREFIX);
    }
    cmdLine.add(ClientProcess.class.getName());
    /*
		 * TODO: here we start the client with several properties that are set through -D. These properties are not visible to the master process (ie
		 * this process), when we access the Properties file. At the moment, we only need few parameters, so we can hack them
		 */
    // should force the load, just to be sure
    Properties.getInstance();
    Properties.TARGET_CLASS = target;
    Properties.PROCESS_COMMUNICATION_PORT = port;
    /*
		 *  FIXME: refactor, and double-check if indeed correct
		 * 
		 * The use of "assertions" in the client is pretty tricky, as those properties need to be transformed into JVM options before starting the
		 * client. Furthermore, the properties in the property file might be overwritten from the commands coming from shell
		 */
    String definedEAforClient = null;
    String definedEAforSUT = null;
    final String DISABLE_ASSERTIONS_EVO = "-da:" + PackageInfo.getEvoSuitePackage() + "...";
    final String ENABLE_ASSERTIONS_EVO = "-ea:" + PackageInfo.getEvoSuitePackage() + "...";
    final String DISABLE_ASSERTIONS_SUT = "-da:" + Properties.PROJECT_PREFIX + "...";
    final String ENABLE_ASSERTIONS_SUT = "-ea:" + Properties.PROJECT_PREFIX + "...";
    for (String s : cmdLine) {
        // first check client
        if (s.startsWith("-Denable_asserts_for_evosuite")) {
            if (s.endsWith("false")) {
                definedEAforClient = DISABLE_ASSERTIONS_EVO;
            } else if (s.endsWith("true")) {
                definedEAforClient = ENABLE_ASSERTIONS_EVO;
            }
        }
        // then check SUT
        if (s.startsWith("-Denable_asserts_for_sut")) {
            if (s.endsWith("false")) {
                definedEAforSUT = DISABLE_ASSERTIONS_SUT;
            } else if (s.endsWith("true")) {
                definedEAforSUT = ENABLE_ASSERTIONS_SUT;
            }
        }
    }
    if (definedEAforSUT == null) {
        if (Properties.ENABLE_ASSERTS_FOR_SUT) {
            definedEAforSUT = ENABLE_ASSERTIONS_SUT;
        } else {
            definedEAforSUT = DISABLE_ASSERTIONS_SUT;
        }
    }
    if (definedEAforClient == null) {
        if (Properties.ENABLE_ASSERTS_FOR_EVOSUITE) {
            definedEAforClient = ENABLE_ASSERTIONS_EVO;
        } else {
            definedEAforClient = DISABLE_ASSERTIONS_EVO;
        }
    }
    /*
		 * We add them in first position, after the java command To avoid confusion, we only add them if they are enabled. NOTE: this might have side
		 * effects "if" in the future we have something like a generic "-ea"
		 */
    if (definedEAforClient.equals(ENABLE_ASSERTIONS_EVO)) {
        cmdLine.add(1, definedEAforClient);
    }
    if (definedEAforSUT.equals(ENABLE_ASSERTIONS_SUT)) {
        cmdLine.add(1, definedEAforSUT);
    }
    LoggingUtils logUtils = new LoggingUtils();
    if (!Properties.CLIENT_ON_THREAD) {
        /*
			 * We want to completely mute the SUT. So, we block all outputs from client, and use a remote logging
			 */
        boolean logServerStarted = logUtils.startLogServer();
        if (!logServerStarted) {
            logger.error("Cannot start the log server");
            return null;
        }
        // 
        int logPort = logUtils.getLogServerPort();
        cmdLine.add(1, "-Dmaster_log_port=" + logPort);
        cmdLine.add(1, "-Devosuite.log.appender=CLIENT");
    }
    String[] newArgs = cmdLine.toArray(new String[cmdLine.size()]);
    for (String entry : ClassPathHandler.getInstance().getTargetProjectClasspath().split(File.pathSeparator)) {
        try {
            ClassPathHacker.addFile(entry);
        } catch (IOException e) {
            LoggingUtils.getEvoLogger().info("* Error while adding classpath entry: " + entry);
        }
    }
    handler.setBaseDir(EvoSuite.base_dir_path);
    if (handler.startProcess(newArgs)) {
        Set<ClientNodeRemote> clients = null;
        try {
            // FIXME: timeout here should be handled by TimeController
            clients = MasterServices.getInstance().getMasterNode().getClientsOnceAllConnected(60000);
        } catch (InterruptedException e) {
        }
        if (clients == null) {
            logger.error("Not possible to access to clients. Clients' state: " + handler.getProcessState() + ". Master registry port: " + MasterServices.getInstance().getRegistryPort());
        } else {
            /*
				 * The clients have started, and connected back to Master.
				 * So now we just need to tell them to start a search
				 */
            for (ClientNodeRemote client : clients) {
                try {
                    client.startNewSearch();
                } catch (RemoteException e) {
                    logger.error("Error in starting clients", e);
                }
            }
            int time = TimeController.getInstance().calculateForHowLongClientWillRunInSeconds();
            handler.waitForResult(time * 1000);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
        }
        if (Properties.CLIENT_ON_THREAD) {
            handler.stopAndWaitForClientOnThread(10000);
        }
        handler.killProcess();
    } else {
        LoggingUtils.getEvoLogger().info("* Could not connect to client process");
    }
    boolean hasFailed = false;
    if (Properties.NEW_STATISTICS) {
        if (MasterServices.getInstance().getMasterNode() == null) {
            logger.error("Cannot write results as RMI master node is not running");
            hasFailed = true;
        } else {
            boolean written = SearchStatistics.getInstance().writeStatistics();
            hasFailed = !written;
        }
    }
    /*
		 * FIXME: it is unclear what is the relation between TestGenerationResult and writeStatistics()
		 */
    List<List<TestGenerationResult>> results = SearchStatistics.getInstance().getTestGenerationResults();
    SearchStatistics.clearInstance();
    handler.closeServer();
    if (Properties.CLIENT_ON_THREAD) {
        handler.stopAndWaitForClientOnThread(10000);
    } else {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        logUtils.closeLogServer();
    }
    logger.debug("Master process has finished to wait for client");
    // FIXME: tmp hack till understood what TestGenerationResult is...
    if (hasFailed) {
        logger.error("failed to write statistics data");
        // note: cannot throw exception because would require refactoring of many SystemTests
        return new ArrayList<List<TestGenerationResult>>();
    }
    return results;
}
Also used : IOException(java.io.IOException) TestGenerationResult(org.evosuite.result.TestGenerationResult) ClientNodeRemote(org.evosuite.rmi.service.ClientNodeRemote) LoggingUtils(org.evosuite.utils.LoggingUtils) ResourceList(org.evosuite.classpath.ResourceList) RemoteException(java.rmi.RemoteException) File(java.io.File) ExternalProcessHandler(org.evosuite.utils.ExternalProcessHandler)

Example 4 with LoggingUtils

use of org.evosuite.utils.LoggingUtils in project evosuite by EvoSuite.

the class WriteDependencies method writeDependencies.

private static void writeDependencies(String targetFile, String targetClass, List<String> args) {
    if (!BytecodeInstrumentation.checkIfCanInstrument(targetClass)) {
        throw new IllegalArgumentException("Cannot consider " + targetClass + " because it belongs to one of the packages EvoSuite cannot currently handle");
    }
    String classPath = ClassPathHandler.getInstance().getEvoSuiteClassPath();
    String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
    classPath += File.pathSeparator + cp;
    ExternalProcessHandler handler = new ExternalProcessHandler();
    int port = handler.openServer();
    List<String> cmdLine = new ArrayList<String>();
    cmdLine.add(JavaExecCmdUtil.getJavaBinExecutablePath(true));
    cmdLine.add("-cp");
    cmdLine.add(classPath);
    cmdLine.add("-Dprocess_communication_port=" + port);
    cmdLine.add("-Djava.awt.headless=true");
    cmdLine.add("-Dlogback.configurationFile=" + LoggingUtils.getLogbackFileName());
    cmdLine.add("-Djava.library.path=lib");
    cmdLine.add("-DCP=" + cp);
    for (String arg : args) {
        if (!arg.startsWith("-DCP=")) {
            cmdLine.add(arg);
        }
    }
    cmdLine.add("-DTARGET_CLASS=" + targetClass);
    if (Properties.PROJECT_PREFIX != null) {
        cmdLine.add("-DPROJECT_PREFIX=" + Properties.PROJECT_PREFIX);
    }
    cmdLine.add("-Dclassloader=true");
    cmdLine.add(ClientProcess.class.getName());
    /*
		 * TODO: here we start the client with several properties that are set through -D. These properties are not visible to the master process (ie
		 * this process), when we access the Properties file. At the moment, we only need few parameters, so we can hack them
		 */
    // should force the load, just to be sure
    Properties.getInstance();
    Properties.TARGET_CLASS = targetClass;
    Properties.PROCESS_COMMUNICATION_PORT = port;
    LoggingUtils logUtils = new LoggingUtils();
    if (!Properties.CLIENT_ON_THREAD) {
        /*
			 * We want to completely mute the SUT. So, we block all outputs from client, and use a remote logging
			 */
        boolean logServerStarted = logUtils.startLogServer();
        if (!logServerStarted) {
            logger.error("Cannot start the log server");
            return;
        }
        // 
        int logPort = logUtils.getLogServerPort();
        cmdLine.add(1, "-Dmaster_log_port=" + logPort);
        cmdLine.add(1, "-Devosuite.log.appender=CLIENT");
    }
    String[] newArgs = cmdLine.toArray(new String[cmdLine.size()]);
    for (String entry : ClassPathHandler.getInstance().getClassPathElementsForTargetProject()) {
        try {
            ClassPathHacker.addFile(entry);
        } catch (IOException e) {
            LoggingUtils.getEvoLogger().info("* Error while adding classpath entry: " + entry);
        }
    }
    handler.setBaseDir(EvoSuite.base_dir_path);
    if (handler.startProcess(newArgs)) {
        Set<ClientNodeRemote> clients = null;
        try {
            clients = MasterServices.getInstance().getMasterNode().getClientsOnceAllConnected(10000);
        } catch (InterruptedException e) {
        }
        if (clients == null) {
            logger.error("Not possible to access to clients");
        } else {
            /*
				 * The clients have started, and connected back to Master.
				 * So now we just need to tell them to start a search
				 */
            for (ClientNodeRemote client : clients) {
                try {
                    client.doDependencyAnalysis(targetFile);
                } catch (RemoteException e) {
                    logger.error("Error in starting clients", e);
                }
            }
            handler.waitForResult((Properties.GLOBAL_TIMEOUT + Properties.MINIMIZATION_TIMEOUT + Properties.EXTRA_TIMEOUT) * // FIXXME: search
            1000);
        }
        // 100 seconds?
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        handler.killProcess();
    } else {
        LoggingUtils.getEvoLogger().info("* Could not connect to client process");
    }
    handler.closeServer();
    if (!Properties.CLIENT_ON_THREAD) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        logUtils.closeLogServer();
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClientNodeRemote(org.evosuite.rmi.service.ClientNodeRemote) LoggingUtils(org.evosuite.utils.LoggingUtils) RemoteException(java.rmi.RemoteException) ClientProcess(org.evosuite.ClientProcess) ExternalProcessHandler(org.evosuite.utils.ExternalProcessHandler)

Aggregations

IOException (java.io.IOException)4 RemoteException (java.rmi.RemoteException)4 ClientNodeRemote (org.evosuite.rmi.service.ClientNodeRemote)4 ExternalProcessHandler (org.evosuite.utils.ExternalProcessHandler)4 LoggingUtils (org.evosuite.utils.LoggingUtils)4 ArrayList (java.util.ArrayList)3 ClientProcess (org.evosuite.ClientProcess)2 File (java.io.File)1 ResourceList (org.evosuite.classpath.ResourceList)1 TestGenerationResult (org.evosuite.result.TestGenerationResult)1