private ICoverageData UpdateDataImpl()
        {
            try
            {
                var coverageFile = CoverageEnvironment.coverageFile();

                if (activeCoverageFilename != coverageFile)
                {
                    activeCoverageFilename = coverageFile;
                    activeCoverageReport   = null;
                }

                if (File.Exists(coverageFile))
                {
                    if (activeCoverageReport != null)
                    {
                        var lastWT = new FileInfo(coverageFile).LastWriteTimeUtc;
                        if (lastWT > activeCoverageReport.FileDate)
                        {
                            activeCoverageReport = null;
                        }
                    }

                    if (activeCoverageReport == null)
                    {
                        CoverageEnvironment.console.WriteLine("Updating coverage results from: {0}", coverageFile);
                        activeCoverageReport   = Load(coverageFile);
                        activeCoverageFilename = coverageFile;
                    }
                }
            }
            catch { }

            return(activeCoverageReport);
        }
Beispiel #2
0
 private void slotUpdateFinish(object sender, System.EventArgs e)
 {
     CoverageEnvironment.UiInvoke(() =>
     {
         updateGUI();
         readCoverageFile();
         return(true);
     });
 }
Beispiel #3
0
        private void updateGUI()
        {
            var sol    = CoverageEnvironment.hasSolution();
            var locked = CoverageEnvironment.runner != null && CoverageEnvironment.runner.isRunning();

            this.CleanCoverage.IsEnabled  = sol && !locked;
            this.StopCoverage.IsEnabled   = sol && locked;
            this.UpdateCoverage.IsEnabled = sol && !locked;
        }
        public void UpdateReport()
        {
            CoverageEnvironment.print("Coverage: Report has changed -> reading");

            CoverageEnvironment.report = UpdateData();

            CoverageEnvironment.print("Coverage: Report is ready into CoverageEnvironment");

            CoverageEnvironment.emitReportUpdated();
        }
        /// <summary>
        /// Initializes the current coverage data
        /// </summary>
        private void InitCurrent()
        {
            CoverageState[] currentFile = new CoverageState[0];
            ProfileVector   currentProf = new Data.ProfileVector(0);

            // Check report exists
            if (CoverageEnvironment.ShowCodeCoverage && CoverageEnvironment.report != null)
            {
                string activeFilename = System.IO.Path.GetFullPath(GetActiveFilename());
                if (activeFilename != null)
                {
                    CoverageEnvironment.print("Coverage: Print report on " + activeFilename);

                    Tuple <BitVector, ProfileVector> activeReport = null;
                    DateTime activeFileLastWrite = File.GetLastWriteTimeUtc(activeFilename);

                    if (CoverageEnvironment.report.FileDate >= activeFileLastWrite)
                    {
                        CoverageEnvironment.print("Coverage: Report is up to date");
                        activeReport = CoverageEnvironment.report.GetData(activeFilename);

                        if (activeReport != null)
                        {
                            CoverageEnvironment.print("Coverage: File is inside report");
                            currentProf = activeReport.Item2;
                            currentFile = new CoverageState[activeReport.Item1.Count];

                            foreach (var item in activeReport.Item1.Enumerate())
                            {
                                if (item.Value)
                                {
                                    currentFile[item.Key] = CoverageState.Covered;
                                }
                                else
                                {
                                    currentFile[item.Key] = CoverageState.Uncovered;
                                }
                            }
                        }
                        else
                        {
                            CoverageEnvironment.print("Coverage: File " + activeFilename + " is not inside report");
                        }
                    }
                    else
                    {
                        CoverageEnvironment.print("Coverage: Report is too old compare to file.");
                    }
                }
            }

            this.currentCoverage = currentFile;
            this.currentProfile  = currentProf;
        }
Beispiel #6
0
 private void onClean(object sender, RoutedEventArgs e)
 {
     try
     {
         var covFile = CoverageEnvironment.coverageFile();
         // Check if file exists with its full path
         if (System.IO.File.Exists(covFile))
         {
             System.IO.File.Delete(covFile);
         }
     }
     catch (System.IO.IOException)
     {}
     // If file found, delete it
 }
Beispiel #7
0
        private void readCoverageFile()
        {
            if (!CoverageEnvironment.hasSolution())
            {
                return;
            }

            var files = System.IO.Directory.GetFiles(CoverageEnvironment.workingCoverageDir, "*.*", System.IO.SearchOption.AllDirectories)
                        .Where(s => s.EndsWith(".cov"));

            coverageFiles.Items.Clear();
            foreach (var file in files)
            {
                this.coverageFiles.Items.Add(new CoverageItem {
                    Name = System.IO.Path.GetFileNameWithoutExtension(file), RealPath = file
                });
            }
        }
Beispiel #8
0
            public void UpdateSettings()
            {
                Func <Color, System.Windows.Media.Color> convert = (Color input) =>
                {
                    return(System.Windows.Media.Color.FromArgb(input.A, input.R, input.G, input.B));
                };

                CoverageEnvironment.Verbose = Verbose;

                CoverageEnvironment.ShowCodeCoverage = ShowCodeCoverage;
                CoverageEnvironment.isSharable       = OptionIsSharable;
                CoverageEnvironment.excludes         = OptionExcludes.Split(';').ToList();

                CoverageEnvironment.UncoveredBrushColor = convert(UncoveredBrush);
                CoverageEnvironment.UncoveredPenColor   = convert(UncoveredPen);
                CoverageEnvironment.CoveredBrushColor   = convert(CoveredBrush);
                CoverageEnvironment.CoveredPenColor     = convert(CoveredPen);

                CoverageEnvironment.emitSettingsChanged();
            }
Beispiel #9
0
        public void slotInterruption(object sender, System.EventArgs e)
        {
            if (isRunning())
            {
                // End process
                if (!process.HasExited)
                {
                    process.Kill();
                }
            }
            // Remove result
            if (File.Exists(resultFile))
            {
                File.Delete(resultFile);
            }

            output.WriteLine("Code coverage aborted.");

            this.process = null;

            CoverageEnvironment.emitFinishCoverage();
        }
Beispiel #10
0
        public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            Debug.WriteLine("Start with solution");

            try
            {
                // Release all GUI
                //->> ToDo !

                // Reload data
                string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);

                // Configure settings
                CoverageEnvironment.configureSolution(dte, solutionDir);
            }
            catch (Exception exp)
            {
                Debug.WriteLine("Error on loading solution: " + exp.ToString());
            }
            return(VSConstants.S_OK);
        }
Beispiel #11
0
        private void StartImpl(string solutionFolder, string platform, string dllFolder, string dllFilename, string workingDirectory, string commandline)
        {
            try
            {
                if (CoverageEnvironment.UseNativeCoverageSupport)
                {
                    DateTime localDate = DateTime.Now;

                    string time = localDate.ToString("yyyy-MM-dd-HH.MM.ss.fff");
                    // Delete old coverage file
                    resultFile = Path.Combine(CoverageEnvironment.workingCoverageDir, dllFilename + "_" + time + ".cov");
                    string mergeFile = Path.Combine(solutionFolder, "CodeCoverage.cov");
                    if (File.Exists(resultFile))
                    {
                        File.Delete(resultFile);
                    }

                    // Find the executables for Coverage.exe
                    string location = typeof(CoverageExecution).Assembly.Location;
                    string folder   = Path.GetDirectoryName(location);

                    // Create your Process
                    this.process = new Process();

                    // Define filepath to execute
                    string executable = "Coverage-x64.exe";
                    if (platform == "x86")
                    {
                        executable = "Coverage-x86.exe";
                    }
                    process.StartInfo.FileName = Path.Combine(folder, "Resources", executable);
                    if (!File.Exists(process.StartInfo.FileName))
                    {
                        throw new NotSupportedException("Coverage.exe instance for platform was not found. Expected: " + process.StartInfo.FileName);
                    }

                    string sourcesFilter = solutionFolder;
                    int    smidx         = sourcesFilter.IndexOf(' ');
                    if (smidx > 0)
                    {
                        sourcesFilter = sourcesFilter.Substring(0, smidx);
                        int lidx = sourcesFilter.LastIndexOf('\\');
                        if (lidx >= 0)
                        {
                            sourcesFilter = sourcesFilter.Substring(0, lidx - 1);
                        }
                    }

                    StringBuilder argumentBuilder = new StringBuilder();

                    argumentBuilder.Append("-o \"" + resultFile + "\" ");
                    if (CoverageEnvironment.isSharable)
                    {
                        argumentBuilder.Append("-r \"");
                        argumentBuilder.Append(solutionFolder.TrimEnd('\\', '/'));
                        argumentBuilder.Append("\" ");
                    }
                    argumentBuilder.Append("-p \"");
                    argumentBuilder.Append(solutionFolder.TrimEnd('\\', '/'));

                    argumentBuilder.Append("\" -m \"");
                    argumentBuilder.Append(mergeFile.TrimEnd('\\', '/'));

                    // Add exclude path
                    if (CoverageEnvironment.excludes != null)
                    {
                        foreach (var exclude in CoverageEnvironment.excludes)
                        {
                            argumentBuilder.Append("\" -x \"" + exclude);
                        }
                    }

                    if (workingDirectory != null && workingDirectory.Length > 0)
                    {
                        // When directory finish by \ : c++ read \" and arguments is badly computed !
                        workingDirectory = workingDirectory.TrimEnd('\\', '/');

                        argumentBuilder.Append("\" -w \"");
                        argumentBuilder.Append(workingDirectory);
                    }
                    else
                    {
                        argumentBuilder.Append("\"");
                    }

                    if (dllFilename.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
                    {
                        argumentBuilder.Append("\" -- \"");
                    }
                    else
                    {
                        argumentBuilder.Append("\" -- ");
                        argumentBuilder.Append(@"""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe""");
                        argumentBuilder.Append(" /Platform:" + platform + " \"");
                    }

                    argumentBuilder.Append(Path.Combine(dllFolder, dllFilename));
                    if (commandline != null && commandline.Length > 0)
                    {
                        argumentBuilder.Append("\" ");
                        argumentBuilder.Append(commandline);
                    }
                    else
                    {
                        argumentBuilder.Append("\"");
                    }

#if DEBUG
                    this.output.WriteLine("Execute coverage: {0}", argumentBuilder.ToString());
#endif

                    process.StartInfo.WorkingDirectory       = dllFolder;
                    process.StartInfo.Arguments              = argumentBuilder.ToString();
                    process.StartInfo.CreateNoWindow         = true;
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError  = true;

                    process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
                    process.ErrorDataReceived  += new DataReceivedEventHandler(OutputHandler);

                    // All is ready to change GUI
                    CoverageEnvironment.emitStartCoverage();

                    lastEvent = DateTime.UtcNow;

                    if (!process.Start())
                    {
                        throw new Exception("Impossible to launch.");
                    }

                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();

                    bool exited = false;
                    while (!exited && lastEvent.AddMilliseconds(CoverageEnvironment.timeoutCoverage) > DateTime.UtcNow)
                    {
                        exited = process.WaitForExit(CoverageEnvironment.timeoutCoverage);
                    }

                    if (!exited)
                    {
                        // Kill process.
                        process.Kill();
                        throw new Exception("Creating code coverage timed out. Do you have a locked program or need to change timeout into Options ?");
                    }

                    // Remove now
                    process = null;

                    string output = tb.ToString();

                    if (output.Contains("Usage:"))
                    {
                        throw new Exception("Incorrect command line argument passed to coverage tool");
                    }

                    if (output.Contains("Error: the test source file"))
                    {
                        throw new Exception("Cannot find test source file " + dllFilename);
                    }

                    if (!File.Exists(resultFile))
                    {
                        this.output.WriteLine("No coverage report generated. Cannot continue.");
                    }
                }
                else
                {
                    // Delete old coverage file
                    string resultFile    = Path.Combine(solutionFolder, "CodeCoverage.tmp.xml");
                    string defResultFile = Path.Combine(solutionFolder, "CodeCoverage.xml");
                    if (File.Exists(resultFile))
                    {
                        File.Delete(resultFile);
                    }

                    // Create your Process
                    Process process = new Process();
                    if (platform == "x86")
                    {
                        process.StartInfo.FileName = @"c:\Program Files\OpenCppCoverage\x86\OpenCppCoverage.exe";

                        if (!File.Exists(process.StartInfo.FileName))
                        {
                            process.StartInfo.FileName = @"c:\Program Files (x86)\OpenCppCoverage\OpenCppCoverage.exe";
                        }
                    }
                    else
                    {
                        process.StartInfo.FileName = @"c:\Program Files\OpenCppCoverage\OpenCppCoverage.exe";
                    }

                    if (!File.Exists(process.StartInfo.FileName))
                    {
                        throw new NotSupportedException("OpenCPPCoverage was not found. Expected: " + process.StartInfo.FileName);
                    }

                    string sourcesFilter = solutionFolder;
                    int    smidx         = sourcesFilter.IndexOf(' ');
                    if (smidx > 0)
                    {
                        sourcesFilter = sourcesFilter.Substring(0, smidx);
                        int lidx = sourcesFilter.LastIndexOf('\\');
                        if (lidx >= 0)
                        {
                            sourcesFilter = sourcesFilter.Substring(0, lidx - 1);
                        }
                    }

                    StringBuilder argumentBuilder = new StringBuilder();
                    if (dllFilename.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
                    {
                        argumentBuilder.Append("--quiet --export_type cobertura:\"");
                        argumentBuilder.Append(resultFile);
                        argumentBuilder.Append("\" --continue_after_cpp_exception --cover_children ");
                        argumentBuilder.Append("--sources ");
                        argumentBuilder.Append(sourcesFilter);
                        argumentBuilder.Append(" -- \"");
                        argumentBuilder.Append(Path.Combine(dllFolder, dllFilename));
                        argumentBuilder.Append("\"");
                    }
                    else
                    {
                        argumentBuilder.Append("--quiet --export_type cobertura:\"");
                        argumentBuilder.Append(resultFile);
                        argumentBuilder.Append("\" --continue_after_cpp_exception --cover_children ");
                        argumentBuilder.Append("--sources ");
                        argumentBuilder.Append(sourcesFilter);
                        argumentBuilder.Append(" -- ");
                        argumentBuilder.Append(@"""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe""");
                        argumentBuilder.Append(" /Platform:" + platform + " \"");
                        argumentBuilder.Append(Path.Combine(dllFolder, dllFilename));
                        argumentBuilder.Append("\"");
                    }

#if DEBUG
                    this.output.WriteLine("Execute coverage: {0}", argumentBuilder.ToString());
#endif

                    process.StartInfo.WorkingDirectory       = Path.GetDirectoryName(resultFile);
                    process.StartInfo.Arguments              = argumentBuilder.ToString();
                    process.StartInfo.CreateNoWindow         = true;
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError  = true;

                    process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
                    process.ErrorDataReceived  += new DataReceivedEventHandler(OutputHandler);

                    // All is ready to change GUI
                    CoverageEnvironment.emitStartCoverage();

                    process.Start();

                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();

                    bool exited = false;
                    while (!exited && lastEvent.AddMinutes(15) > DateTime.UtcNow)
                    {
                        exited = process.WaitForExit(1000 * 60);
                    }

                    if (!exited)
                    {
                        // Kill process.
                        process.Kill();
                        throw new Exception("Creating code coverage timed out.");
                    }

                    // Remove now
                    process = null;

                    string output = tb.ToString();

                    if (output.Contains("Usage:"))
                    {
                        throw new Exception("Incorrect command line argument passed to coverage tool.");
                    }

                    if (output.Contains("Error: the test source file"))
                    {
                        throw new Exception("Cannot find test source file " + dllFilename);
                    }

                    if (File.Exists(resultFile))
                    {
                        // All fine, update file:
                        if (File.Exists(defResultFile))
                        {
                            File.Delete(defResultFile);
                        }
                        File.Move(resultFile, defResultFile);
                    }
                    else
                    {
                        this.output.WriteLine("No coverage report generated. Cannot continue.");
                    }
                }

                this.output.WriteLine("Code coverage finished.");
            }
            catch (Exception ex)
            {
                output.WriteLine("Uncaught error during coverage execution: {0}", ex.Message);
            }
            finally
            {
                this.process = null;

                Interlocked.Exchange(ref running, 0);
            }

            // In all case, send finish coverage
            CoverageEnvironment.emitFinishCoverage();
        }
 private void SlotFinishChanged(object sender, EventArgs e)
 {
     CoverageEnvironment.UiInvoke(() => { ResetData(); return(true); });
 }
Beispiel #13
0
 public int OnAfterCloseSolution(object pUnkReserved)
 {
     CoverageEnvironment.configureSolution(dte, string.Empty);
     return(VSConstants.S_OK);
 }
Beispiel #14
0
 private void onStop(object sender, RoutedEventArgs e)
 {
     CoverageEnvironment.emitInterruptCoverage();
 }
Beispiel #15
0
        public NativeData(string filename)
        {
            // Get file date (for modified checks)
            FileDate = new System.IO.FileInfo(filename).LastWriteTimeUtc;

            // Read file:
            using (var sr = new System.IO.StreamReader(filename))
            {
                string name = sr.ReadLine();
                while (name != null)
                {
                    if (name.StartsWith("FILE: "))
                    {
                        string currentFile = name.Substring("FILE: ".Length);
                        // If relative, we add solutionDir to relative directory.
                        if (!System.IO.Path.IsPathRooted(currentFile))
                        {
                            // Here: we can add a list of ordered registered folders and try to find file inside.
                            string solutionDir = CoverageEnvironment.solutionPath;
                            currentFile = System.IO.Path.Combine(solutionDir, currentFile);

                            if (!System.IO.File.Exists(currentFile))
                            {
                                CoverageEnvironment.console.WriteLine("Impossible to find into solution: {0}", currentFile);
                            }
                        }

                        string cov = sr.ReadLine();

                        if (cov != null && cov.StartsWith("RES: "))
                        {
                            cov = cov.Substring("RES: ".Length);

                            BitVector currentVector = new Data.BitVector();

                            for (int i = 0; i < cov.Length; ++i)
                            {
                                char c = cov[i];
                                if (c == 'c' || c == 'p')
                                {
                                    currentVector.Set(i + 1, true);
                                }
                                else if (c == 'u')
                                {
                                    currentVector.Set(i + 1, false);
                                }
                                else
                                {
                                    currentVector.Ensure(i + 1);
                                }
                            }

                            ProfileVector currentProfile = new Data.ProfileVector(currentVector.Count);

                            string prof = sr.ReadLine();
                            if (prof != null && prof.StartsWith("PROF: "))
                            {
                                prof = prof.Substring("PROF: ".Length);
                                int line = 0;

                                for (int i = 0; i < prof.Length;)
                                {
                                    int deep = 0;
                                    while (i < prof.Length && prof[i] != ',')
                                    {
                                        char c = prof[i];
                                        deep = deep * 10 + (c - '0');
                                        ++i;
                                    }
                                    ++i;

                                    int shallow = 0;
                                    while (i < prof.Length && prof[i] != ',')
                                    {
                                        char c = prof[i];
                                        shallow = shallow * 10 + (c - '0');
                                        ++i;
                                    }
                                    ++i;

                                    currentProfile.Set(line, deep, shallow);
                                    ++line;
                                }
                            }
                            else
                            {
                                name = prof;
                                continue;
                            }

                            try
                            {
                                lookup.Add(System.IO.Path.GetFullPath(currentFile), new Tuple <BitVector, ProfileVector>(currentVector, currentProfile));
                            }
                            catch (Exception e)
                            {
                                CoverageEnvironment.console.WriteLine("Error loading coverage report: {0} with key {1}", e.Message, currentFile.ToLower());
                            }
                        }
                    }
                    // otherwise: ignore; grab next line

                    name = sr.ReadLine();
                }
            }

            CoverageEnvironment.print("Coverage: Report " + filename + " has been properly read: " + lookup.Count + " items found.");
        }