[CRIU] [PATCH 3/3] zdtm: Add futex-rl test

Cyrill Gorcunov gorcunov at openvz.org
Fri Aug 10 05:21:19 EDT 2012


To test futex robust list C/R.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm.sh                     |    1 +
 test/zdtm/live/static/Makefile   |    3 +
 test/zdtm/live/static/futex-rl.c |  107 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 0 deletions(-)
 create mode 100644 test/zdtm/live/static/futex-rl.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 57902fd..10f00f8 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -21,6 +21,7 @@ static/vdso00
 static/file_shared
 static/timers
 static/futex
+static/futex-rl
 static/xids00
 streaming/pipe_loop00
 streaming/pipe_shared00
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index b9ba4c9..70372a0 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -12,6 +12,7 @@ TST_NOFILE	=				\
 		zombie00			\
 		fpu00				\
 		futex				\
+		futex-rl			\
 		mmx00				\
 		sse00				\
 		sse20				\
@@ -169,6 +170,8 @@ $(TST):	$(LIB)
 
 futex.o:		override CFLAGS += -pthread
 futex:			override LDFLAGS += -pthread
+futex-rl.o:		override CFLAGS += -pthread
+futex-rl:		override LDFLAGS += -pthread
 jobctl00:		override LDLIBS += -lutil
 socket_listen:		override LDLIBS += -lrt
 socket_aio:		override LDLIBS += -lrt
diff --git a/test/zdtm/live/static/futex-rl.c b/test/zdtm/live/static/futex-rl.c
new file mode 100644
index 0000000..4f0f362
--- /dev/null
+++ b/test/zdtm/live/static/futex-rl.c
@@ -0,0 +1,107 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+
+#include <sys/mman.h>
+#include <sys/syscall.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check the futex robust list c/r";
+const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+struct args {
+	task_waiter_t	waiter;
+	int		result;
+};
+
+static pid_t __gettid(void)
+{
+	return syscall(__NR_gettid);
+}
+
+void *thread_fn(void *arg)
+{
+	struct robust_list_head *head_orig = NULL, *head_new = NULL;
+	size_t len_orig = 0, len_new = 0;
+	struct args *args = arg;
+
+	test_msg("Obtaining old RL\n");
+	if (syscall(__NR_get_robust_list, __gettid(), &head_orig, &len_orig)) {
+		args->result = -1;
+		fail("__NR_get_robust_list failed");
+	}
+
+	test_msg("Complete\n");
+	task_waiter_complete(&args->waiter, 1);
+	if (args->result == -1)
+		goto out;
+
+	task_waiter_wait4(&args->waiter, 2);
+
+	test_msg("Obtaining new RL\n");
+	if (syscall(__NR_get_robust_list, __gettid(), &head_new, &len_new)) {
+		args->result = -1;
+		fail("__NR_get_robust_list failed");
+	}
+	if (args->result == -1)
+		goto out;
+
+	if (head_orig != head_new || len_orig != len_new) {
+		args->result = -1;
+		fail("comparision failed");
+	}
+
+	args->result = 0;
+out:
+	return NULL;
+}
+
+int main(int argc, char **argv)
+{
+	pthread_t thread;
+	struct args *args;
+
+	test_init(argc, argv);
+
+	args = (struct args *)mmap(NULL, sizeof(*args), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+	if ((void *)args == MAP_FAILED) {
+		fail("mmap failed\n");
+		exit(1);
+	}
+
+	task_waiter_init(&args->waiter);
+	args->result = 0;
+
+	test_msg("Createing thread\n");
+	if (pthread_create(&thread, NULL, thread_fn, (void *)args)) {
+		fail("Can't create thread\n");
+		exit(1);
+	}
+
+	test_msg("Wait for thread work\n");
+	task_waiter_wait4(&args->waiter, 1);
+	if (args->result == -1) {
+		fail("thread failed\n");
+		exit(1);
+	}
+
+	test_msg("C/R cycle\n");
+	test_daemon();
+	test_waitsig();
+
+	task_waiter_complete(&args->waiter, 2);
+
+	pthread_join(thread, NULL);
+	if (args->result)
+		fail();
+	else
+		pass();
+
+	munmap((void *)args, sizeof(*args));
+
+	return 0;
+}
-- 
1.7.7.6



More information about the CRIU mailing list