Skip to content
Snippets Groups Projects
Commit b1c44c58 authored by James Johnston's avatar James Johnston Committed by Brad King
Browse files

Process: Refactor sleeping code in testProcess.c.

Code for delaying/sleeping has been unified into one location.

Change-Id: I234f3e1be667539e8126f7ed24aec95fe14284b3
parent 4cd8846c
No related branches found
No related tags found
No related merge requests found
...@@ -35,17 +35,37 @@ ...@@ -35,17 +35,37 @@
# pragma warn -8060 /* possibly incorrect assignment */ # pragma warn -8060 /* possibly incorrect assignment */
#endif #endif
/* Platform-specific sleep functions. */
#if defined(__BEOS__) && !defined(__ZETA__) #if defined(__BEOS__) && !defined(__ZETA__)
/* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */ /* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */
# include <be/kernel/OS.h> # 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 #else
# define testProcess_usleep usleep # define testProcess_usleep usleep
#endif #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 runChild(const char* cmd[], int state, int exception, int value,
int share, int output, int delay, double timeout, int poll, int share, int output, int delay, double timeout, int poll,
int repeat, int disown); int repeat, int disown);
...@@ -73,11 +93,7 @@ static int test3(int argc, const char* argv[]) ...@@ -73,11 +93,7 @@ static int test3(int argc, const char* argv[])
fprintf(stderr, "Output before sleep on stderr from timeout test.\n"); fprintf(stderr, "Output before sleep on stderr from timeout test.\n");
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
#if defined(_WIN32) testProcess_sleep(15);
Sleep(15000);
#else
sleep(15);
#endif
fprintf(stdout, "Output after sleep on stdout from timeout test.\n"); fprintf(stdout, "Output after sleep on stdout from timeout test.\n");
fprintf(stderr, "Output after sleep on stderr from timeout test.\n"); fprintf(stderr, "Output after sleep on stderr from timeout test.\n");
return 0; return 0;
...@@ -168,11 +184,7 @@ static int test7(int argc, const char* argv[]) ...@@ -168,11 +184,7 @@ static int test7(int argc, const char* argv[])
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
/* Sleep for 1 second. */ /* Sleep for 1 second. */
#if defined(_WIN32) testProcess_sleep(1);
Sleep(1000);
#else
sleep(1);
#endif
fprintf(stdout, "Output on stdout after sleep.\n"); fprintf(stdout, "Output on stdout after sleep.\n");
fprintf(stderr, "Output on stderr after sleep.\n"); fprintf(stderr, "Output on stderr after sleep.\n");
fflush(stdout); fflush(stdout);
...@@ -217,11 +229,7 @@ static int test8_grandchild(int argc, const char* argv[]) ...@@ -217,11 +229,7 @@ static int test8_grandchild(int argc, const char* argv[])
implemented. */ implemented. */
fclose(stdout); fclose(stdout);
fclose(stderr); fclose(stderr);
#if defined(_WIN32) testProcess_sleep(15);
Sleep(15000);
#else
sleep(15);
#endif
return 0; return 0;
} }
...@@ -286,17 +294,13 @@ static int runChild2(kwsysProcess* kp, ...@@ -286,17 +294,13 @@ static int runChild2(kwsysProcess* kp,
if(poll) if(poll)
{ {
/* Delay to avoid busy loop during polling. */ /* Delay to avoid busy loop during polling. */
#if defined(_WIN32)
Sleep(100);
#else
testProcess_usleep(100000); testProcess_usleep(100000);
#endif
} }
if(delay) if(delay)
{ {
/* Purposely sleeping only on Win32 to let pipe fill up. */ /* Purposely sleeping only on Win32 to let pipe fill up. */
#if defined(_WIN32) #if defined(_WIN32)
Sleep(100); testProcess_usleep(100000);
#endif #endif
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment