[CRIU] [PATCH 7/7] test: pty05 -- Add testing of multiple devpts instance

Cyrill Gorcunov gorcunov at openvz.org
Thu Jan 19 14:16:01 PST 2017


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/static/Makefile   |   1 +
 test/zdtm/static/pty05.c    | 121 ++++++++++++++++++++++++++++++++++++++++++++
 test/zdtm/static/pty05.desc |   1 +
 3 files changed, 123 insertions(+)
 create mode 100644 test/zdtm/static/pty05.c
 create mode 100644 test/zdtm/static/pty05.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index d89e3edc2266..1c3d1fb099fa 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -281,6 +281,7 @@ TST_DIR		=				\
 		mnt_enablefs			\
 		autofs				\
 		del_standalone_un		\
+		pty05				\
 
 TST_DIR_FILE	=				\
 		chroot				\
diff --git a/test/zdtm/static/pty05.c b/test/zdtm/static/pty05.c
new file mode 100644
index 000000000000..46cdba5e448d
--- /dev/null
+++ b/test/zdtm/static/pty05.c
@@ -0,0 +1,121 @@
+#define _XOPEN_SOURCE 500
+
+#include <termios.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <limits.h>
+#include <fcntl.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Test multiple PTYs with different session leaders";
+const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+static int pty_get_index(int fd)
+{
+	int index;
+
+	if (ioctl(fd, TIOCGPTN, &index)) {
+		pr_perror("Can't fetch ptmx index");
+		return -1;
+	}
+
+	return index;
+}
+
+static int open_pty_pair(char *dir, int *fdm, int *fds)
+{
+	char path[PATH_MAX];
+	int index;
+
+	snprintf(path, sizeof(path), "%s/ptmx", dir);
+	*fdm = open(path, O_RDWR);
+	if (*fdm < 0) {
+		pr_perror("Can't open %s", path);
+		return -1;
+	}
+
+	grantpt(*fdm);
+	unlockpt(*fdm);
+
+	index = pty_get_index(*fdm);
+	if (index < 0) {
+		close(*fdm);
+		return -1;
+	}
+
+	snprintf(path, sizeof(path), "%s/%d", dir, index);
+	*fds = open(path, O_RDWR);
+	if (*fds < 0) {
+		pr_perror("Can't open %s\n", path);
+		close(*fdm);
+		return -1;
+	}
+
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	char path[PATH_MAX], *dir1, *dir2;
+	int fdm1, fdm2, fds1, fds2;
+
+	test_init(argc, argv);
+
+	if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
+		pr_perror("Can't create testing directory %s", dirname);
+		exit(1);
+	}
+
+	snprintf(path, sizeof(path), "%s/%s", dirname, "lvl1");
+	dir1 = strdup(path);
+
+	if (!dir1 || mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
+		pr_perror("Can't create testing directory %s", path);
+		exit(1);
+	}
+	if (mount("devpts", path, "devpts", 0, "newinstance,ptmxmode=0666")) {
+		pr_perror("Can't mount testing directory %s", path);
+		exit(1);
+	}
+
+	snprintf(path, sizeof(path), "%s/%s", dirname, "lvl2");
+	dir2 = strdup(path);
+	if (!dir2 || mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
+		umount(dir1);
+		pr_perror("Can't create testing directory %s", path);
+		exit(1);
+	}
+	if (mount("devpts", path, "devpts", 0, "newinstance,ptmxmode=0666")) {
+		umount(dir1);
+		pr_perror("Can't mount testing directory %s", path);
+		exit(1);
+	}
+
+	if (open_pty_pair(dir1, &fdm1, &fds1) ||
+	    open_pty_pair(dir2, &fdm2, &fds2)) {
+		umount(dir1);
+		umount(dir2);
+		exit(1);
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	umount(dir1);
+	umount(dir2);
+
+	pass();
+
+	return 0;
+}
diff --git a/test/zdtm/static/pty05.desc b/test/zdtm/static/pty05.desc
new file mode 100644
index 000000000000..7657ba45c195
--- /dev/null
+++ b/test/zdtm/static/pty05.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'flags': 'suid'}
-- 
2.7.4



More information about the CRIU mailing list