예제 #1
0
        public void Stop()
        {
            stopping = true;

            try {
                if (communicationManager != null)
                {
                    communicationManager.StopServer();
                    communicationManager = null;
                }
            } catch (Exception ex) {
                LoggingService.LogError("TestPlatformCommunicationManager stop error.", ex);
            }

            try {
                if (dotNetProcess != null)
                {
                    if (!dotNetProcess.HasExited)
                    {
                        dotNetProcess.Dispose();
                    }
                    dotNetProcess = null;
                }
            } catch (Exception ex) {
                LoggingService.LogError("VSTest process dispose error.", ex);
            }
        }
예제 #2
0
        public static string GetOutputFromProcess(string executable, string args, string baseDirectory)
        {
            string         processOutput = null;
            ProcessWrapper p             = null;
            StringWriter   output        = null,
                           error         = null;

            try {
                output = new StringWriter();
                error  = new StringWriter();

                p = Runtime.ProcessService.StartProcess(executable, args, baseDirectory, output, error, null);
                p.WaitForOutput(10000);

                if (p.HasExited)
                {
                    processOutput = output.ToString();
                }
            } finally {
                if (p != null)
                {
                    p.Dispose();
                }
                if (output != null)
                {
                    output.Dispose();
                }
            }

            return(processOutput);
        }
예제 #3
0
 public void should_make_the_process_nonexistent_after_killing_it()
 {
     var pw = new ProcessWrapper("ruby", @"-e ""system(\""ruby -e 'sleep 300'\"")""");
     pw.Execute();
     var processId = pw.Id;
     pw.Dispose();
     Assert.That(ProcessHasExited(processId));
 }
예제 #4
0
 public void should_capture_std_error_output()
 {
     var err = new StringBuilder();
     var pw = new ProcessWrapper("ruby", "-e '$stderr.puts(\"fle\")'");
     pw.OnErrorOutput += output => err.Append(output);
     pw.Execute();
     pw.WaitForProcess(5000);
     pw.Dispose();
     Assert.That(err.ToString(), Is.Not.Empty);
 }
 void Dispose(bool disposing)
 {
     if (mtouchProcess == null)
     {
         return;
     }
     mtouchProcess.Dispose();
     outTail.Dispose();
     errTail.Dispose();
     mtouchProcess = null;
 }
예제 #6
0
        public void should_capture_std_output()
        {
            var std = new StringBuilder();
            var pw = new ProcessWrapper("ruby", "-e 'puts \"ff\"'");
            pw.OnStdOutput += output => std.Append(output);

            pw.Execute();
            pw.WaitForProcess(5000);
            pw.Dispose();

            Assert.That(std.ToString(), Is.Not.Empty);
        }
예제 #7
0
 public static string UnixTotalProcessorTime(int processId)
 {
     var p = new ProcessWrapper("python",string.Format("{0} {1}", Path.Combine(Locations.SupportScriptsLocation, "cpu_times.py"), processId));
     var processStrings = new List<String>();
     var errorStrings = new List<String>();
     p.OnStdOutput += s => { if (!s.IsNullOrEmpty()) processStrings.Add(s); };
     p.OnErrorOutput += s => { if (!s.IsNullOrEmpty()) errorStrings.Add(s); };
     p.Execute();
     p.WaitForProcess(10000);
     p.Dispose();
     return ParseCPUTreeUsageInfo(processStrings, errorStrings);
 }
예제 #8
0
        public void should_indicate_no_cpu_usage_when_process_does_nothing()
        {
            var pw = new ProcessWrapper("ruby", "-e 'sleep 30'");
            pw.Execute();
            pw.WaitForProcess(1000);
            var tpt = pw.ProcessTreeCPUUsageId;
            pw.WaitForProcess(2000);
            var tpt1 = pw.ProcessTreeCPUUsageId;
            pw.Dispose();

            Assert.That(tpt, Is.EqualTo(tpt1));
        }
예제 #9
0
        public void should_indicate_cpu_usage_when_process_consumes_one()
        {
            var pw = new ProcessWrapper("ruby", "-e '100000000.times {|e| e}'");
            pw.Execute();
            pw.WaitForProcess(1);
            var tpt = pw.ProcessTreeCPUUsageId;
            pw.WaitForProcess(500);
            var tpt1 = pw.ProcessTreeCPUUsageId;
            pw.Dispose();

            Assert.That(tpt, Is.Not.EqualTo(tpt1));
        }
예제 #10
0
파일: GitDriver.cs 프로젝트: pshomov/frog
 public CheckoutInfo GetSourceRevision(string revision, string workingArea)
 {
     var scriptPath = Path.Combine(Locations.GitProductionScriptsLocation, "git_fetch.rb");
     var process = new ProcessWrapper("ruby",
                                      scriptPath + " \"" + repoUrl + "\" " + revision + " " + " \"" + workingArea+"\"");
     var log = "";
     process.OnStdOutput += s => { if (!s.IsNullOrEmpty()) log = s; };
     string err_log = "";
     process.OnErrorOutput += s => err_log += s;
     process.Execute();
     process.WaitForProcess(GitTimeoutInMs);
     var exitcode = process.Dispose();
     if (exitcode != 0)
         throw new InvalidProgramException("script failed: "+err_log);
     return new CheckoutInfo {Comment = log, Revision = revision};
 }
예제 #11
0
        static int DoCompilation(ProgressMonitor monitor, string compilerName, string compilerArgs, string working_dir, ExecutionEnvironment envVars, List <string> gacRoots, ref string output, ref string error)
        {
            output = Path.GetTempFileName();
            error  = Path.GetTempFileName();

            StreamWriter outwr = new StreamWriter(output);
            StreamWriter errwr = new StreamWriter(error);

            ProcessStartInfo pinfo = new ProcessStartInfo(compilerName, compilerArgs);

            pinfo.StandardErrorEncoding  = Encoding.UTF8;
            pinfo.StandardOutputEncoding = Encoding.UTF8;

            // The "." is a workaround for a bug in ProcessStartInfo.WorkingDirectory - not able to handle null
            pinfo.WorkingDirectory = working_dir ?? ".";

            if (gacRoots.Count > 0)
            {
                // Create the gac prefix string
                string gacPrefix = string.Join("" + Path.PathSeparator, gacRoots.ToArray());
                string oldGacVar = Environment.GetEnvironmentVariable("MONO_GAC_PREFIX");
                if (!string.IsNullOrEmpty(oldGacVar))
                {
                    gacPrefix += Path.PathSeparator + oldGacVar;
                }
                pinfo.EnvironmentVariables ["MONO_GAC_PREFIX"] = gacPrefix;
            }

            envVars.MergeTo(pinfo);

            pinfo.UseShellExecute        = false;
            pinfo.RedirectStandardOutput = true;
            pinfo.RedirectStandardError  = true;

            ProcessWrapper pw = Runtime.ProcessService.StartProcess(pinfo, outwr, errwr, null);

            using (monitor.CancellationToken.Register(pw.Cancel)) {
                pw.Task.Wait();
            }
            int  exitCode        = pw.ExitCode;
            bool cancelRequested = pw.CancelRequested;

            outwr.Close();
            errwr.Close();
            pw.Dispose();
            return(cancelRequested ? 0 : exitCode);
        }
예제 #12
0
 protected virtual void Dispose(bool disposing)
 {
     if (_disposed)
     {
         return;
     }
     try
     {
         _processWrapper.Dispose();
         _settings.Dispose();
     }
     catch (Exception ex)
     {
         Info(ex.ToString());
     }
     _disposed = true;
 }
        static int DoCompilation(string outstr, string workingDir, ExecutionEnvironment envVars, List <string> gacRoots, ref string output, ref string error)
        {
            output = Path.GetTempFileName();
            error  = Path.GetTempFileName();

            var outwr = new StreamWriter(output);
            var errwr = new StreamWriter(error);

            string[] tokens = outstr.Split(' ');

            outstr = outstr.Substring(tokens[0].Length + 1);

            var pinfo = new ProcessStartInfo(tokens[0], outstr);

            pinfo.WorkingDirectory = workingDir;

            if (gacRoots.Count > 0)
            {
                // Create the gac prefix string
                string gacPrefix = string.Join("" + Path.PathSeparator, gacRoots.ToArray());
                string oldGacVar = Environment.GetEnvironmentVariable("MONO_GAC_PREFIX");
                if (!string.IsNullOrEmpty(oldGacVar))
                {
                    gacPrefix += Path.PathSeparator + oldGacVar;
                }
                pinfo.EnvironmentVariables ["MONO_GAC_PREFIX"] = gacPrefix;
            }

            envVars.MergeTo(pinfo);

            pinfo.UseShellExecute        = false;
            pinfo.RedirectStandardOutput = true;
            pinfo.RedirectStandardError  = true;

            ProcessWrapper pw = Runtime.ProcessService.StartProcess(pinfo, outwr, errwr, null);

            pw.WaitForOutput();
            int exitCode = pw.ExitCode;

            outwr.Close();
            errwr.Close();
            pw.Dispose();
            return(exitCode);
        }
예제 #14
0
        int ExecuteCommand(string command, string args, string baseDirectory, IProgressMonitor monitor, out string errorOutput)
        {
            errorOutput = string.Empty;
            int exitCode = -1;

            StringWriter  swError      = new StringWriter();
            LogTextWriter chainedError = new LogTextWriter();

            chainedError.ChainWriter(monitor.Log);
            chainedError.ChainWriter(swError);

            monitor.Log.WriteLine("{0} {1}", command, args);

            AggregatedOperationMonitor operationMonitor = new AggregatedOperationMonitor(monitor);

            try
            {
                ProcessWrapper p = Runtime.ProcessService.StartProcess(command, args, baseDirectory, monitor.Log, chainedError, null);
                operationMonitor.AddOperation(p); //handles cancellation

                p.WaitForOutput();
                errorOutput = swError.ToString();
                exitCode    = p.ExitCode;
                p.Dispose();

                if (monitor.IsCancelRequested)
                {
                    monitor.Log.WriteLine(GettextCatalog.GetString("Build cancelled"));
                    monitor.ReportError(GettextCatalog.GetString("Build cancelled"), null);
                    if (exitCode == 0)
                    {
                        exitCode = -1;
                    }
                }
            }
            finally
            {
                chainedError.Close();
                swError.Close();
                operationMonitor.Dispose();
            }

            return(exitCode);
        }
예제 #15
0
        void Disconnect()
        {
            if (process == null)
            {
                return;
            }

            log.WriteConsoleLogText("\nDisconnected\n");

            if (!process.HasExited)
            {
                process.Kill();
            }
            else if (process.ExitCode != 0)
            {
                log.WriteError(string.Format("Unknown error {0}\n", process.ExitCode));
            }

            process.Dispose();

            process = null;
        }
예제 #16
0
파일: GitDriver.cs 프로젝트: pshomov/frog
 public RevisionInfo GetLatestRevision()
 {
     string scriptPath = Path.Combine(Locations.GitProductionScriptsLocation, "git_remote_latest_rev.rb");
     var process = new ProcessWrapper("ruby",
                                      scriptPath + " \"" + repoUrl+"\"");
     string result = "";
     process.OnStdOutput +=
         s =>
             {
                 if (result.Length == 0 && !s.IsNullOrEmpty())
                 {
                     if (Regex.IsMatch(s, RevisionExtractingRegex))
                         result = Regex.Match(s, RevisionExtractingRegex).Groups[1].Value;
                 }
             };
     process.Execute();
     process.WaitForProcess(GitTimeoutInMs);
     var exitcode = process.Dispose();
     if (exitcode != 0)
         throw new InvalidProgramException(string.Format("script failed with exit code {1}: {0}", 1, exitcode));
     if (result.IsNullOrEmpty())
         throw new InvalidProgramException("Failed to retrieve repo revision");
     return new RevisionInfo {Revision = result};
 }
예제 #17
0
        private string[] Headers(Project project, string filename, bool with_system)
        {
            List <string> headers  = new List <string> ();
            CProject      cproject = project as CProject;

            if (cproject == null)
            {
                return(headers.ToArray());
            }

            StringBuilder output = new StringBuilder();
            StringBuilder option = new StringBuilder("-M");

            if (!with_system)
            {
                option.Append("M");
            }

            option.Append(" -MG ");
            foreach (Package package in cproject.Packages)
            {
                package.ParsePackage();
                option.AppendFormat("{0} ", string.Join(" ", package.CFlags.ToArray()));
            }

            ProcessWrapper p = null;

            try {
                p = Runtime.ProcessService.StartProcess("gcc", option.ToString() + filename.Replace(@"\ ", " ").Replace(" ", @"\ "), null, null);
                p.WaitForOutput();

                // Doing the below completely breaks header parsing
                // // Skip first two lines (.o & .c* files) - WARNING, sometimes this is compacted to 1 line... we need a better way of handling this.
                // if(p.StandardOutput.ReadLine () == null) return new string[0]; // object file
                // if(p.StandardOutput.ReadLine () == null) return new string[0]; // compile file

                string line;
                while ((line = p.StandardOutput.ReadLine()) != null)
                {
                    output.Append(line);
                }
            } catch (Exception ex) {
                LoggingService.LogError(ex.ToString());
                return(new string [0]);
            }
            finally {
                if (p != null)
                {
                    p.Dispose();
                }
            }

            MatchCollection files = Regex.Matches(output.ToString().Replace(@" \", String.Empty), @" (?<file>([^ \\]|(\\ ))+)", RegexOptions.IgnoreCase);

            foreach (Match match in files)
            {
                string depfile = findFileInIncludes(project, match.Groups["file"].Value.Trim());

                headers.Add(depfile.Replace(@"\ ", " ").Replace(" ", @"\ "));
            }

            return(headers.ToArray());
        }
 public void Dispose()
 {
     _process?.Dispose();
 }
예제 #19
0
 public void should_throw_an_exception_when_trying_to_get_process_snapshot_for_process_that_has_died()
 {
     var pw = new ProcessWrapper("ruby", @"-e exit 0");
     pw.Execute();
     pw.WaitForProcess(1000);
     var processId = pw.Id;
     //            pw.Dispose();
     Assert.That(ProcessHasExited(processId));
     try
     {
         var tpt = pw.ProcessTreeCPUUsageId;
         Assert.Fail("the process should have been gone, operation should have failed");
     }
     catch(InvalidOperationException)
     {
         // that's what we are aiming for ;)
     }
     pw.Dispose();
 }
        private void FillFileInformation(FileInformation fileInfo)
        {
            if (!DepsInstalled)
            {
                return;
            }

            string confdir         = PropertyService.ConfigPath;
            string tagFileName     = Path.GetFileName(fileInfo.FileName) + ".tag";
            string tagdir          = Path.Combine(confdir, "system-tags");
            string tagFullFileName = Path.Combine(tagdir, tagFileName);
            string ctags_kinds     = "--C++-kinds=+px";

            if (PropertyService.Get <bool> ("CBinding.ParseLocalVariables", true))
            {
                ctags_kinds += "l";
            }

            string ctags_options = ctags_kinds + " --fields=+aStisk-fz --language-force=C++ --excmd=number --line-directives=yes -f '" + tagFullFileName + "' '" + fileInfo.FileName + "'";

            if (!Directory.Exists(tagdir))
            {
                Directory.CreateDirectory(tagdir);
            }

            if (!File.Exists(tagFullFileName) || File.GetLastWriteTimeUtc(tagFullFileName) < File.GetLastWriteTimeUtc(fileInfo.FileName))
            {
                ProcessWrapper         p      = null;
                System.IO.StringWriter output = null;
                try {
                    output = new System.IO.StringWriter();

                    p = Runtime.ProcessService.StartProcess("ctags", ctags_options, null, null, output, null);
                    p.WaitForOutput(10000);
                    if (p.ExitCode != 0 || !File.Exists(tagFullFileName))
                    {
                        LoggingService.LogError("Ctags did not successfully populate the tags database '{0}' within ten seconds.\nOutput: {1}", tagFullFileName, output.ToString());
                        return;
                    }
                } catch (Exception ex) {
                    throw new IOException("Could not create tags database (You must have exuberant ctags installed).", ex);
                } finally {
                    if (output != null)
                    {
                        output.Dispose();
                    }
                    if (p != null)
                    {
                        p.Dispose();
                    }
                }
            }

            string ctags_output;
            string tagEntry;

            using (StreamReader reader = new StreamReader(tagFullFileName)) {
                ctags_output = reader.ReadToEnd();
            }

            using (StringReader reader = new StringReader(ctags_output)) {
                while ((tagEntry = reader.ReadLine()) != null)
                {
                    if (tagEntry.StartsWith("!_"))
                    {
                        continue;
                    }

                    Tag tag = ParseTag(tagEntry);

                    if (tag != null)
                    {
                        AddInfo(fileInfo, tag, ctags_output);
                    }
                }
            }

            fileInfo.IsFilled = true;
        }
        private void DoUpdateFileTags(Project project, string filename)
        {
            if (!DepsInstalled)
            {
                return;
            }

            string[]      headers        = Headers(project, filename, false);
            string[]      system_headers = diff(Headers(project, filename, true), headers);
            StringBuilder ctags_kinds    = new StringBuilder("--C++-kinds=+px");

            if (PropertyService.Get <bool> ("CBinding.ParseLocalVariables", true))
            {
                ctags_kinds.Append("+l");
            }

            // Maybe we should only ask for locals for 'local' files? (not external #includes?)
            ctags_kinds.AppendFormat(" --fields=+aStisk-fz --language-force=C++ --excmd=number --line-directives=yes -f - '{0}'", filename);
            foreach (string header in headers)
            {
                ctags_kinds.AppendFormat(" '{0}'", header);
            }

            string ctags_output = string.Empty;

            ProcessWrapper p = null;

            System.IO.StringWriter output = null, error = null;
            try {
                output = new System.IO.StringWriter();
                error  = new System.IO.StringWriter();

                p = Runtime.ProcessService.StartProcess("ctags", ctags_kinds.ToString(), project.BaseDirectory, output, error, null);
                p.WaitForOutput(10000);
                if (p.ExitCode != 0)
                {
                    LoggingService.LogError("Ctags did not successfully populate the tags database from '{0}' within ten seconds.\nError output: {1}", filename, error.ToString());
                    return;
                }
                ctags_output = output.ToString();
            } catch (Exception ex) {
                throw new IOException("Could not create tags database (You must have exuberant ctags installed).", ex);
            } finally {
                if (output != null)
                {
                    output.Dispose();
                }
                if (error != null)
                {
                    error.Dispose();
                }
                if (p != null)
                {
                    p.Dispose();
                }
            }

            ProjectInformation info = ProjectInformationManager.Instance.Get(project);

            lock (info) {
                info.RemoveFileInfo(filename);
                string tagEntry;

                using (StringReader reader = new StringReader(ctags_output)) {
                    while ((tagEntry = reader.ReadLine()) != null)
                    {
                        if (tagEntry.StartsWith("!_"))
                        {
                            continue;
                        }

                        Tag tag = ParseTag(tagEntry);

                        if (tag != null)
                        {
                            AddInfo(info, tag, ctags_output);
                        }
                    }
                }
            }

            OnFileUpdated(new ClassPadEventArgs(project));

            if (PropertyService.Get <bool> ("CBinding.ParseSystemTags", true))
            {
                UpdateSystemTags(project, filename, system_headers);
            }

            if (cache.Count > cache_size)
            {
                cache.Clear();
            }
        }
예제 #22
0
        public void Dispose()
        {
            PeParser.Dispose();

            RemoteProcess.Dispose();
        }