Skip to content

Coretestlib: Add information of parent process id during test failure for Windows #112724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025
Merged
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
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 @@ -801,6 +801,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 @@ -833,5 +839,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;
}
}
}
Loading