diff --git a/test/tools/TestExe/TestExe.cs b/test/tools/TestExe/TestExe.cs index fa57fb5721..ab8f76d542 100644 --- a/test/tools/TestExe/TestExe.cs +++ b/test/tools/TestExe/TestExe.cs @@ -4,6 +4,7 @@ using System; using System.Threading; using System.Diagnostics; +using System.Runtime.InteropServices; namespace TestExe { @@ -11,6 +12,7 @@ namespace TestExe { private static int Main(string[] args) { + int exitCode = 0; if (args.Length > 0) { switch (args[0].ToLowerInvariant()) @@ -18,6 +20,9 @@ namespace TestExe case "-echoargs": EchoArgs(args); break; + case "-echocmdline": + EchoCmdLine(); + break; case "-createchildprocess": CreateChildProcess(args); break; @@ -28,17 +33,23 @@ namespace TestExe case "-stderr": Console.Error.WriteLine(args[1]); break; + case "--help": + case "-h": + PrintHelp(); + break; default: - Console.WriteLine("Unknown test {0}", args[0]); + exitCode = 1; + Console.Error.WriteLine("Unknown test {0}. Run with '-h' for help.", args[0]); break; } } else { - Console.WriteLine("Test not specified"); + exitCode = 1; + Console.Error.WriteLine("Test not specified"); } - return 0; + return exitCode; } // @@ -52,6 +63,36 @@ namespace TestExe } } + // + // Echos the raw command line received by the process plus the arguments passed in. + // + private static void EchoCmdLine() + { + string rawCmdLine = "N/A"; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + nint cmdLinePtr = Interop.GetCommandLineW(); + rawCmdLine = Marshal.PtrToStringUni(cmdLinePtr); + } + + Console.WriteLine(rawCmdLine); + } + + // + // Print help content. + // + private static void PrintHelp() + { + const string Content = @" +Options for echoing args are: + -echoargs Echos back to stdout the arguments passed in. + -echocmdline Echos the raw command line received by the process. + +Other options are for specific tests only. Read source code for details. +"; + Console.WriteLine(Content); + } + // // First argument is the number of child processes to create which are instances of itself // Processes automatically exit after 100 seconds @@ -73,4 +114,10 @@ namespace TestExe Thread.Sleep(100000); } } + + internal static partial class Interop + { + [LibraryImport("Kernel32.dll")] + internal static partial nint GetCommandLineW(); + } }