Esempio n. 1
0
        public UnitProcess(string clientId, string startDir)
        {
            int clientPort = GetClientPort();

            if (clientId == null)
            {
                clientId = GetClientId().ToString();
            }
            this.ID = clientId;
            string localArgs = "--id=" + clientId + " --driver=tcp://" +
                               Util.IPAddressString + ':' + Util.DriverPort + '/' +
                               CommConstants.DriverService + " --bbServer=";

            if (Util.ExternalBBServer != null)
            {
                localArgs += Util.ExternalBBServer + ' ' + clientPort;
            }
            else
            {
                localArgs += "tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                             '/' + CommConstants.BBService + ' ' + clientPort;
            }
            lock (((ICollection)ProcessIDMap).SyncRoot)
            {
                ProcessIDMap[clientId] = m_clientEvent;
            }
            bool procStarted;
            bool hasCoverage = "true".Equals(Environment.GetEnvironmentVariable(
                                                 "COVERAGE_ENABLED"));

            if (hasCoverage)
            {
                string coveragePrefix = "coverage-" + clientId;
                procStarted = Util.StartProcess("ncover.console.exe", "//x "
                                                + coveragePrefix + ".xml " + ClientProcName + " " + localArgs,
                                                Util.LogFile == null, startDir, true, true, true, out m_process);
            }
            else
            {
                procStarted = Util.StartProcess(ClientProcName, localArgs,
                                                Util.LogFile == null, startDir, false, false, false, true, out m_process);
            }
            if (!procStarted)
            {
                throw new AssertionException("FATAL: Could not start client: " +
                                             ClientProcName);
            }

            m_clientComm = ServerConnection <IClientComm> .Connect("tcp://" +
                                                                   Util.IPAddressString + ':' + clientPort + '/' + CommConstants.ClientService);

            m_timeout  = false;
            m_exiting  = false;
            m_startDir = startDir;
        }
Esempio n. 2
0
 private void ExitClient(int waitMillis, bool force)
 {
     if (m_clientComm != null)
     {
         Thread killThread = new Thread(ExitClient);
         killThread.Start();
         if (waitMillis > 0)
         {
             if (!killThread.Join(waitMillis))
             {
                 Util.Log(Util.LogLevel.Error,
                          "Timed out waiting for client {0} to exit.", ID);
             }
         }
         if (m_process != null && !m_process.HasExited)
         {
             if (waitMillis > 0)
             {
                 m_process.WaitForExit(waitMillis);
             }
         }
         if (m_process != null && !m_process.HasExited)
         {
             try
             {
                 m_process.Kill();
             }
             catch
             {
             }
             if (waitMillis > 0)
             {
                 m_process.WaitForExit(waitMillis);
             }
         }
         m_clientComm = null;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Create a UnitProcess object by launching a client using a launcher. The
        /// launcher is launched on the remote host using psexec.
        /// </summary>
        public UnitProcess(string clientId, int clientNum, string psexecPath,
                           string psexecArgs, string hostName, string sharePath, string shareName,
                           string startDir, Dictionary <string, string> envs,
                           int launcherPort, Dictionary <string, UnitProcess> launcherProcesses, string logPath)
        {
            UnitProcess launcherProcess = null;

            if (!launcherProcesses.ContainsKey(hostName))
            {
                launcherProcess = CreateLauncherUsingPsexec(GetClientId().ToString(),
                                                            psexecPath, psexecArgs, hostName, sharePath, shareName, startDir,
                                                            launcherPort, logPath);
                launcherProcesses.Add(hostName, launcherProcess);
            }
            else
            {
                launcherProcess = launcherProcesses[hostName];
            }

            string clientProcPath = ClientProcName;
            string remoteArgs;
            string runDir = null;

            if (sharePath != null)
            {
                runDir         = Util.AssemblyDir.Replace(sharePath.ToLower(), shareName);
                clientProcPath = runDir + Path.DirectorySeparatorChar + ClientProcName;
                clientProcPath = clientProcPath.Replace('/', '\\');
            }

            int clientPort = GetClientPort();

            if (clientId == null)
            {
                clientId = GetClientId().ToString();
            }
            this.ID = clientId;
            string envStr = string.Empty;

            if (envs != null)
            {
                m_envs = envs;
                foreach (KeyValuePair <string, string> envNameValue in envs)
                {
                    string envValue = envNameValue.Value.Replace(sharePath, shareName);
                    envStr += " --env:" + envNameValue.Key + "=\"" + envValue + '\"';
                }
            }
            string bbServer;

            if (Util.ExternalBBServer != null)
            {
                bbServer = Util.ExternalBBServer;
            }
            else
            {
                bbServer = "tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                           '/' + CommConstants.BBService;
            }
            remoteArgs = " --id=" + clientId + " --num=" + clientNum + envStr +
                         " --startdir=\"" + (startDir == null ? runDir : startDir) +
                         "\" --driver=tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                         '/' + CommConstants.DriverService + " --bbServer=\"" + bbServer +
                         "\" " + clientPort;
            try
            {
                IClientCommV2 clientComm = launcherProcess.m_clientComm as IClientCommV2;
                Process       proc;
                if (!clientComm.LaunchNewClient(clientProcPath, remoteArgs, out proc))
                {
                    throw new AssertionException("Failed to start client: " +
                                                 clientId);
                }

                m_process = proc;
                lock (((ICollection)ProcessIDMap).SyncRoot)
                {
                    ProcessIDMap[clientId] = m_clientEvent;
                }

                if (!m_clientEvent.WaitOne(MaxStartWaitMillis, false))
                {
                    throw new AssertionException("Timed out waiting for client to start.");
                }

                m_clientComm = ServerConnection <IClientComm> .Connect("tcp://" +
                                                                       hostName + ':' + clientPort + '/' + CommConstants.ClientService);

                m_process = m_clientComm.GetClientProcess();

                m_psexecPath = psexecPath;
                m_psexecArgs = psexecArgs;
                m_hostName   = hostName;
                m_timeout    = false;
                m_exiting    = false;
                m_sharePath  = sharePath;
                m_shareName  = shareName;
                m_startDir   = startDir;
            }
            catch (Exception ex)
            {
                throw new AssertionException(string.Format("FATAL: Could not start " +
                                                           "client: {1}{0}\ton host: {2}{0}\tusing: FwkLauncher{0}" +
                                                           "\tException: {3}", Environment.NewLine, clientProcPath, hostName,
                                                           ex));
            }
        }
Esempio n. 4
0
        public UnitProcess(string clientId, int clientNum, string sshPath,
                           string sshArgs, string hostName, string sharePath, string shareName,
                           string startDir, Dictionary <string, string> envs)
        {
            string clientProcPath = ClientProcName;
            string remoteArgs;
            string runDir = null;

            if (sharePath != null)
            {
                runDir         = Util.AssemblyDir.Replace(sharePath.ToLower(), shareName);
                clientProcPath = runDir + Path.DirectorySeparatorChar + ClientProcName;
                clientProcPath = clientProcPath.Replace('\\', '/');
            }

            int clientPort = GetClientPort();

            if (clientId == null)
            {
                clientId = GetClientId().ToString();
            }
            this.ID = clientId;
            string envStr = string.Empty;

            if (envs != null)
            {
                m_envs = envs;
                foreach (KeyValuePair <string, string> envNameValue in envs)
                {
                    string envValue = envNameValue.Value.Replace(sharePath, shareName);
                    envStr += " '--env:" + envNameValue.Key + '=' + envValue + '\'';
                }
            }
            string bbServer;

            if (Util.ExternalBBServer != null)
            {
                bbServer = Util.ExternalBBServer;
            }
            else
            {
                bbServer = "tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                           '/' + CommConstants.BBService;
            }
            remoteArgs = sshArgs + ' ' + hostName + " '" + clientProcPath +
                         "' --id=" + clientId + " --num=" + clientNum + envStr +
                         " '--startdir=" + (startDir == null ? runDir : startDir) +
                         "' '--driver=tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                         '/' + CommConstants.DriverService + "' '--bbServer=" + bbServer +
                         "' " + clientPort;
            try
            {
                lock (((ICollection)ProcessIDMap).SyncRoot)
                {
                    ProcessIDMap[clientId] = m_clientEvent;
                }
                if (!Util.StartProcess(sshPath, remoteArgs, Util.LogFile == null,
                                       null, false, false, false, out m_process))
                {
                    throw new AssertionException("Failed to start the client.");
                }

                if (!m_clientEvent.WaitOne(MaxStartWaitMillis, false))
                {
                    throw new AssertionException("Timed out waiting for client to start.");
                }
                m_clientComm = ServerConnection <IClientComm> .Connect("tcp://" +
                                                                       hostName + ':' + clientPort + '/' + CommConstants.ClientService);

                m_process   = m_clientComm.GetClientProcess();
                m_sshPath   = sshPath;
                m_sshArgs   = sshArgs;
                m_hostName  = hostName;
                m_timeout   = false;
                m_exiting   = false;
                m_sharePath = sharePath;
                m_shareName = shareName;
                m_startDir  = startDir;
            }
            catch (Exception ex)
            {
                throw new AssertionException(string.Format("FATAL: Could not start " +
                                                           "client: {1}{0}\ton host: {2}{0}\tusing remote shell: {3}{0}" +
                                                           "\tException: {4}", Environment.NewLine, clientProcPath, hostName,
                                                           sshPath, ex));
            }
        }