Commit 49efb6ae authored by Kitware Robot's avatar Kitware Robot Committed by Brad King
Browse files

KWSys 2015-07-30 (f63febb7)

Extract upstream KWSys using the following shell commands.

$ git archive --prefix=upstream-kwsys/ f63febb7 | tar x
$ git shortlog --no-merges --abbrev=8 --format='%h %s' c9336bcf..f63febb7
Brad King (1):
      83b4a6b8 Process: Fix conversion warning in testProcess.c

James Johnston (7):
      4cd8846c Process: Remove trailing whitespace in ProcessUNIX.c
      b1c44c58 Process: Refactor sleeping code in testProcess.c.
      faff2ab0 Process: Wait for children to terminate on Ctrl+C.
      ef517b19 Process: Added initial support for process groups.
      906c2cae Process: Added test cases for testing Ctrl+C and process groups.
      52874e6a Process: Fix leaked file descriptor in ProcessUNIX
      f63febb7 Process: Fix error message for startup failure on Windows
parent 083f7a8f
......@@ -1237,7 +1237,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
IF(NOT CYGWIN)
SET(KWSYS_TEST_PROCESS_7 7)
ENDIF()
FOREACH(n 1 2 3 4 5 6 ${KWSYS_TEST_PROCESS_7})
FOREACH(n 1 2 3 4 5 6 ${KWSYS_TEST_PROCESS_7} 9 10)
ADD_TEST(kwsys.testProcess-${n} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestProcess ${n})
SET_PROPERTY(TEST kwsys.testProcess-${n} PROPERTY LABELS ${KWSYS_LABELS_TEST})
SET_TESTS_PROPERTIES(kwsys.testProcess-${n} PROPERTIES TIMEOUT 120)
......@@ -1270,6 +1270,10 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
MESSAGE(STATUS "GET_TEST_PROPERTY returned: ${wfv}")
ENDIF()
# Set up ctest custom configuration file.
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/CTestCustom.cmake.in
${PROJECT_BINARY_DIR}/CTestCustom.cmake @ONLY)
# Suppress known consistent failures on buggy systems.
IF(KWSYS_TEST_BOGUS_FAILURES)
SET_TESTS_PROPERTIES(${KWSYS_TEST_BOGUS_FAILURES} PROPERTIES WILL_FAIL ON)
......
# kwsys.testProcess-10 involves sending SIGINT to a child process, which then
# exits abnormally via a call to _exit(). (On Windows, a call to ExitProcess).
# Naturally, this results in plenty of memory being "leaked" by this child
# process - the memory check results are not meaningful in this case.
#
# kwsys.testProcess-9 also tests sending SIGINT to a child process. However,
# normal operation of that test involves the child process timing out, and the
# host process kills (SIGKILL) it as a result. Since it was SIGKILL'ed, the
# resulting memory leaks are not logged by valgrind anyway. Therefore, we
# don't have to exclude it.
set(CTEST_CUSTOM_MEMCHECK_IGNORE
${CTEST_CUSTOM_MEMCHECK_IGNORE}
kwsys.testProcess-10
)
......@@ -23,58 +23,60 @@
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
#endif
#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsysProcess kwsys_ns(Process)
# define kwsysProcess_s kwsys_ns(Process_s)
# define kwsysProcess_New kwsys_ns(Process_New)
# define kwsysProcess_Delete kwsys_ns(Process_Delete)
# define kwsysProcess_SetCommand kwsys_ns(Process_SetCommand)
# define kwsysProcess_AddCommand kwsys_ns(Process_AddCommand)
# define kwsysProcess_SetTimeout kwsys_ns(Process_SetTimeout)
# define kwsysProcess_SetWorkingDirectory kwsys_ns(Process_SetWorkingDirectory)
# define kwsysProcess_SetPipeFile kwsys_ns(Process_SetPipeFile)
# define kwsysProcess_SetPipeNative kwsys_ns(Process_SetPipeNative)
# define kwsysProcess_SetPipeShared kwsys_ns(Process_SetPipeShared)
# define kwsysProcess_Option_Detach kwsys_ns(Process_Option_Detach)
# define kwsysProcess_Option_HideWindow kwsys_ns(Process_Option_HideWindow)
# define kwsysProcess_Option_MergeOutput kwsys_ns(Process_Option_MergeOutput)
# define kwsysProcess_Option_Verbatim kwsys_ns(Process_Option_Verbatim)
# define kwsysProcess_GetOption kwsys_ns(Process_GetOption)
# define kwsysProcess_SetOption kwsys_ns(Process_SetOption)
# define kwsysProcess_Option_e kwsys_ns(Process_Option_e)
# define kwsysProcess_State_Starting kwsys_ns(Process_State_Starting)
# define kwsysProcess_State_Error kwsys_ns(Process_State_Error)
# define kwsysProcess_State_Exception kwsys_ns(Process_State_Exception)
# define kwsysProcess_State_Executing kwsys_ns(Process_State_Executing)
# define kwsysProcess_State_Exited kwsys_ns(Process_State_Exited)
# define kwsysProcess_State_Expired kwsys_ns(Process_State_Expired)
# define kwsysProcess_State_Killed kwsys_ns(Process_State_Killed)
# define kwsysProcess_State_Disowned kwsys_ns(Process_State_Disowned)
# define kwsysProcess_GetState kwsys_ns(Process_GetState)
# define kwsysProcess_State_e kwsys_ns(Process_State_e)
# define kwsysProcess_Exception_None kwsys_ns(Process_Exception_None)
# define kwsysProcess_Exception_Fault kwsys_ns(Process_Exception_Fault)
# define kwsysProcess_Exception_Illegal kwsys_ns(Process_Exception_Illegal)
# define kwsysProcess_Exception_Interrupt kwsys_ns(Process_Exception_Interrupt)
# define kwsysProcess_Exception_Numerical kwsys_ns(Process_Exception_Numerical)
# define kwsysProcess_Exception_Other kwsys_ns(Process_Exception_Other)
# define kwsysProcess_GetExitException kwsys_ns(Process_GetExitException)
# define kwsysProcess_Exception_e kwsys_ns(Process_Exception_e)
# define kwsysProcess_GetExitCode kwsys_ns(Process_GetExitCode)
# define kwsysProcess_GetExitValue kwsys_ns(Process_GetExitValue)
# define kwsysProcess_GetErrorString kwsys_ns(Process_GetErrorString)
# define kwsysProcess_GetExceptionString kwsys_ns(Process_GetExceptionString)
# define kwsysProcess_Execute kwsys_ns(Process_Execute)
# define kwsysProcess_Disown kwsys_ns(Process_Disown)
# define kwsysProcess_WaitForData kwsys_ns(Process_WaitForData)
# define kwsysProcess_Pipes_e kwsys_ns(Process_Pipes_e)
# define kwsysProcess_Pipe_None kwsys_ns(Process_Pipe_None)
# define kwsysProcess_Pipe_STDIN kwsys_ns(Process_Pipe_STDIN)
# define kwsysProcess_Pipe_STDOUT kwsys_ns(Process_Pipe_STDOUT)
# define kwsysProcess_Pipe_STDERR kwsys_ns(Process_Pipe_STDERR)
# define kwsysProcess_Pipe_Timeout kwsys_ns(Process_Pipe_Timeout)
# define kwsysProcess_Pipe_Handle kwsys_ns(Process_Pipe_Handle)
# define kwsysProcess_WaitForExit kwsys_ns(Process_WaitForExit)
# define kwsysProcess_Kill kwsys_ns(Process_Kill)
# define kwsysProcess kwsys_ns(Process)
# define kwsysProcess_s kwsys_ns(Process_s)
# define kwsysProcess_New kwsys_ns(Process_New)
# define kwsysProcess_Delete kwsys_ns(Process_Delete)
# define kwsysProcess_SetCommand kwsys_ns(Process_SetCommand)
# define kwsysProcess_AddCommand kwsys_ns(Process_AddCommand)
# define kwsysProcess_SetTimeout kwsys_ns(Process_SetTimeout)
# define kwsysProcess_SetWorkingDirectory kwsys_ns(Process_SetWorkingDirectory)
# define kwsysProcess_SetPipeFile kwsys_ns(Process_SetPipeFile)
# define kwsysProcess_SetPipeNative kwsys_ns(Process_SetPipeNative)
# define kwsysProcess_SetPipeShared kwsys_ns(Process_SetPipeShared)
# define kwsysProcess_Option_Detach kwsys_ns(Process_Option_Detach)
# define kwsysProcess_Option_HideWindow kwsys_ns(Process_Option_HideWindow)
# define kwsysProcess_Option_MergeOutput kwsys_ns(Process_Option_MergeOutput)
# define kwsysProcess_Option_Verbatim kwsys_ns(Process_Option_Verbatim)
# define kwsysProcess_Option_CreateProcessGroup kwsys_ns(Process_Option_CreateProcessGroup)
# define kwsysProcess_GetOption kwsys_ns(Process_GetOption)
# define kwsysProcess_SetOption kwsys_ns(Process_SetOption)
# define kwsysProcess_Option_e kwsys_ns(Process_Option_e)
# define kwsysProcess_State_Starting kwsys_ns(Process_State_Starting)
# define kwsysProcess_State_Error kwsys_ns(Process_State_Error)
# define kwsysProcess_State_Exception kwsys_ns(Process_State_Exception)
# define kwsysProcess_State_Executing kwsys_ns(Process_State_Executing)
# define kwsysProcess_State_Exited kwsys_ns(Process_State_Exited)
# define kwsysProcess_State_Expired kwsys_ns(Process_State_Expired)
# define kwsysProcess_State_Killed kwsys_ns(Process_State_Killed)
# define kwsysProcess_State_Disowned kwsys_ns(Process_State_Disowned)
# define kwsysProcess_GetState kwsys_ns(Process_GetState)
# define kwsysProcess_State_e kwsys_ns(Process_State_e)
# define kwsysProcess_Exception_None kwsys_ns(Process_Exception_None)
# define kwsysProcess_Exception_Fault kwsys_ns(Process_Exception_Fault)
# define kwsysProcess_Exception_Illegal kwsys_ns(Process_Exception_Illegal)
# define kwsysProcess_Exception_Interrupt kwsys_ns(Process_Exception_Interrupt)
# define kwsysProcess_Exception_Numerical kwsys_ns(Process_Exception_Numerical)
# define kwsysProcess_Exception_Other kwsys_ns(Process_Exception_Other)
# define kwsysProcess_GetExitException kwsys_ns(Process_GetExitException)
# define kwsysProcess_Exception_e kwsys_ns(Process_Exception_e)
# define kwsysProcess_GetExitCode kwsys_ns(Process_GetExitCode)
# define kwsysProcess_GetExitValue kwsys_ns(Process_GetExitValue)
# define kwsysProcess_GetErrorString kwsys_ns(Process_GetErrorString)
# define kwsysProcess_GetExceptionString kwsys_ns(Process_GetExceptionString)
# define kwsysProcess_Execute kwsys_ns(Process_Execute)
# define kwsysProcess_Disown kwsys_ns(Process_Disown)
# define kwsysProcess_WaitForData kwsys_ns(Process_WaitForData)
# define kwsysProcess_Pipes_e kwsys_ns(Process_Pipes_e)
# define kwsysProcess_Pipe_None kwsys_ns(Process_Pipe_None)
# define kwsysProcess_Pipe_STDIN kwsys_ns(Process_Pipe_STDIN)
# define kwsysProcess_Pipe_STDOUT kwsys_ns(Process_Pipe_STDOUT)
# define kwsysProcess_Pipe_STDERR kwsys_ns(Process_Pipe_STDERR)
# define kwsysProcess_Pipe_Timeout kwsys_ns(Process_Pipe_Timeout)
# define kwsysProcess_Pipe_Handle kwsys_ns(Process_Pipe_Handle)
# define kwsysProcess_WaitForExit kwsys_ns(Process_WaitForExit)
# define kwsysProcess_Interrupt kwsys_ns(Process_Interrupt)
# define kwsysProcess_Kill kwsys_ns(Process_Kill)
#endif
#if defined(__cplusplus)
......@@ -199,6 +201,15 @@ kwsysEXPORT void kwsysProcess_SetPipeNative(kwsysProcess* cp, int pipe,
* and ignore the rest of the arguments.
* 0 = No (default)
* 1 = Yes
*
* kwsysProcess_Option_CreateProcessGroup = Whether to place the process in a
* new process group. This is
* useful if you want to send Ctrl+C
* to the process. On UNIX, also
* places the process in a new
* session.
* 0 = No (default)
* 1 = Yes
*/
kwsysEXPORT int kwsysProcess_GetOption(kwsysProcess* cp, int optionId);
kwsysEXPORT void kwsysProcess_SetOption(kwsysProcess* cp, int optionId,
......@@ -208,7 +219,8 @@ enum kwsysProcess_Option_e
kwsysProcess_Option_HideWindow,
kwsysProcess_Option_Detach,
kwsysProcess_Option_MergeOutput,
kwsysProcess_Option_Verbatim
kwsysProcess_Option_Verbatim,
kwsysProcess_Option_CreateProcessGroup
};
/**
......@@ -362,6 +374,17 @@ enum kwsysProcess_Pipes_e
*/
kwsysEXPORT int kwsysProcess_WaitForExit(kwsysProcess* cp, double* timeout);
/**
* Interrupt the process group for the child process that is currently
* running by sending it the appropriate operating-system specific signal.
* The caller should call WaitForExit after this returns to wait for the
* child to terminate.
*
* WARNING: If you didn't specify kwsysProcess_Option_CreateProcessGroup,
* you will interrupt your own process group.
*/
kwsysEXPORT void kwsysProcess_Interrupt(kwsysProcess* cp);
/**
* Forcefully terminate the child process that is currently running.
* The caller should call WaitForExit after this returns to wait for
......@@ -394,6 +417,7 @@ kwsysEXPORT void kwsysProcess_Kill(kwsysProcess* cp);
# undef kwsysProcess_Option_HideWindow
# undef kwsysProcess_Option_MergeOutput
# undef kwsysProcess_Option_Verbatim
# undef kwsysProcess_Option_CreateProcessGroup
# undef kwsysProcess_GetOption
# undef kwsysProcess_SetOption
# undef kwsysProcess_Option_e
......@@ -430,6 +454,7 @@ kwsysEXPORT void kwsysProcess_Kill(kwsysProcess* cp);
# undef kwsysProcess_Pipe_Timeout
# undef kwsysProcess_Pipe_Handle
# undef kwsysProcess_WaitForExit
# undef kwsysProcess_Interrupt
# undef kwsysProcess_Kill
# endif
#endif
......
This diff is collapsed.
This diff is collapsed.
......@@ -29,26 +29,48 @@
# include <windows.h>
#else
# include <unistd.h>
# include <signal.h>
#endif
#if defined(__BORLANDC__)
# pragma warn -8060 /* possibly incorrect assignment */
#endif
/* Platform-specific sleep functions. */
#if defined(__BEOS__) && !defined(__ZETA__)
/* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */
# include <be/kernel/OS.h>
static inline void testProcess_usleep(unsigned int msec)
static inline void testProcess_usleep(unsigned int usec)
{
snooze(usec);
}
#elif defined(_WIN32)
/* Windows can only sleep in millisecond intervals. */
static void testProcess_usleep(unsigned int usec)
{
snooze(msec);
Sleep(usec / 1000);
}
#else
# define testProcess_usleep usleep
#endif
#if defined(_WIN32)
static void testProcess_sleep(unsigned int sec)
{
Sleep(sec*1000);
}
#else
static void testProcess_sleep(unsigned int sec)
{
sleep(sec);
}
#endif
int runChild(const char* cmd[], int state, int exception, int value,
int share, int output, int delay, double timeout, int poll,
int repeat, int disown);
int repeat, int disown, int createNewGroup,
unsigned int interruptDelay);
static int test1(int argc, const char* argv[])
{
......@@ -73,11 +95,7 @@ static int test3(int argc, const char* argv[])
fprintf(stderr, "Output before sleep on stderr from timeout test.\n");
fflush(stdout);
fflush(stderr);
#if defined(_WIN32)
Sleep(15000);
#else
sleep(15);
#endif
testProcess_sleep(15);
fprintf(stdout, "Output after sleep on stdout from timeout test.\n");
fprintf(stderr, "Output after sleep on stderr from timeout test.\n");
return 0;
......@@ -102,7 +120,7 @@ static int test4(int argc, const char* argv[])
#endif
(void)argc; (void)argv;
fprintf(stdout, "Output before crash on stdout from crash test.\n");
fprintf(stderr, "Output before crash on stderr from crash test.\n");
fprintf(stderr, "Output before crash on stderr from crash test.\n");
fflush(stdout);
fflush(stderr);
assert(invalidAddress); /* Quiet Clang scan-build. */
......@@ -127,7 +145,7 @@ static int test5(int argc, const char* argv[])
fflush(stdout);
fflush(stderr);
r = runChild(cmd, kwsysProcess_State_Exception,
kwsysProcess_Exception_Fault, 1, 1, 1, 0, 15, 0, 1, 0);
kwsysProcess_Exception_Fault, 1, 1, 1, 0, 15, 0, 1, 0, 0, 0);
fprintf(stdout, "Output on stdout after recursive test.\n");
fprintf(stderr, "Output on stderr after recursive test.\n");
fflush(stdout);
......@@ -168,11 +186,7 @@ static int test7(int argc, const char* argv[])
fflush(stdout);
fflush(stderr);
/* Sleep for 1 second. */
#if defined(_WIN32)
Sleep(1000);
#else
sleep(1);
#endif
testProcess_sleep(1);
fprintf(stdout, "Output on stdout after sleep.\n");
fprintf(stderr, "Output on stderr after sleep.\n");
fflush(stdout);
......@@ -196,7 +210,7 @@ static int test8(int argc, const char* argv[])
fflush(stdout);
fflush(stderr);
r = runChild(cmd, kwsysProcess_State_Disowned, kwsysProcess_Exception_None,
1, 1, 1, 0, 10, 0, 1, 1);
1, 1, 1, 0, 10, 0, 1, 1, 0, 0);
fprintf(stdout, "Output on stdout after grandchild test.\n");
fprintf(stderr, "Output on stderr after grandchild test.\n");
fflush(stdout);
......@@ -217,18 +231,137 @@ static int test8_grandchild(int argc, const char* argv[])
implemented. */
fclose(stdout);
fclose(stderr);
testProcess_sleep(15);
return 0;
}
static int test9(int argc, const char* argv[])
{
/* Test Ctrl+C behavior: the root test program will send a Ctrl+C to this
process. Here, we start a child process that sleeps for a long time
while ignoring signals. The test is successful if this process waits
for the child to return before exiting from the Ctrl+C handler.
WARNING: This test will falsely pass if the share parameter of runChild
was set to 0 when invoking the test9 process. */
int r;
const char* cmd[4];
(void)argc;
cmd[0] = argv[0];
cmd[1] = "run";
cmd[2] = "109";
cmd[3] = 0;
fprintf(stdout, "Output on stdout before grandchild test.\n");
fprintf(stderr, "Output on stderr before grandchild test.\n");
fflush(stdout);
fflush(stderr);
r = runChild(cmd, kwsysProcess_State_Exited,
kwsysProcess_Exception_None,
0, 1, 1, 0, 30, 0, 1, 0, 0, 0);
/* This sleep will avoid a race condition between this function exiting
normally and our Ctrl+C handler exiting abnormally after the process
exits. */
testProcess_sleep(1);
fprintf(stdout, "Output on stdout after grandchild test.\n");
fprintf(stderr, "Output on stderr after grandchild test.\n");
fflush(stdout);
fflush(stderr);
return r;
}
#if defined(_WIN32)
Sleep(15000);
static BOOL WINAPI test9_grandchild_handler(DWORD dwCtrlType)
{
/* Ignore all Ctrl+C/Break signals. We must use an actual handler function
instead of using SetConsoleCtrlHandler(NULL, TRUE) so that we can also
ignore Ctrl+Break in addition to Ctrl+C. */
(void)dwCtrlType;
return TRUE;
}
#endif
static int test9_grandchild(int argc, const char* argv[])
{
/* The grandchild just sleeps for a few seconds while ignoring signals. */
(void)argc; (void)argv;
#if defined(_WIN32)
if(!SetConsoleCtrlHandler(test9_grandchild_handler, TRUE))
{
return 1;
}
#else
sleep(15);
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
if(sigaction(SIGINT, &sa, 0) < 0)
{
return 1;
}
#endif
fprintf(stdout, "Output on stdout from grandchild before sleep.\n");
fprintf(stderr, "Output on stderr from grandchild before sleep.\n");
fflush(stdout);
fflush(stderr);
/* Sleep for 9 seconds. */
testProcess_sleep(9);
fprintf(stdout, "Output on stdout from grandchild after sleep.\n");
fprintf(stderr, "Output on stderr from grandchild after sleep.\n");
fflush(stdout);
fflush(stderr);
return 0;
}
static int test10(int argc, const char* argv[])
{
/* Test Ctrl+C behavior: the root test program will send a Ctrl+C to this
process. Here, we start a child process that sleeps for a long time and
processes signals normally. However, this grandchild is created in a new
process group - ensuring that Ctrl+C we receive is sent to our process
groups. We make sure it exits anyway. */
int r;
const char* cmd[4];
(void)argc;
cmd[0] = argv[0];
cmd[1] = "run";
cmd[2] = "110";
cmd[3] = 0;
fprintf(stdout, "Output on stdout before grandchild test.\n");
fprintf(stderr, "Output on stderr before grandchild test.\n");
fflush(stdout);
fflush(stderr);
r = runChild(cmd, kwsysProcess_State_Exception,
kwsysProcess_Exception_Interrupt,
0, 1, 1, 0, 30, 0, 1, 0, 1, 0);
fprintf(stdout, "Output on stdout after grandchild test.\n");
fprintf(stderr, "Output on stderr after grandchild test.\n");
fflush(stdout);
fflush(stderr);
return r;
}
static int test10_grandchild(int argc, const char* argv[])
{
/* The grandchild just sleeps for a few seconds and handles signals. */
(void)argc; (void)argv;
fprintf(stdout, "Output on stdout from grandchild before sleep.\n");
fprintf(stderr, "Output on stderr from grandchild before sleep.\n");
fflush(stdout);
fflush(stderr);
/* Sleep for 6 seconds. */
testProcess_sleep(6);
fprintf(stdout, "Output on stdout from grandchild after sleep.\n");
fprintf(stderr, "Output on stderr from grandchild after sleep.\n");
fflush(stdout);
fflush(stderr);
return 0;
}
static int runChild2(kwsysProcess* kp,
const char* cmd[], int state, int exception, int value,
int share, int output, int delay, double timeout,
int poll, int disown)
int poll, int disown, int createNewGroup,
unsigned int interruptDelay)
{
int result = 0;
char* data = 0;
......@@ -249,6 +382,10 @@ static int runChild2(kwsysProcess* kp,
{
kwsysProcess_SetOption(kp, kwsysProcess_Option_Detach, 1);
}
if(createNewGroup)
{
kwsysProcess_SetOption(kp, kwsysProcess_Option_CreateProcessGroup, 1);
}
kwsysProcess_Execute(kp);
if(poll)
......@@ -256,6 +393,12 @@ static int runChild2(kwsysProcess* kp,
pUserTimeout = &userTimeout;
}
if(interruptDelay)
{
testProcess_sleep(interruptDelay);
kwsysProcess_Interrupt(kp);
}
if(!share && !disown)
{
int p;
......@@ -286,17 +429,13 @@ static int runChild2(kwsysProcess* kp,
if(poll)
{
/* Delay to avoid busy loop during polling. */
#if defined(_WIN32)
Sleep(100);
#else
testProcess_usleep(100000);
#endif
}
if(delay)
{
/* Purposely sleeping only on Win32 to let pipe fill up. */
#if defined(_WIN32)
Sleep(100);
testProcess_usleep(100000);
#endif
}
}
......@@ -337,7 +476,7 @@ static int runChild2(kwsysProcess* kp,
printf("Error in administrating child process: [%s]\n",
kwsysProcess_GetErrorString(kp)); break;
};
if(result)
{
if(exception != kwsysProcess_GetExitException(kp))
......@@ -353,7 +492,7 @@ static int runChild2(kwsysProcess* kp,
value, kwsysProcess_GetExitValue(kp));
}
}
if(kwsysProcess_GetState(kp) != state)
{
fprintf(stderr, "Mismatch in state. "
......@@ -374,9 +513,37 @@ static int runChild2(kwsysProcess* kp,
return result;
}
/**
* Runs a child process and blocks until it returns. Arguments as follows:
*
* cmd = Command line to run.
* state = Expected return value of kwsysProcess_GetState after exit.
* exception = Expected return value of kwsysProcess_GetExitException.
* value = Expected return value of kwsysProcess_GetExitValue.
* share = Whether to share stdout/stderr child pipes with our pipes
* by way of kwsysProcess_SetPipeShared. If false, new pipes
* are created.
* output = If !share && !disown, whether to write the child's stdout
* and stderr output to our stdout.
* delay = If !share && !disown, adds an additional short delay to
* the pipe loop to allow the pipes to fill up; Windows only.
* timeout = Non-zero to sets a timeout in seconds via
* kwsysProcess_SetTimeout.
* poll = If !share && !disown, we count the number of 0.1 second
* intervals where the child pipes had no new data. We fail
* if not in the bounds of MINPOLL/MAXPOLL.
* repeat = Number of times to run the process.
* disown = If set, the process is disowned.
* createNewGroup = If set, the process is created in a new process group.
* interruptDelay = If non-zero, number of seconds to delay before
* interrupting the process. Note that this delay will occur
* BEFORE any reading/polling of pipes occurs and before any
* detachment occurs.
*/
int runChild(const char* cmd[], int state, int exception, int value,
int share, int output, int delay, double timeout,
int poll, int repeat, int disown)
int poll, int repeat, int disown, int createNewGroup,
unsigned int interruptDelay)
{
int result = 1;
kwsysProcess* kp = kwsysProcess_New();
......@@ -388,7 +555,8 @@ int runChild(const char* cmd[], int state, int exception, int value,
while(repeat-- > 0)
{
result = runChild2(kp, cmd, state, exception, value, share,
output, delay, timeout, poll, disown);
output, delay, timeout, poll, disown, createNewGroup,
interruptDelay);
}
kwsysProcess_Delete(kp);
return result;
......@@ -435,7 +603,7 @@ int main(int argc, const char* argv[])
n = atoi(argv[2]);
}
/* Check arguments. */
if(((n >= 1 && n <= 8) || n == 108) && argc == 3)
if(((n >= 1 && n <= 10) || n == 108 || n == 109 || n == 110) && argc == 3)
{
/* This is the child process for a requested test number. */
switch (n)
......@@ -448,15 +616,19 @@ int main(int argc, const char* argv[])
case 6: test6(argc, argv); return 0;
case 7: return test7(argc, argv);
case 8: return test8(argc, argv);
case 9: return test9(argc, argv);
case 10: return test10(argc, argv);
case 108: return test8_grandchild(argc, argv);
case 109: return test9_grandchild(argc, argv);
case 110: return test10_grandchild(argc, argv);
}
fprintf(stderr, "Invalid test number %d.\n", n);
return 1;
}
else if(n >= 1 && n <= 8)
else if(n >= 1 && n <= 10)
{
/* This is the parent process for a requested test number. */
int states[8] =
int states[10] =
{
kwsysProcess_State_Exited,
kwsysProcess_State_Exited,
......@@ -465,9 +637,11 @@ int main(int argc, const char* argv[])
kwsysProcess_State_Exited,
kwsysProcess_State_Expired,
kwsysProcess_State_Exited,
kwsysProcess_State_Exited
kwsysProcess_State_Exited,
kwsysProcess_State_Expired, /* Ctrl+C handler test */
kwsysProcess_State_Exception /* Process group test */
};
int exceptions[8] =
int exceptions[10] =
{
kwsysProcess_Exception_None,
kwsysProcess_Exception_None,
......@@ -476,14 +650,19 @@ int main(int argc, const char* argv[])
kwsysProcess_Exception_None,
kwsysProcess_Exception_None,
kwsysProcess_Exception_None,
kwsysProcess_Exception_None
kwsysProcess_Exception_None,
kwsysProcess_Exception_None,
kwsysProcess_Exception_Interrupt
};
int values[8] = {0, 123, 1, 1, 0, 0, 0, 0};
int outputs[8] = {1, 1, 1, 1, 1, 0, 1, 1};
int delays[8] = {0, 0, 0, 0, 0, 1, 0, 0};
double timeouts[8] = {10, 10, 10, 30, 30, 10, -1, 10};
int polls[8] = {0, 0, 0, 0, 0, 0, 1, 0};
int repeat[8] = {2, 1, 1, 1, 1, 1, 1, 1};
int values[10] = {0, 123, 1, 1, 0, 0, 0, 0, 1, 1};
int shares[10] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1};
int outputs[10] = {1, 1, 1, 1, 1, 0, 1, 1, 1, 1};
int delays[10] = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0};
double timeouts[10] = {10, 10, 10, 30, 30, 10, -1, 10, 6, 4};
int polls[10] = {0, 0, 0, 0, 0, 0, 1, 0, 0, 0};
int repeat[10] = {2, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int createNewGroups[10] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1};
unsigned int interruptDelays[10] = {0, 0, 0, 0, 0, 0, 0, 0, 3, 2};
int r;
const char* cmd[4];
#ifdef _WIN32
......@@ -515,9 +694,10 @@ int main(int argc, const char* argv[])
fprintf(stderr, "Output on stderr before test %d.\n", n);
fflush(stdout);
fflush(stderr);
r = runChild(cmd, states[n-1], exceptions[n-1], values[n-1], 0,
r = runChild(cmd, states[n-1], exceptions[n-1], values[n-1], shares[n-1],