Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public static async Task<ITestApplicationBuilder> CreateBuilderAsync(string[] ar
// First step is to parse the command line from where we get the second input layer.
// The first one should be the env vars handled autonomously by extensions and part of the test platform.
CommandLineParseResult parseResult = CommandLineParser.Parse(args, systemEnvironment);
if (parseResult.IsOptionSet(PlatformCommandLineProvider.DebugAttachOptionKey))
Comment thread
Evangelink marked this conversation as resolved.
{
WaitForDebuggerToAttach(systemEnvironment, systemConsole, systemProcess);
}

TestHostControllerInfo testHostControllerInfo = new(parseResult);
CurrentTestApplicationModuleInfo testApplicationModuleInfo = new(systemEnvironment, systemProcess);

Expand Down Expand Up @@ -230,16 +235,21 @@ private static void AttachDebuggerIfNeeded(SystemEnvironment environment, System

if (environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_WAIT_ATTACH_DEBUGGER) == "1")
{
using IProcess currentProcess = systemProcess.GetCurrentProcess();
console.WriteLine($"Waiting for debugger to attach... Process Id: {environment.ProcessId}, Name: {currentProcess.Name}");
WaitForDebuggerToAttach(environment, console, systemProcess);
}
}

while (!Debugger.IsAttached)
{
Thread.Sleep(1000);
}
private static void WaitForDebuggerToAttach(SystemEnvironment environment, SystemConsole console, SystemProcessHandler systemProcess)
{
using IProcess currentProcess = systemProcess.GetCurrentProcess();
console.WriteLine($"Waiting for debugger to attach... Process Id: {environment.ProcessId}, Name: {currentProcess.Name}");

Debugger.Break();
while (!Debugger.IsAttached)
{
Thread.Sleep(1000);
}

Debugger.Break();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal sealed class PlatformCommandLineProvider : ICommandLineOptionsProvider
public const string ExitOnProcessExitOptionKey = "exit-on-process-exit";
public const string ConfigFileOptionKey = "config-file";
public const string FilterUidOptionKey = "filter-uid";
public const string DebugAttachOptionKey = "debug-wait-attach";

public const string ServerOptionKey = "server";
public const string ClientPortOptionKey = "client-port";
Expand Down Expand Up @@ -59,6 +60,7 @@ internal sealed class PlatformCommandLineProvider : ICommandLineOptionsProvider
new(ExitOnProcessExitOptionKey, PlatformResources.PlatformCommandLineExitOnProcessExitOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true),
new(ConfigFileOptionKey, PlatformResources.PlatformCommandLineConfigFileOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true),
new(FilterUidOptionKey, PlatformResources.PlatformCommandLineFilterUidOptionDescription, ArgumentArity.OneOrMore, false, isBuiltIn: true),
new(DebugAttachOptionKey, PlatformResources.PlatformCommandLineDebugAttachOptionDescription, ArgumentArity.Zero, false, isBuiltIn: true),

// Hidden options
new(HelpOptionQuestionMark, PlatformResources.PlatformCommandLineHelpOptionDescription, ArgumentArity.Zero, true, isBuiltIn: true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,7 @@ Takes one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is
<data name="OnlyOneFilterSupported" xml:space="preserve">
<value>Passing both '--treenode-filter' and '--filter-uid' is unsupported.</value>
</data>
</root>
<data name="PlatformCommandLineDebugAttachOptionDescription" xml:space="preserve">
<value>Allows to pause execution in order to attach to the process for debug purposes.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">Určuje soubor testconfig.json.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">Gibt eine testconfig.json-Datei an.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">Especifica un archivo testconfig.json.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">Spécifie un fichier testconfig.json.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">Specifica un file testconfig.json.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">testconfig.json ファイルを指定します。</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">testconfig.json 파일을 지정합니다.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">Określa plik testconfig.json.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">Especifica um arquivo testconfig.json.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">Указывает файл testconfig.json.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">testconfig.json dosyası belirtir.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">指定 testconfig.json 文件。</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
<target state="translated">指定 testconfig.json 檔案。</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDebugAttachOptionDescription">
<source>Allows to pause execution in order to attach to the process for debug purposes.</source>
<target state="new">Allows to pause execution in order to attach to the process for debug purposes.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineDiagnosticFileLoggerSynchronousWriteOptionDescription">
<source>Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Execute a .NET Test Application.
Options:
--config-file
Specifies a testconfig.json file.
--debug-wait-attach
Allows to pause execution in order to attach to the process for debug purposes.
--diagnostic
Enable the diagnostic logging. The default log level is 'Trace'.
The file will be written in the output directory with the name log_[yyMMddHHmmssfff].diag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Execute a .NET Test Application.
Options:
--config-file
Specifies a testconfig.json file.
--debug-wait-attach
Allows to pause execution in order to attach to the process for debug purposes.
--diagnostic
Enable the diagnostic logging. The default log level is 'Trace'.
The file will be written in the output directory with the name log_[yyMMddHHmmssfff].diag
Expand Down Expand Up @@ -148,10 +150,14 @@ Microsoft.Testing.Platform v.+ \[.+\]
Arity: 1
Hidden: True
Description: Specify the port of the client\.
--config-file
--config-file
Arity: 1
Hidden: False
Description: Specifies a testconfig\.json file\.
--debug-wait-attach
Arity: 0
Hidden: False
Description: Allows to pause execution in order to attach to the process for debug purposes.
--diagnostic
Arity: 0
Hidden: False
Expand Down Expand Up @@ -279,6 +285,8 @@ Execute a .NET Test Application.
Options:
--config-file
Specifies a testconfig.json file.
--debug-wait-attach
Allows to pause execution in order to attach to the process for debug purposes.
--diagnostic
Enable the diagnostic logging. The default log level is 'Trace'.
The file will be written in the output directory with the name log_[yyMMddHHmmssfff].diag
Expand Down Expand Up @@ -420,6 +428,10 @@ Microsoft.Testing.Platform v* [*]
Arity: 1
Hidden: False
Description: Specifies a testconfig.json file.
--debug-wait-attach
Arity: 0
Hidden: False
Description: Allows to pause execution in order to attach to the process for debug purposes.
--diagnostic
Arity: 0
Hidden: False
Expand Down