Example #1
0
        /// <summary>
        /// Gather debug information if the process was being monitored, otherwise just terminate.
        /// </summary>
        internal void OnProcessCrash(int processId)
        {
            ExecutionEventLog.RecordStatus("Process " + processId + " crash notification recieved.");
            try
            {
                if (Process.GetCurrentProcess().Id == processId)
                {
                    //It may be possible that some strange unhandled exception is arising in a background thread, leading to a debugger being launched
                    //and the infra Terminating itself. Somehow, it seems unlikely for this code to be reachable, but this case is a hypothetical possibility to account for.
                    ExecutionEventLog.RecordStatus("Catastrophic Situation: Infra has recieved notification that it's own process has crashed. ");
                }
                else if (isTestRunning && pids.Contains(processId) && accumulatedDumpCost < maxDumpCost)
                {
                    ExecutionEventLog.RecordStatus("Debugging Process: " + processId);
                    FileInfo debugLogFilePath  = new FileInfo(Path.Combine(executionDirectory.FullName, "TestInfraDebuggingLog_" + processId + ".log"));
                    FileInfo debugDumpFilePath = new FileInfo(Path.Combine(executionDirectory.FullName, "TestInfraDebuggingDump_" + processId + ".dmp"));

                    CdbUtilities.DebugProcess(processId.ToString(CultureInfo.InvariantCulture), debugLogFilePath, debugDumpFilePath);

                    accumulatedDumpCost += debugDumpFilePath.Length;
                    //

                    LoggingMediator.LogFile(debugLogFilePath.FullName);
                    LoggingMediator.LogFile(debugDumpFilePath.FullName);
                    //Dan: Is the Recording Logger guaranteed to be explicitly aware that the given test has failed if this point is reached?
                    //Getting here means a process the tester cares about has crashed.
                }
                else
                {
                    if (accumulatedDumpCost < maxDumpCost)
                    {
                        ExecutionEventLog.RecordStatus("Terminating non-monitored Process:" + processId);
                    }
                    else
                    {
                        ExecutionEventLog.RecordStatus("Dump limit exceeded - Terminating process without analysis:" + processId);
                    }
                    Process process = Process.GetProcessById(processId);
                    if (process != null && !process.HasExited)
                    {
                        process.Kill();
                        process.WaitForExit();
                    }
                }
            }
            //Uncaught exceptions in this event handler will ---- up the logging stack... Which would be bad.
            catch (Exception exception)
            {
                ExecutionEventLog.RecordException(exception);
            }
        }
Example #2
0
 private void ReportRogueProcesses(List <Process> list)
 {
     foreach (Process p in list)
     {
         try
         {
             ExecutionEventLog.RecordStatus("ALERT- Possible rogue process! Unsuccessfully terminated:" + p.ProcessName + " " + p.Id);
         }
         catch (Exception e)
         {
             ExecutionEventLog.RecordException(e);
         }
     }
 }
 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);
     }
 }
Example #4
0
 /// <summary>
 /// Encapsulates termination of processes.
 /// Debug processes are not a problem, as they execute synchronously.
 /// </summary>
 /// <param name="processes"></param>
 private void TerminateProcesses(List <Process> processes)
 {
     foreach (Process process in processes)
     {
         if (!process.HasExited)
         {
             try
             {
                 ExecutionEventLog.RecordStatus("Process Name: " + process.ProcessName + " ID:" + process.Id + " is being terminated.");
                 process.Kill();
                 process.WaitForExit();
                 ExecutionEventLog.RecordStatus("Process termination completed.");
             }
             catch (InvalidOperationException e)
             {
                 ExecutionEventLog.RecordException(e);
                 //The process has already exited
             }
             catch (Win32Exception e)
             {
                 ExecutionEventLog.RecordException(e);
                 //The process has already exited or access is denied (Probably a Whidbey
             }
             catch (Exception e)
             {
                 ExecutionEventLog.RecordException(e);
             }
             finally
             {
                 if (!process.HasExited)
                 {
                     ExecutionEventLog.RecordStatus("Could not kill process " + process.ProcessName + " ID:" + process.Id);
                     ExecutionEventLog.RecordStatus("Launching external taskkill process to retry killing...");
                     KillWithMoreForce(process);
                 }
             }
         }
     }
 }
Example #5
0
        /// <summary>
        /// Encapsulates discovering processes which emerged during the test run
        /// </summary>
        /// <returns></returns>
        private List <Process> IdentifyUnwantedProcesses(DateTime startTime)
        {
            string userSid = WindowsIdentity.GetCurrent().User.Value;

            List <Process> newProcesses = new List <Process>();

            foreach (Process process in Process.GetProcesses())
            {
                try
                {
                    if (IsUnwantedProcess(startTime, userSid, process))
                    {
                        newProcesses.Add(process);
                    }
                }
                catch (Exception e)
                {
                    //With filtering, we shouldn't be hitting this. -
                    ExecutionEventLog.RecordException(e);
                }
            }
            return(newProcesses);
        }