[CRIU] Re: [PATCH 2/2] zdtm: Add tty05 test

Cyrill Gorcunov gorcunov at openvz.org
Wed Sep 5 06:52:54 EDT 2012


On Wed, Sep 05, 2012 at 02:50:05PM +0400, Cyrill Gorcunov wrote:
> For testing locked/exclusive ptys
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  test/zdtm/live/static/Makefile |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index ab2143e..34ce641 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -56,6 +56,7 @@ TST_NOFILE	=				\
>  		pty02				\
>  		pty03				\
>  		pty04				\
> +		pty05				\
>  		tty00				\
>  		mountpoints			\
>  		netns				\

Forgot to update git index. Sorry.

	Cyrill
-------------- next part --------------
>From 04c11079dc6a365dabdf466e6b224e4385bd967f Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Wed, 5 Sep 2012 14:42:22 +0400
Subject: [PATCH 2/2] zdtm: Add tty05 test

For testing locked/exclusive ptys

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

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index ab2143e..34ce641 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -56,6 +56,7 @@ TST_NOFILE	=				\
 		pty02				\
 		pty03				\
 		pty04				\
+		pty05				\
 		tty00				\
 		mountpoints			\
 		netns				\
diff --git a/test/zdtm/live/static/pty05.c b/test/zdtm/live/static/pty05.c
new file mode 100644
index 0000000..a2db139
--- /dev/null
+++ b/test/zdtm/live/static/pty05.c
@@ -0,0 +1,110 @@
+#define _XOPEN_SOURCE
+#include <stdlib.h>
+#define _XOPEN_SOURCE
+#include <stdlib.h>
+#include "zdtmtst.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <termios.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+
+const char *test_doc	= "Check ptys with locked/exclusive flags";
+const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+static const char teststr[] = "ping\n";
+
+static int lock_pty_master(int master)
+{
+	const int lock = 1;
+
+	if (ioctl(master, TIOCSPTLCK, &lock)) {
+		err("Unable to lock pty master device %d\n", master);
+		return 1;
+	}
+
+	return 0;
+}
+
+static int set_exclusive_pty_master(int master)
+{
+	if (ioctl(master, TIOCEXCL)) {
+		err("Unable to make pty master exclusive %d\n", master);
+		return 1;
+	}
+
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	char buf[sizeof(teststr)];
+	int master_locked;
+	int slave_locked;
+	int master_excl;
+	int ret;
+
+	char *slavename;
+
+	test_init(argc, argv);
+
+	master_locked = open("/dev/ptmx", O_RDWR);
+	master_excl = open("/dev/ptmx", O_RDWR);
+	if (master_locked == -1 || master_excl == -1) {
+		err("open(%s) failed", "/dev/ptmx");
+		return 1;
+	}
+
+	grantpt(master_locked);
+	unlockpt(master_locked);
+
+	slavename = ptsname(master_locked);
+
+	set_exclusive_pty_master(master_excl);
+
+	slave_locked = open(slavename, O_RDWR);
+	if (slave_locked == -1) {
+		err("open(%s) failed", slavename);
+		return 1;
+	}
+
+	if (ioctl(slave_locked, TIOCSCTTY, 1)) {
+		err("Can't set a controll terminal");
+		return 1;
+	}
+
+	lock_pty_master(master_locked);
+
+	test_daemon();
+	test_waitsig();
+
+	signal(SIGHUP, SIG_IGN);
+
+	ret = write(master_locked, teststr, sizeof(teststr) - 1);
+	if (ret != sizeof(teststr) - 1) {
+		err("write(master_locked) failed");
+		return 1;
+	}
+
+	ret = read(slave_locked, buf, sizeof(teststr) - 1);
+	if (ret != sizeof(teststr) - 1) {
+		err("read(slave_locked) failed");
+		return 1;
+	}
+
+	if (strncmp(teststr, buf, sizeof(teststr) - 1)) {
+		fail("data mismatch");
+		return 1;
+	}
+
+	close(master_locked);
+	close(slave_locked);
+	close(master_excl);
+
+	pass();
+
+	return 0;
+}
-- 
1.7.7.6



More information about the CRIU mailing list