mirror of
https://github.com/samba-team/samba.git
synced 2025-01-25 06:04:04 +03:00
pthreadpool: Add test for fork crash
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Kamen Mazdrashki <kamenim@samba.org> Reviewed-by: Simo Sorce <simo@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
parent
ccc187ff5e
commit
7e12bfc6a8
@ -5,6 +5,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include "pthreadpool.h"
|
#include "pthreadpool.h"
|
||||||
|
|
||||||
static int test_init(void)
|
static int test_init(void)
|
||||||
@ -318,6 +320,46 @@ static int test_threaded_addjob(int num_pools, int num_threads, int poolsize,
|
|||||||
return 0;
|
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 main(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -328,6 +370,12 @@ int main(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = test_fork();
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "test_fork failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
ret = test_jobs(10, 10000);
|
ret = test_jobs(10, 10000);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "test_jobs failed\n");
|
fprintf(stderr, "test_jobs failed\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user