From 7e12bfc6a8fe97da907525ae90288e37c4fa7a7f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 3 Mar 2014 11:57:18 +0000 Subject: pthreadpool: Add test for fork crash Signed-off-by: Volker Lendecke Reviewed-by: Kamen Mazdrashki Reviewed-by: Simo Sorce Reviewed-by: Michael Adam --- source3/lib/pthreadpool/tests.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/source3/lib/pthreadpool/tests.c b/source3/lib/pthreadpool/tests.c index 95d37b6f17..170cedf07f 100644 --- a/source3/lib/pthreadpool/tests.c +++ b/source3/lib/pthreadpool/tests.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #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"); -- cgit