[CRIU] [PATCH 4/4] zdtm: Add pty02 test
Cyrill Gorcunov
gorcunov at openvz.org
Mon Aug 13 03:59:34 EDT 2012
The test is tricky -- it opens master in task 1
and dup it in task 2, then close in task 1 and
do C/R.
Thus we need to setup SID of master terminal
somehow in children, which usually fails in
currnt tty restore implementation.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/pty02.c | 102 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 0 deletions(-)
create mode 100644 test/zdtm/live/static/pty02.c
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index b7ad970..8c3bc60 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -53,6 +53,7 @@ TST_NOFILE = \
session00 \
pty00 \
pty01 \
+ pty02 \
tty00 \
mountpoints \
netns \
diff --git a/test/zdtm/live/static/pty02.c b/test/zdtm/live/static/pty02.c
new file mode 100644
index 0000000..a9317d3
--- /dev/null
+++ b/test/zdtm/live/static/pty02.c
@@ -0,0 +1,102 @@
+#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>
+
+const char *test_doc = "Check forked master ptmx";
+const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+static const char teststr[] = "ping\n";
+
+#define exit_shot(pid, code) \
+ do { kill(pid, SIGKILL); exit(code); } while (0)
+
+#define exit_shot_parent(code) \
+ exit_shot(getppid(), 1)
+
+int main(int argc, char *argv[])
+{
+ char buf[sizeof(teststr)];
+ int master, slave, ret;
+ char *slavename;
+ task_waiter_t t;
+ pid_t pid;
+
+ test_init(argc, argv);
+
+ master = open("/dev/ptmx", O_RDWR);
+ if (master == -1) {
+ err("open(%s) failed", "/dev/ptmx");
+ return 1;
+ }
+
+ grantpt(master);
+ unlockpt(master);
+
+ slavename = ptsname(master);
+ slave = open(slavename, O_RDWR);
+ if (slave == -1) {
+ err("open(%s) failed", slavename);
+ return 1;
+ }
+
+ task_waiter_init(&t);
+
+ pid = test_fork();
+ if (pid == 0) {
+ int new_master, ret;
+
+ new_master = dup(master);
+ if (new_master < 0) {
+ err("can't dup master\n");
+ exit_shot_parent(1);
+ }
+
+ task_waiter_complete_current(&t);
+
+ ret = write(new_master, teststr, sizeof(teststr) - 1);
+ if (ret != sizeof(teststr) - 1) {
+ err("write(new_master) failed");
+ exit_shot_parent(1);
+ }
+
+ task_waiter_wait4(&t, 1);
+
+ close(new_master);
+ exit(0);
+ } else if (pid < 0) {
+ err("test_fork failed: %m\n");
+ exit(1);
+ }
+
+ task_waiter_wait4(&t, pid);
+ close(master);
+
+ test_daemon();
+ test_waitsig();
+
+ task_waiter_complete(&t, 1);
+
+ ret = read(slave, buf, sizeof(teststr) - 1);
+ if (ret != sizeof(teststr) - 1) {
+ err("read(slave) failed");
+ return 1;
+ }
+
+ if (strncmp(teststr, buf, sizeof(teststr) - 1)) {
+ fail("data mismatch");
+ return 1;
+ }
+
+ close(slave);
+
+ pass();
+
+ return 0;
+}
--
1.7.7.6
More information about the CRIU
mailing list