Ejemplo n.º 1
0
        /// <summary>
        /// Bucketize and run through groups of matching support file needs.
        /// </summary>
        private static void ExecuteTestSupportFileGroups(ExecutionSettings settings, List <TestRecord> stateManagementGroup, ExecutionGroupRecord stateGroupRecord, int stateGroupIndex, ExecutionComponents components)
        {
            int supportFileGroupIndex = 0;

            //Bucketize
            // NOTE: Hash method for SupportFiles is order sensitive.
            IEnumerable <List <TestRecord> > testGroups = ExecutionGrouper.Bucketize(
                stateManagementGroup,
                ExecutionGroupingLevel.SharedSupportFiles,
                x => HashSupportFileGroup(x));

            foreach (List <TestRecord> supportFileGroup in testGroups)
            {
                Stack <ICleanableCommand> filecleanupCommands = new Stack <ICleanableCommand>();

                ExecutionGroupRecord supportFileGroupRecord = ExecutionGroupRecord.Begin(ExecutionGroupType.Files, stateGroupRecord.Area);
                stateGroupRecord.ExecutionGroupRecords.Add(supportFileGroupRecord);
                DirectoryInfo executionDirectory = settings.DetermineTestExecutionDirectory(settings.DetermineGroupPath(stateGroupIndex, supportFileGroupIndex));
                DirectoryInfo logDirectory       = settings.DetermineTestLogDirectory(settings.DetermineGroupPath(stateGroupIndex, supportFileGroupIndex));
                PrepLogDirectory(logDirectory);//HACK: Ideally logging can guarantee this in final configuration.
                if (GetCachedExecutionResult(settings, supportFileGroup, logDirectory, components))
                {
                    ExecutionEventLog.RecordStatus("Successfully retrieved previously stored execution result. ");
                }
                else
                {
                    ExecutionEventLog.RecordStatus("Applying Support Files and Executing.");
                    ExecutionGroupLogCommand command = ExecutionGroupLogCommand.Apply("SupportFiles", logDirectory, components.LoggingMediator);
                    filecleanupCommands.Push(command);
                    filecleanupCommands.Push(DesktopSnapshotCommand.Apply(logDirectory));
                    // Create temporary directory, but if we are using a fixed test execution directory, don't delete it if it was pre-existing.
                    filecleanupCommands.Push(TemporaryDirectoryCommand.Apply(executionDirectory, settings.FixedTestExecutionDirectory != null));
                    filecleanupCommands.Push(SupportFileCommand.Apply(supportFileGroup, settings.TestBinariesDirectory, executionDirectory));
                    filecleanupCommands.Push(BackupRecordsCommand.Apply(supportFileGroup, logDirectory));
                    filecleanupCommands.Push(ProcessLogsCommand.Apply(supportFileGroup, components.LoggingMediator));
                    try
                    {
                        ExecuteUniformTestGroup(settings, supportFileGroup, supportFileGroupRecord, stateGroupIndex, supportFileGroupIndex, components);
                    }
                    catch (Exception e)
                    {
                        ExecutionEventLog.RecordException(e);
                    }
                    finally
                    {
                        Cleanup(filecleanupCommands);
                    }
                }
                supportFileGroupRecord.End();
                supportFileGroupIndex++;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes Tests
        /// </summary>
        public static void Execute(ExecutionSettings settings)
        {
            Stack <ICleanableCommand> cleanupCommands = new Stack <ICleanableCommand>();

            try
            {
                //Elevation Service is hitting Error #5 "Access Denied" in XP - We don't have run time dependencies on it right now, so disabling.
                //cleanupCommands.Push(ElevationServiceCommand.Apply(infraBinariesDirectory));

                cleanupCommands.Push(LogDirectoryCommand.Apply(settings.LogFilesPath, settings.SkipDxDiag));

                ExecutionComponents executionComponents = new ExecutionComponents();
                executionComponents.DebuggingEngine = DebuggingEngineCommand.Apply(settings.InfraBinariesDirectory, settings.JitDebuggerCommand);
                cleanupCommands.Push(executionComponents.DebuggingEngine);
                ExecutionEventLog.RecordStatus("Creating LoggingMediator.");
                executionComponents.LoggingMediator = new LoggingMediator(settings.DebugTests); //Consider using dispose pattern.
                executionComponents.LoggingMediator.StartService(executionComponents.DebuggingEngine, settings.Tests.TestCollection.Count(record => record.ExecutionEnabled));

                //

                cleanupCommands.Push(ExecutionGroupLogCommand.Apply("InfraExecution", settings.LogFilesPath, executionComponents.LoggingMediator));
                if (settings.CodeCoverageEnabled)
                {
                    cleanupCommands.Push(MergeCodeCoverageDataCommand.Apply(settings.LogFilesPath));
                }
                cleanupCommands.Push(TemporaryDirectoryCommand.Apply(settings.ExecutionRootDirectory));
                cleanupCommands.Push(MoveWindowCommand.Apply());
                cleanupCommands.Push(ExecutionEventLog.Apply(settings.LogFilesPath, !settings.ContinueExecution));

                try
                {
                    ExecuteTestStateGroups(settings, executionComponents);
                }
                catch (Exception e)
                {
                    ExecutionEventLog.RecordException(e);
                }
                finally
                {
                    ExecutionEventLog.RecordStatus("Ending Test Sequence.");
                    ExecutionEventLog.RecordStatus("Shutting down test logging system.");
                    executionComponents.LoggingMediator.StopService();
                }
            }
            finally
            {
                Cleanup(cleanupCommands);
                Console.WriteLine("Test Execution has finished.\n");
            }
        }