Cygwin: testsuite: Add a simple timeout mechanism

Astonishingly, we don't have this already, so tests which hang just stop
the testsuite dead in it's tracks...

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
This commit is contained in:
Jon Turney 2023-07-11 11:17:56 +01:00
parent e8c1a579cd
commit 328258eba4
No known key found for this signature in database
GPG Key ID: C7C86F0370285C81
1 changed files with 15 additions and 2 deletions

View File

@ -20,6 +20,7 @@ main (int argc, char **argv)
{ {
STARTUPINFO sa; STARTUPINFO sa;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
DWORD res;
DWORD ec = 1; DWORD ec = 1;
char *p; char *p;
@ -42,9 +43,21 @@ main (int argc, char **argv)
exit (1); exit (1);
} }
WaitForSingleObject (pi.hProcess, INFINITE); res = WaitForSingleObject (pi.hProcess, 60 * 1000);
GetExitCodeProcess (pi.hProcess, &ec); if (res == WAIT_TIMEOUT)
{
char cmd[1024];
// there is no simple API to kill a Windows process tree
sprintf(cmd, "taskkill /f /t /pid %lu", GetProcessId(pi.hProcess));
system(cmd);
fprintf (stderr, "Timeout\n");
ec = 124;
}
else
{
GetExitCodeProcess (pi.hProcess, &ec);
}
CloseHandle (pi.hProcess); CloseHandle (pi.hProcess);
CloseHandle (pi.hThread); CloseHandle (pi.hThread);