2003-01-22 23:18:58 +08:00
|
|
|
/* cygrun.c: testsuite support program
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
/* This program is intended to be used only by the testsuite. It runs
|
|
|
|
programs without using the cygwin api, so that the just-built dll
|
|
|
|
can be tested without interference from the currently installed
|
|
|
|
dll. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
STARTUPINFO sa;
|
|
|
|
PROCESS_INFORMATION pi;
|
2023-07-11 18:17:56 +08:00
|
|
|
DWORD res;
|
2003-01-22 23:18:58 +08:00
|
|
|
DWORD ec = 1;
|
|
|
|
char *p;
|
2023-07-20 20:54:09 +08:00
|
|
|
DWORD timeout = 60 * 1000;
|
2003-01-22 23:18:58 +08:00
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
2023-07-06 18:54:04 +08:00
|
|
|
fprintf (stderr, "Usage: cygrun [program]\n");
|
2023-07-20 20:54:09 +08:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < argc; ++i)
|
|
|
|
{
|
|
|
|
if (strcmp (argv[i], "-notimeout") == 0)
|
|
|
|
timeout = INFINITE;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *command = argv[i];
|
|
|
|
|
|
|
|
if (i < (argc-1))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "cygrun: excess arguments\n");
|
|
|
|
exit (1);
|
2003-01-22 23:18:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SetEnvironmentVariable ("CYGWIN_TESTING", "1");
|
|
|
|
|
|
|
|
memset (&sa, 0, sizeof (sa));
|
|
|
|
memset (&pi, 0, sizeof (pi));
|
2023-07-20 20:54:09 +08:00
|
|
|
if (!CreateProcess (0, command, 0, 0, 1, 0, 0, 0, &sa, &pi))
|
2003-01-22 23:18:58 +08:00
|
|
|
{
|
2023-07-20 20:54:09 +08:00
|
|
|
fprintf (stderr, "CreateProcess %s failed\n", command);
|
2003-01-22 23:18:58 +08:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2023-07-20 20:54:09 +08:00
|
|
|
res = WaitForSingleObject (pi.hProcess, timeout);
|
2003-01-22 23:18:58 +08:00
|
|
|
|
2023-07-11 18:17:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2003-01-22 23:18:58 +08:00
|
|
|
|
|
|
|
CloseHandle (pi.hProcess);
|
|
|
|
CloseHandle (pi.hThread);
|
2005-01-10 12:13:39 +08:00
|
|
|
if (ec > 0xff)
|
|
|
|
ec >>= 8;
|
2003-01-22 23:18:58 +08:00
|
|
|
return ec;
|
|
|
|
}
|