From db99fc5c63d779e733e75fc6884ca7bab81e3b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 3 Sep 2025 10:12:07 +0200 Subject: [PATCH 1/2] Add --debug-attach option to MTP --- .../Builder/TestApplication.cs | 24 +++++++++++++------ .../PlatformCommandLineProvider.cs | 2 ++ .../Resources/PlatformResources.resx | 5 +++- .../Resources/xlf/PlatformResources.cs.xlf | 5 ++++ .../Resources/xlf/PlatformResources.de.xlf | 5 ++++ .../Resources/xlf/PlatformResources.es.xlf | 5 ++++ .../Resources/xlf/PlatformResources.fr.xlf | 5 ++++ .../Resources/xlf/PlatformResources.it.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ja.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ko.xlf | 5 ++++ .../Resources/xlf/PlatformResources.pl.xlf | 5 ++++ .../Resources/xlf/PlatformResources.pt-BR.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ru.xlf | 5 ++++ .../Resources/xlf/PlatformResources.tr.xlf | 5 ++++ .../xlf/PlatformResources.zh-Hans.xlf | 5 ++++ .../xlf/PlatformResources.zh-Hant.xlf | 5 ++++ .../HelpInfoTests.cs | 2 ++ .../HelpInfoTests.cs | 14 ++++++++++- 18 files changed, 103 insertions(+), 9 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs index fc8c2870ef..4ee303edd6 100644 --- a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs +++ b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs @@ -78,6 +78,11 @@ public static async Task 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)) + { + WaitForDebuggerToAttach(systemEnvironment, systemConsole, systemProcess); + } + TestHostControllerInfo testHostControllerInfo = new(parseResult); CurrentTestApplicationModuleInfo testApplicationModuleInfo = new(systemEnvironment, systemProcess); @@ -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(); } /* diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs index 5f1b3f192b..6d4e95d680 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs @@ -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-attach"; public const string ServerOptionKey = "server"; public const string ClientPortOptionKey = "client-port"; @@ -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), diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 9ca55934cd..a3c8767c8f 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -713,4 +713,7 @@ Takes one argument as string in the format <value>[h|m|s] where 'value' is Passing both '--treenode-filter' and '--filter-uid' is unsupported. - + + Allows to pause execution in order to attach to the process for debug purposes. + + \ No newline at end of file diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf index 2dd7c37384..d7788c81b0 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -466,6 +466,11 @@ Určuje soubor testconfig.json. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf index 2901eea04a..a739f627ef 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -466,6 +466,11 @@ Gibt eine testconfig.json-Datei an. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf index 613ea681c3..5d78b736ff 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -466,6 +466,11 @@ Especifica un archivo testconfig.json. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf index 6ac9dfb271..5460814520 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -466,6 +466,11 @@ Spécifie un fichier testconfig.json. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf index e2b61cae0c..f810f98b81 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -466,6 +466,11 @@ Specifica un file testconfig.json. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf index 1998a73c03..e08f96a303 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -466,6 +466,11 @@ testconfig.json ファイルを指定します。 + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf index e2d0097ada..3b7c2d118a 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -466,6 +466,11 @@ testconfig.json 파일을 지정합니다. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf index 9f96ada5b5..b22b0c5fad 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -466,6 +466,11 @@ Określa plik testconfig.json. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf index a0884e336d..25cef70f6d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf @@ -466,6 +466,11 @@ Especifica um arquivo testconfig.json. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf index e57b6d1544..0c59bd9def 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -466,6 +466,11 @@ Указывает файл testconfig.json. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf index 4008f64005..0837ca3b32 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -466,6 +466,11 @@ testconfig.json dosyası belirtir. + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf index 5fdcc9180a..4f4cf7fd1f 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf @@ -466,6 +466,11 @@ 指定 testconfig.json 文件。 + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf index 60fd30786c..55cb5acaab 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf @@ -466,6 +466,11 @@ 指定 testconfig.json 檔案。 + + Allows to pause execution in order to attach to the process for debug purposes. + Allows to pause execution in order to attach to the process for debug purposes. + + 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). diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs index f65ad6d7c4..270538fc7a 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -28,6 +28,8 @@ Execute a .NET Test Application. Options: --config-file Specifies a testconfig.json file. + --debug-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 diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs index 1956c917fc..62c565df8c 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -22,6 +22,8 @@ Execute a .NET Test Application. Options: --config-file Specifies a testconfig.json file. + --debug-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 @@ -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-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 @@ -279,6 +285,8 @@ Execute a .NET Test Application. Options: --config-file Specifies a testconfig.json file. + --debug-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 @@ -420,6 +428,10 @@ Microsoft.Testing.Platform v* [*] Arity: 1 Hidden: False Description: Specifies a testconfig.json file. + --debug-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 From 50fafedf0b0fad79f32b46db0293a432c023b7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 3 Sep 2025 13:35:09 +0200 Subject: [PATCH 2/2] Rename option --- .../CommandLine/PlatformCommandLineProvider.cs | 2 +- .../MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs | 2 +- .../HelpInfoTests.cs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs index 6d4e95d680..777497f217 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs @@ -29,7 +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-attach"; + public const string DebugAttachOptionKey = "debug-wait-attach"; public const string ServerOptionKey = "server"; public const string ClientPortOptionKey = "client-port"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs index 270538fc7a..ac09977edf 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -28,7 +28,7 @@ Execute a .NET Test Application. Options: --config-file Specifies a testconfig.json file. - --debug-attach + --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'. diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs index 62c565df8c..0cf5d33aa6 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -22,7 +22,7 @@ Execute a .NET Test Application. Options: --config-file Specifies a testconfig.json file. - --debug-attach + --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'. @@ -154,7 +154,7 @@ Microsoft.Testing.Platform v.+ \[.+\] Arity: 1 Hidden: False Description: Specifies a testconfig\.json file\. - --debug-attach + --debug-wait-attach Arity: 0 Hidden: False Description: Allows to pause execution in order to attach to the process for debug purposes. @@ -285,7 +285,7 @@ Execute a .NET Test Application. Options: --config-file Specifies a testconfig.json file. - --debug-attach + --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'. @@ -428,7 +428,7 @@ Microsoft.Testing.Platform v* [*] Arity: 1 Hidden: False Description: Specifies a testconfig.json file. - --debug-attach + --debug-wait-attach Arity: 0 Hidden: False Description: Allows to pause execution in order to attach to the process for debug purposes.