diff options
-rw-r--r-- | source3/lib/pthreadpool/tests.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/source3/lib/pthreadpool/tests.c b/source3/lib/pthreadpool/tests.c index 95d37b6f170..170cedf07f7 100644 --- a/source3/lib/pthreadpool/tests.c +++ b/source3/lib/pthreadpool/tests.c @@ -5,6 +5,8 @@ #include <stdlib.h> #include <pthread.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> #include "pthreadpool.h" static int test_init(void) @@ -318,6 +320,46 @@ static int test_threaded_addjob(int num_pools, int num_threads, int poolsize, return 0; } +static int test_fork(void) +{ + struct pthreadpool *p; + pid_t child, waited; + int status, ret; + + ret = pthreadpool_init(1, &p); + if (ret != 0) { + fprintf(stderr, "pthreadpool_init failed: %s\n", + strerror(ret)); + return -1; + } + ret = pthreadpool_destroy(p); + if (ret != 0) { + fprintf(stderr, "pthreadpool_destroy failed: %s\n", + strerror(ret)); + return -1; + } + + child = fork(); + if (child < 0) { + perror("fork failed"); + return -1; + } + if (child == 0) { + exit(0); + } + waited = wait(&status); + if (waited == -1) { + perror("wait failed"); + return -1; + } + if (waited != child) { + fprintf(stderr, "expected child %d, got %d\n", + (int)child, (int)waited); + return -1; + } + return 0; +} + int main(void) { int ret; @@ -328,6 +370,12 @@ int main(void) return 1; } + ret = test_fork(); + if (ret != 0) { + fprintf(stderr, "test_fork failed\n"); + return 1; + } + ret = test_jobs(10, 10000); if (ret != 0) { fprintf(stderr, "test_jobs failed\n"); |