From 1a41fcfc212abaf98fb42d1915449ac396c4e4d0 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Wed, 12 Sep 2012 20:02:32 +0400 Subject: [PATCH] zdtm: Add pty01 test Two slaves on same pty. Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- test/zdtm/live/static/Makefile | 1 + test/zdtm/live/static/pty01.c | 93 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/zdtm/live/static/pty01.c diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile index 74b7b56bd..d46482185 100644 --- a/test/zdtm/live/static/Makefile +++ b/test/zdtm/live/static/Makefile @@ -52,6 +52,7 @@ TST_NOFILE = \ uptime_grow \ session00 \ pty00 \ + pty01 \ tty00 \ mountpoints \ netns \ diff --git a/test/zdtm/live/static/pty01.c b/test/zdtm/live/static/pty01.c new file mode 100644 index 000000000..a6b58bacc --- /dev/null +++ b/test/zdtm/live/static/pty01.c @@ -0,0 +1,93 @@ +#define _XOPEN_SOURCE +#include +#include "zdtmtst.h" +#include +#include +#include +#include +#include +#include +#include + +const char *test_doc = "Check two pts on ptmx"; +const char *test_author = "Cyrill Gorcunov "; + +static const char teststr[] = "ping\n"; + +int main(int argc, char *argv[]) +{ + char buf[sizeof(teststr)]; + int master, slave1, slave2, ret; + char *slavename; + + 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); + slave1 = open(slavename, O_RDWR); + if (slave1 == -1) { + err("open(%s) failed", slavename); + return 1; + } + + slave2 = open(slavename, O_RDWR); + if (slave2 == -1) { + err("open(%s) failed", slavename); + return 1; + } + + test_daemon(); + test_waitsig(); + + signal(SIGHUP, SIG_IGN); + + ret = write(master, teststr, sizeof(teststr) - 1); + if (ret != sizeof(teststr) - 1) { + err("write(master) failed"); + return 1; + } + + ret = read(slave1, buf, sizeof(teststr) - 1); + if (ret != sizeof(teststr) - 1) { + err("read(slave1) failed"); + return 1; + } + + if (strncmp(teststr, buf, sizeof(teststr) - 1)) { + fail("data mismatch"); + return 1; + } + + ret = write(master, teststr, sizeof(teststr) - 1); + if (ret != sizeof(teststr) - 1) { + err("write(master) failed"); + return 1; + } + + ret = read(slave2, buf, sizeof(teststr) - 1); + if (ret != sizeof(teststr) - 1) { + err("read(slave1) failed"); + return 1; + } + + if (strncmp(teststr, buf, sizeof(teststr) - 1)) { + fail("data mismatch"); + return 1; + } + + close(master); + close(slave1); + close(slave2); + + pass(); + + return 0; +}