@samitouri / QOSAMI-WSL / commits / 14a635f6

Make the tests actually terminate on ctrl-c (#40460)

* Make the tests actually terminate on ctrl-c * Fix the exit condition

Blue committed May 8, 2026 at 10:51 UTC 14a635f6d39777196aa4c2482d8e715a605b23d0
2 files changed +24 -4
test/windows/Common.cpp
+11
@@ -58,6 +58,7 @@ static HANDLE g_OriginalStderr;
58 static BOOL g_RelogEverything = TRUE;
59 static bool g_LogDmesgAfterEachTest = false;
60 static PTP_TIMER g_WatchdogTimer;
61 +
62 static BOOL g_VmMode;
63 static std::wstring g_originalConfig;
64 static std::wstring g_originalDefaultDistro;
@@ -69,6 +70,7 @@ std::wstring g_testDistroPath;
70 std::wstring g_testDataPath;
71 bool g_fastTestRun = false; // True when test.bat was invoked with -f
72 static wil::unique_mta_usage_cookie g_mtaCookie;
73 +static wil::unique_handle g_processJob;
74
75 std::pair<wil::unique_handle, wil::unique_handle> CreateSubprocessPipe(bool inheritRead, bool inheritWrite, DWORD bufferSize, _In_opt_ SECURITY_ATTRIBUTES* sa)
76 {
@@ -1977,6 +1979,15 @@ Return Value:
1979
1980 THROW_IF_FAILED(CoIncrementMTAUsage(&g_mtaCookie));
1981
1982 + // Assign a job object to the current process to ensure that we don't leak processes on failure.
1983 + g_processJob.reset(CreateJobObjectW(nullptr, nullptr));
1984 + THROW_LAST_ERROR_IF(!g_processJob);
1985 +
1986 + JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobInfo{};
1987 + jobInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
1988 + THROW_IF_WIN32_BOOL_FALSE(SetInformationJobObject(g_processJob.get(), JobObjectExtendedLimitInformation, &jobInfo, sizeof(jobInfo)));
1989 + THROW_IF_WIN32_BOOL_FALSE(AssignProcessToJobObject(g_processJob.get(), GetCurrentProcess()));
1990 +
1991 // Don't crash for unknown exceptions (makes debugging testpasses harder)
1992 #ifndef _DEBUG
1993 wil::g_fResultFailFastUnknownExceptions = false;
tools/test/run-tests.ps1
+13 -4
@@ -89,14 +89,23 @@ if (-not $HasUserSelection)
89 $teArgList += "/select:`"@WSLVersion='$Version' or not(@WSLVersion='*')`""
90 }
91
92 -$teProcess = Start-Process -FilePath "te.exe" -ArgumentList $teArgList -PassThru -NoNewWindow
93 -
92 if ($AttachDebugger)
93 {
94 + $teProcess = Start-Process -FilePath "te.exe" -ArgumentList $teArgList -PassThru -NoNewWindow
95 +
96 # /inproc is always added above, so attach directly to TE.exe.
97 Write-Host "Launching WinDbgX attached to TE.exe (PID: $($teProcess.Id))..."
98 Start-Process "WinDbgX.exe" -ArgumentList "-p $($teProcess.Id)"
99 +
100 + $teProcess | Wait-Process
101 + exit $teProcess.ExitCode
102 +}
103 +else
104 +{
105 + te.exe $teArgList
106 + if (!$?)
107 + {
108 + exit 1
109 + }
110 }
111
101 -$teProcess | Wait-Process
102 -exit $teProcess.ExitCode