[CRIU] [PATCH 4/6] zdtm: add a new test, which creates and destroys threads

Andrey Vagin avagin at openvz.org
Thu Dec 19 04:59:44 PST 2013


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: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm.sh                            |  9 +++--
 test/zdtm/live/transition/Makefile      |  3 ++
 test/zdtm/live/transition/thread-bomb.c | 58 +++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 2 deletions(-)
 create mode 100644 test/zdtm/live/transition/thread-bomb.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index cf3e672..545e3d3 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -73,6 +73,7 @@ static/fifo_wronly
 static/zombie00
 static/rlimits00
 transition/fork
+transition/thread-bomb
 static/pty00
 static/pty01
 static/pty04
@@ -514,7 +515,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.*"
@@ -547,7 +550,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
 
 		if [ -n "$PIDNS" ]; then
diff --git a/test/zdtm/live/transition/Makefile b/test/zdtm/live/transition/Makefile
index ea6568b..9da5c90 100644
--- a/test/zdtm/live/transition/Makefile
+++ b/test/zdtm/live/transition/Makefile
@@ -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 $< $@
diff --git a/test/zdtm/live/transition/thread-bomb.c b/test/zdtm/live/transition/thread-bomb.c
new file mode 100644
index 0000000..493de07
--- /dev/null
+++ b/test/zdtm/live/transition/thread-bomb.c
@@ -0,0 +1,58 @@
+#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;
+}
-- 
1.8.3.1



More information about the CRIU mailing list