private void DoRunTests(ICollection <TestCase> testCasesToRun, IRunContext runContext, IFrameworkHandle frameworkHandle) { if (testCasesToRun.Count == 0) { return; } bool isRunningInsideVisualStudio = !string.IsNullOrEmpty(runContext.SolutionDirectory); var reporter = new VsTestFrameworkReporter(frameworkHandle, isRunningInsideVisualStudio, _logger); var launcher = new DebuggedProcessLauncher(frameworkHandle); ProcessExecutor processExecutor = null; if (_settings.UseNewTestExecutionFramework) { IDebuggerAttacher debuggerAttacher = null; if (runContext.IsBeingDebugged) { debuggerAttacher = new MessageBasedDebuggerAttacher(_settings.DebuggingNamedPipeId, _logger); } processExecutor = new ProcessExecutor(debuggerAttacher, _logger); } lock (_lock) { if (_canceled) { return; } _executor = new GoogleTestExecutor(_logger, _settings); } _executor.RunTests(testCasesToRun, reporter, launcher, runContext.IsBeingDebugged, runContext.SolutionDirectory, processExecutor); reporter.AllTestsFinished(); }
public NativeDebuggedProcessExecutor(IDebuggerAttacher debuggerAttacher, DebuggerEngine debuggerEngine, bool printTestOutput, ILogger logger) { _debuggerAttacher = debuggerAttacher ?? throw new ArgumentNullException(nameof(debuggerAttacher)); _debuggerEngine = debuggerEngine; _printTestOutput = printTestOutput; _logger = logger; }
/// <summary> /// Constructs the host for DebuggerAttacherService. /// </summary> /// <param name="id">Identifier of the service end-point</param> public DebuggerAttacherServiceHost(string id, IDebuggerAttacher debuggerAttacher, ILogger logger) : base(new DebuggerAttacherService(debuggerAttacher, logger), new Uri[] { DebuggerAttacherServiceConfiguration.ConstructPipeUri(id) }) { AddServiceEndpoint(typeof(IDebuggerAttacherService), new NetNamedPipeBinding(), DebuggerAttacherServiceConfiguration.InterfaceAddress); }
internal static int ExecuteCommandBlocking( string command, string parameters, string workingDir, string pathExtension, IDebuggerAttacher debuggerAttacher, Action <string> reportOutputLine, Action <int> reportProcessId) { using (var pipeStream = new ProcessOutputPipeStream()) { var processInfo = CreateProcess(command, parameters, workingDir, pathExtension, pipeStream._writingEnd); reportProcessId(processInfo.dwProcessId); using (var process = new SafeWaitHandle(processInfo.hProcess, true)) using (var thread = new SafeWaitHandle(processInfo.hThread, true)) { pipeStream.ConnectedToChildProcess(); debuggerAttacher?.AttachDebugger(processInfo.dwProcessId); ResumeThread(thread); using (var reader = new StreamReader(pipeStream, Encoding.Default)) while (!reader.EndOfStream) { reportOutputLine(reader.ReadLine()); } WaitForSingleObject(process, INFINITE); int exitCode; if (!GetExitCodeProcess(process, out exitCode)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not get exit code of process"); } return(exitCode); } } }
public DebuggerAttacherService(string debuggingNampedPipeId, IDebuggerAttacher debuggerAttacher, ILogger logger) { _debuggingNampedPipeId = debuggingNampedPipeId; _debuggerAttacher = debuggerAttacher; _logger = logger; _server = CreateAndStartPipeServer(); if (_server != null) { _logger.DebugInfo("Server side of named pipe started"); } }
private void DoRunTests( IEnumerable <TestCase> allTestCasesInExecutables, ICollection <TestCase> testCasesToRun, IRunContext runContext, IFrameworkHandle frameworkHandle) { bool isRunningInsideVisualStudio = !string.IsNullOrEmpty(runContext.SolutionDirectory); var reporter = new VsTestFrameworkReporter(frameworkHandle, isRunningInsideVisualStudio); var launcher = new DebuggedProcessLauncher(frameworkHandle); ProcessExecutor processExecutor = null; if (_settings.UseNewTestExecutionFramework) { IDebuggerAttacher debuggerAttacher = null; if (runContext.IsBeingDebugged) { debuggerAttacher = new VsDebuggerAttacher(_logger, _settings.VisualStudioProcessId); } processExecutor = new ProcessExecutor(debuggerAttacher, _logger); } _executor = new GoogleTestExecutor(_logger, _settings); _executor.RunTests(allTestCasesInExecutables, testCasesToRun, reporter, launcher, runContext.IsBeingDebugged, runContext.SolutionDirectory, processExecutor); reporter.AllTestsFinished(); }
public TestExecutor(ILogger logger, SettingsWrapper settings, IDebuggerAttacher debuggerAttacher) { _logger = logger; _settings = settings; _debuggerAttacher = debuggerAttacher; }
public static bool AttachDebugger(this IDebuggerAttacher attacher, int processIdToAttachTo) { return(attacher.AttachDebugger(Process.GetProcessById(processIdToAttachTo))); }
public DebuggerAttacherService(IDebuggerAttacher debuggerAttacher, ILogger logger) { _debuggerAttacher = debuggerAttacher; _logger = logger; }
public ProcessExecutor(IDebuggerAttacher debuggerAttacher, ILogger logger) { _debuggerAttacher = debuggerAttacher; _logger = logger; }
internal static int ExecuteCommandBlocking( string command, string parameters, string workingDir, string pathExtension, IDebuggerAttacher debuggerAttacher, DebuggerEngine debuggerEngine, ILogger logger, bool printTestOutput, Action <string> reportOutputLine, Action <int> reportProcessId) { ProcessOutputPipeStream pipeStream = null; try { pipeStream = new ProcessOutputPipeStream(); var processInfo = CreateProcess(command, parameters, workingDir, pathExtension, pipeStream._writingEnd); reportProcessId(processInfo.dwProcessId); using (var process = new SafeWaitHandle(processInfo.hProcess, true)) using (var thread = new SafeWaitHandle(processInfo.hThread, true)) { pipeStream.ConnectedToChildProcess(); logger.DebugInfo($"Attaching debugger to '{command}' via {debuggerEngine} engine"); if (!debuggerAttacher.AttachDebugger(processInfo.dwProcessId, debuggerEngine)) { logger.LogError($"Could not attach debugger to process {processInfo.dwProcessId}"); } if (printTestOutput) { DotNetProcessExecutor.LogStartOfOutput(logger, command, parameters); } ResumeThread(thread); using (var reader = new StreamReader(pipeStream, Encoding.Default)) { pipeStream = null; while (!reader.EndOfStream) { string line = reader.ReadLine(); reportOutputLine(line); if (printTestOutput) { logger.LogInfo(line); } } } WaitForSingleObject(process, INFINITE); if (printTestOutput) { DotNetProcessExecutor.LogEndOfOutput(logger); } int exitCode; if (!GetExitCodeProcess(process, out exitCode)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not get exit code of process"); } return(exitCode); } } finally { pipeStream?.Dispose(); } }
public DebuggedProcessExecutorFactory(IFrameworkHandle frameworkHandle, IDebuggerAttacher debuggerAttacher) { _frameworkHandle = frameworkHandle; _debuggerAttacher = debuggerAttacher; }