[CRIU] [RFC] zdtm: Add task waiters

Cyrill Gorcunov gorcunov at openvz.org
Thu May 31 11:01:27 EDT 2012


In some test cases I need to make sure the parent process has
reached some point before child to continue. This patch adds
sync points (based on Pavel's idea syncing via pipes blocking
i/o).

Take a look please.

	Cyrill
-------------- next part --------------
>From 2df43b49bc951aea4c8a70faccd824a3b084c3cc Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Thu, 31 May 2012 18:55:37 +0400
Subject: [PATCH] zdtm: Add task waiters

The task waiters are supposed to be trivial
sync primitives to be used in fork()'ed task
where children need to wait until parent has
reached some predefined program flow point.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/lib/Makefile  |    2 +-
 test/zdtm/lib/lock.c    |   45 +++++++++++++++++++++++++++++++++++++++++++++
 test/zdtm/lib/zdtmtst.h |    9 +++++++++
 3 files changed, 55 insertions(+), 1 deletions(-)
 create mode 100644 test/zdtm/lib/lock.c

diff --git a/test/zdtm/lib/Makefile b/test/zdtm/lib/Makefile
index a4ab681..f09e71f 100644
--- a/test/zdtm/lib/Makefile
+++ b/test/zdtm/lib/Makefile
@@ -2,7 +2,7 @@ CFLAGS	= -g -O2 -Wall -Werror -Wno-unused-result
 
 LIB	= libzdtmtst.a
 
-LIBSRC	= datagen.c msg.c parseargs.c test.c streamutil.c
+LIBSRC	= datagen.c msg.c parseargs.c test.c streamutil.c lock.c
 LIBOBJ	= $(LIBSRC:%.c=%.o)
 LIBDEP	= $(LIBSRC:%.c=%.d)
 
diff --git a/test/zdtm/lib/lock.c b/test/zdtm/lib/lock.c
new file mode 100644
index 0000000..04aac52
--- /dev/null
+++ b/test/zdtm/lib/lock.c
@@ -0,0 +1,45 @@
+/*
+ * Various locking primitives
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "zdtmtst.h"
+
+void task_waiter_init(task_waiter_t *t)
+{
+	if (pipe(t->pipes)) {
+		err("task_waiter_init failed: %m");
+		exit(1);
+	}
+}
+
+void task_waiter_fini(task_waiter_t *t)
+{
+	close(t->pipes[0]);
+	close(t->pipes[1]);
+}
+
+void task_waiter_wait(task_waiter_t *t)
+{
+	int v;
+	if (read(t->pipes[0], &v, sizeof(v)) !=  sizeof(v)) {
+		err("task_waiter_wait failed: %m");
+		exit(1);
+	}
+}
+
+void task_waiter_complete(task_waiter_t *t)
+{
+	int v;
+	if (write(t->pipes[1], &v, sizeof(v)) !=  sizeof(v)) {
+		err("task_waiter_complete failed: %m");
+		exit(1);
+	}
+}
diff --git a/test/zdtm/lib/zdtmtst.h b/test/zdtm/lib/zdtmtst.h
index 6ef7804..6e21676 100644
--- a/test/zdtm/lib/zdtmtst.h
+++ b/test/zdtm/lib/zdtmtst.h
@@ -89,4 +89,13 @@ extern int parse_opt_string(char *param, void *arg);
 		 __FILE__, __LINE__, ## arg)
 #define pass()	test_msg("PASS\n")
 
+typedef struct {
+	int pipes[2];
+} task_waiter_t;
+
+extern void task_waiter_init(task_waiter_t *t);
+extern void task_waiter_fini(task_waiter_t *t);
+extern void task_waiter_wait(task_waiter_t *t);
+extern void task_waiter_complete(task_waiter_t *t);
+
 #endif /* _VIMITESU_H_ */
-- 
1.7.7.6



More information about the CRIU mailing list