internal GatherTestCodeCoverageCommand(TestRecord test, DirectoryInfo logDirectory)
 {
     this.logDirectory = logDirectory;
     this.test         = test;
     ExecutionEventLog.RecordStatus("Beginning Code Coverage session.");
     CodeCoverageUtilities.BeginTrace();
 }
Beispiel #2
0
        /// <summary>
        /// Encapsulates logic for executing.
        /// </summary>
        public override void Execute()
        {
            DirectoryInfo distributedExecutionDirectory = TestRecords.GetDistributedDirectory(DistributionKey, RunDirectory);
            TestRecords   tests = TestRecords.Load(distributedExecutionDirectory);

            ExecutionSettings settings = new ExecutionSettings();

            settings.Tests = tests;
            settings.TestBinariesDirectory = TestBinariesDirectory;
            settings.DebugTests            = DebugTests;
            settings.DebugSti            = DebugSti;
            settings.WaitForDebugger     = WaitForDebugger;
            settings.LogFilesPath        = distributedExecutionDirectory;
            settings.JitDebuggerCommand  = JitDebuggerCommand;
            settings.TimeoutMultiplier   = TimeoutMultiplier;
            settings.ContinueExecution   = ContinueExecution;
            settings.CodeCoverageEnabled = CodeCoverage;
            settings.CodeCoverageImport  = CodeCoverageImport;
            settings.RerunFailures       = RerunFailures;
            settings.SkipDxDiag          = SkipDxDiag;
            CodeCoverageUtilities.ValidateForCodeCoverage(CodeCoverage, CodeCoverageImport);

            tests.Execute(settings);
            tests.Save(distributedExecutionDirectory);
            ExecutionBackupStore.ClearAllIntermediateTestResults(settings.LogFilesPath);
            tests.DisplayConsoleSummary();
        }
Beispiel #3
0
        /// <summary>
        /// Encapsulates logic of merging results.
        /// </summary>
        public override void Execute()
        {
            CodeCoverageUtilities.ValidateForCodeCoverage(CodeCoverage, CodeCoverageImport);
            TestRecords.Merge(RunDirectory, CodeCoverage, CodeCoverageImport);

            //Record the lab Run information at this stage. We assume homogeneous configuration.
            RunInfo.FromEnvironment().Save(RunDirectory);
        }
        public void GetFiltersWithInvalidFilterInput()
        {
            string include, exclude;

            Assert.Throws <ArgumentException>(() => CodeCoverageUtilities.GetFilters("invalidFilter", out include, out exclude));
            Assert.Throws <ArgumentException>(() => CodeCoverageUtilities.GetFilters("+,-:", out include, out exclude));
            Assert.Throws <ArgumentException>(() => CodeCoverageUtilities.GetFilters("+: , -: ", out include, out exclude));
        }
Beispiel #5
0
 public void GetPriorityOrderTest()
 {
     Assert.Equal(1, CodeCoverageUtilities.GetPriorityOrder("cLaSs"));
     Assert.Equal(2, CodeCoverageUtilities.GetPriorityOrder("ComplexiTy"));
     Assert.Equal(3, CodeCoverageUtilities.GetPriorityOrder("MEthoD"));
     Assert.Equal(4, CodeCoverageUtilities.GetPriorityOrder("line"));
     Assert.Equal(5, CodeCoverageUtilities.GetPriorityOrder("InstruCtion"));
     Assert.Equal(6, CodeCoverageUtilities.GetPriorityOrder("invalid"));
 }
 public void SetSourceDirectoryToCurrentLogsMessage()
 {
     SetupMocks();
     CodeCoverageUtilities.SetCurrentDirectoryIfDirectoriesParameterIsEmpty(_ec.Object, " ", "warningMessage");
     Assert.Equal(0, _warnings.Count);
     Assert.Equal(0, _errors.Count);
     Assert.Equal(1, _outputMessages.Count);
     Assert.Equal(_outputMessages[0], "warningMessage");
 }
        public void SetSourceDirectoryTrimsSourceDirectory()
        {
            SetupMocks();
            var sourceDir = CodeCoverageUtilities.SetCurrentDirectoryIfDirectoriesParameterIsEmpty(_ec.Object, " sourceDir  ", "warningMessage");

            Assert.Equal(0, _warnings.Count);
            Assert.Equal(0, _errors.Count);
            Assert.Equal(0, _outputMessages.Count);
            Assert.Equal("sourceDir", sourceDir);
        }
 public void Cleanup()
 {
     try
     {
         bool   retainResults = (ReportingUtilities.InterpretTestOutcome(test) == Result.Pass || (test.TestInfo.Bugs != null && test.TestInfo.Bugs.Count != 0));
         string traceName     = MakeTraceName(test);
         ExecutionEventLog.RecordStatus("Ending Code Coverage session - Saving Code Coverage Trace Results.");
         CodeCoverageUtilities.EndTrace(logDirectory, retainResults, traceName);
     }
     //Hitting a null-ref somewhere in the cleanup logic - need to understand source.
     catch (Exception e)
     {
         ExecutionEventLog.RecordException(e);
     }
 }
Beispiel #9
0
        /// <summary>
        /// Merges the results of distributed execution back together.
        /// </summary>
        /// <param name="distributionDirectory">Root distribution directory for the full set of tests.</param>
        /// /// <param name="useCodeCoverage">Specifies if distribution should account for code coverage data</param>
        /// <param name="codeCoverageConnection">Connection string for Code Coverage Database</param>
        public static void Merge(DirectoryInfo distributionDirectory, bool useCodeCoverage, string codeCoverageConnection)
        {
            DirectoryInfo[] subdirectories = distributionDirectory.GetDirectories();

            TestRecords mergedTestResults = new TestRecords();

            for (int i = 0; i < subdirectories.Length; i++)
            {
                TestRecords deserializedTestResults = TestRecords.Load(subdirectories[i]);
                // If for a testcollection it looks like nothing was run, this
                // suggests badness and we want to halt the merge. If we proceed
                // along with a merge, we end up deleted the TestCollection
                // subsets, making the run unsalvagable. By failing hard here,
                // the culprit set of tests can be rerun, and then merge
                // attempted again.
                if (!ValidateTestsWereExecuted(deserializedTestResults))
                {
                    throw new ApplicationException("TestCollection located in the " + subdirectories[i].FullName + " directory did not have any results. It is highly likely that execution on the associated machine failed. Aborting merge.");
                }

                foreach (TestRecord test in deserializedTestResults.TestCollection)
                {
                    mergedTestResults.TestCollection.Add(test);
                }

                foreach (ExecutionGroupRecord group in deserializedTestResults.ExecutionGroupRecords)
                {
                    mergedTestResults.ExecutionGroupRecords.Add(group);
                }
            }

            mergedTestResults.Save(distributionDirectory);

            if (useCodeCoverage)
            {
                CodeCoverageUtilities.MergeCodeCoverage(subdirectories, distributionDirectory);
                Console.WriteLine("Attempting to Upload Results.");
                CodeCoverageUtilities.UploadCodeCoverage(distributionDirectory, codeCoverageConnection);
                CodeCoverageUtilities.DeleteCodeCoverageMergeInputs(subdirectories);
            }

            // Once we have safely merged the test collections and saved the merged
            // TestCollection to disk, delete those distributed subsets.
            for (int i = 0; i < subdirectories.Length; i++)
            {
                TestRecords.Delete(subdirectories[i]);
            }
        }
        public void GetFiltersWithValidFilterInput()
        {
            string include, exclude;

            CodeCoverageUtilities.GetFilters("", out include, out exclude);
            Assert.Equal(include, "");
            Assert.Equal(exclude, "");

            CodeCoverageUtilities.GetFilters("+:avfd.s.sdsd,-:sad.fdf.fs,-:aa.bb,+:av.fd", out include, out exclude);
            Assert.Equal(include, "avfd.s.sdsd:av.fd");
            Assert.Equal(exclude, "sad.fdf.fs:aa.bb");

            CodeCoverageUtilities.GetFilters("+:avfd.s.sdsd,-:sad.fdf.fs", out include, out exclude);
            Assert.Equal(include, "avfd.s.sdsd");
            Assert.Equal(exclude, "sad.fdf.fs");
        }
Beispiel #11
0
        public void CopyFilesWithDirectoryStructureWhenFilesWithDifferentNamesAreGiven()
        {
            List <string> files = GetAdditionalCodeCoverageFilesWithDifferentFileNames();
            string        destinationFilePath = Path.Combine(Path.GetTempPath(), "additional");

            try
            {
                Directory.CreateDirectory(destinationFilePath);
                CodeCoverageUtilities.CopyFilesFromFileListWithDirStructure(files, ref destinationFilePath);
                Assert.True(File.Exists(Path.Combine(destinationFilePath, "a.xml")));
                Assert.True(File.Exists(Path.Combine(destinationFilePath, "b.xml")));
            }
            finally
            {
                Directory.Delete(destinationFilePath, true);
                Directory.Delete(Path.Combine(Path.GetTempPath(), "A"), true);
            }
        }
Beispiel #12
0
 public void ThrowsIfParameterNull()
 {
     Assert.Throws <ArgumentException>(() => CodeCoverageUtilities.TrimNonEmptyParam(null, "inputName"));
 }
Beispiel #13
0
        public void CopyFilesWithDirectoryStructureWhenInputIsNull()
        {
            string destinationFilePath = string.Empty;

            CodeCoverageUtilities.CopyFilesFromFileListWithDirStructure(null, ref destinationFilePath);
        }
Beispiel #14
0
 public void ThrowsIfParameterIsWhiteSpace()
 {
     Assert.Throws <ArgumentException>(() => CodeCoverageUtilities.TrimNonEmptyParam("       ", "inputName"));
 }
 /// <summary>
 /// Harvest the coverage data, and after we've successfully completed this step, delete the inputs.
 /// A local machine will have a single results\CodeCoverage directory. Queen Bee needs to merge results to then merge to single set in lab scenario.
 /// </summary>
 public void Cleanup()
 {
     ExecutionEventLog.RecordStatus("Locally merging Code Coverage Results.");
     CodeCoverageUtilities.MergeSingleMachineResults(executionLogPath);
 }
Beispiel #16
0
        /// <summary>
        /// Encapsulates logic for running tests.
        /// </summary>
        public override void Execute()
        {
            if (!ContinueExecution)
            {
                // If the run directory already exists, we need to get rid of it for
                // now. In the future we may add a directory versioning scheme so
                // that the results of multiple runs can be retained.
                if (RunDirectory.Exists)
                {
                    RunDirectory.Delete(true);
                }
                RunDirectory.Create();
            }
            else
            {
                if (!RunDirectory.Exists)
                {
                    throw new InvalidOperationException("No run directory exists - the ContinueExecution mode is only intended for finishing an incomplete run.");
                }
            }

            //


            TestRecords.RegisterKey(Environment.MachineName, RunDirectory);

            FilteringSettings filteringSettings = FilteringSettings;
            TestRecords       tests             = TestRecords.Discover(DiscoveryInfoPath, filteringSettings);

            tests.Filter(filteringSettings, DiscoveryInfoPath.Directory);
            tests.Distribute(RunDirectory, null, DiscoveryInfoPath.Directory);

            DirectoryInfo distributedExecutionDirectory = TestRecords.GetDistributedDirectory(Environment.MachineName, RunDirectory);

            tests = TestRecords.Load(distributedExecutionDirectory);
            ExecutionSettings settings = new ExecutionSettings();

            settings.Tests = tests;
            settings.TestBinariesDirectory = DiscoveryInfoPath.Directory;
            settings.DebugTests            = DebugTests;
            settings.DebugSti                    = DebugSti;
            settings.WaitForDebugger             = WaitForDebugger;
            settings.LogFilesPath                = distributedExecutionDirectory;
            settings.FixedTestExecutionDirectory = FixedTestExecutionDirectory;
            settings.JitDebuggerCommand          = JitDebuggerCommand;
            settings.TimeoutMultiplier           = TimeoutMultiplier;
            settings.ContinueExecution           = ContinueExecution;
            settings.CodeCoverageEnabled         = CodeCoverage;
            settings.CodeCoverageImport          = CodeCoverageImport;
            settings.RerunFailures               = RerunFailures;
            settings.SkipDxDiag                  = SkipDxDiag;
            CodeCoverageUtilities.ValidateForCodeCoverage(CodeCoverage, CodeCoverageImport);
            tests.Execute(settings);
            tests.Save(distributedExecutionDirectory);
            ExecutionBackupStore.ClearAllIntermediateTestResults(settings.LogFilesPath);

            TestRecords.Merge(RunDirectory, CodeCoverage, CodeCoverageImport);

            // RunCommand's report policy will be to publish reports to a
            // Report subdirectory of the RunDirectory.
            tests = TestRecords.Load(RunDirectory);
            string  reportDirectoryPath = Path.Combine(RunDirectory.FullName, "Report");
            RunInfo runInfo             = RunInfo.FromOS();

            runInfo.Save(RunDirectory);
            Console.WriteLine("Saving Report to: {0}\\LabReport.xml", reportDirectoryPath);
            tests.GenerateXmlReport(tests, runInfo, new DirectoryInfo(reportDirectoryPath), DiscoveryInfoPath.Directory);
            tests.DisplayConsoleSummary();
        }