Commit ca44f6f0 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: add a new test, which creates and destroys threads

A thread can create another threads, if the number of threads is less
than the limit.

This test case is very useful to check criu freezer.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a37cf7a4
......@@ -73,6 +73,7 @@ static/fifo_wronly
static/zombie00
static/rlimits00
transition/fork
transition/thread-bomb
static/pty00
static/pty01
static/pty04
......@@ -509,7 +510,9 @@ EOF
diff_fds $ddump/dump.fd $ddump/dump.fd.after || return 1
save_maps $PID $ddump/dump.maps.after
diff_maps $ddump/dump.maps $ddump/dump.maps.after || return 1
expr $tname : "static" > /dev/null && {
diff_maps $ddump/dump.maps $ddump/dump.maps.after || return 1
}
if [[ $linkremap ]]; then
echo "remove ./$tdir/link_remap.*"
......@@ -542,7 +545,9 @@ EOF
[ $i -eq 5 ] && return 2
save_maps $PID $ddump/restore.maps
diff_maps $ddump/dump.maps $ddump/restore.maps || return 2
expr $tname : "static" > /dev/null && {
diff_maps $ddump/dump.maps $ddump/restore.maps || return 2
}
fi
done
......
......@@ -11,6 +11,7 @@ TST_NOFILE = \
epoll \
fork \
fork2 \
thread-bomb \
TST_FILE = \
file_read \
......@@ -61,6 +62,8 @@ ptrace.o: override CFLAGS += -pthread
ptrace: override LDFLAGS += -pthread
ipc: override CFLAGS += -DNEW_IPC_NS
fork2: override CFLAGS += -D FORK2
thread-bomb.o: override CFLAGS += -pthread
thread-bomb: override LDFLAGS += -pthread
%: %.sh
cp $< $@
......
#include <pthread.h>
#include <unistd.h>
#include <linux/unistd.h>
#include <syscall.h>
#include <fcntl.h>
#include <errno.h>
#include "zdtmtst.h"
static int p[2];
static char buf[100]; /* the size is equal to the limit of threads */
#define exit_group(code) \
syscall(__NR_exit_group, code)
static void *thread_fn(void *arg)
{
pthread_t t;
char c = 0;
int ret;
while (test_go()) {
ret = read(p[0], &c, 1);
if (ret == -1 && errno == EAGAIN)
return NULL;
if (ret != 1)
goto err;
if (pthread_create(&t, NULL, thread_fn, NULL))
goto err;
pthread_join(t, NULL);
if (write(p[1], &c, 1) != 1)
goto err;
}
return NULL;
err:
exit_group(1);
return NULL;
}
int main(int argc, char **argv)
{
if (pipe(p))
return 1;
fcntl(p[0], F_SETFL, O_NONBLOCK);
if (write(p[1], buf, sizeof(buf)) != sizeof(buf))
return 1;
test_init(argc, argv);
test_daemon();
thread_fn(NULL);
pass();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment