Skip to content

Commit

Permalink
Coretestlib: Add information of parent process id during test failure…
Browse files Browse the repository at this point in the history
… for Windows (#112724)

* Print process and parent process using wmic

* Do it for windows only
  • Loading branch information
kunalspathak authored Feb 21, 2025
1 parent 488b948 commit c1fe87a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,12 @@ public int RunTest(string executable, string outputFile, string errorFile, strin
Console.WriteLine($"\t{activeProcess.Id,-6} {activeProcess.ProcessName}");
}

if (OperatingSystem.IsWindows())
{
Console.WriteLine("Snapshot of processes currently running (using wmic):");
Console.WriteLine(GetAllProcessNames_wmic());
}

if (collectCrashDumps)
{
if (crashDumpFolder != null)
Expand Down Expand Up @@ -840,5 +846,27 @@ public int RunTest(string executable, string outputFile, string errorFile, strin

return exitCode;
}

private static string GetAllProcessNames_wmic()
{
// The command to execute
string command = "wmic process get Name, ProcessId, ParentProcessId";

// Start the process and capture the output
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = $"/c {command}";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Start the process and read the output
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit(100); // wait for 100 ms

// Output the result
return output;
}
}
}

0 comments on commit c1fe87a

Please sign in to comment.