[LTP] [PATCH 03/10] Add ptem02 test
Andrea Cervesato
andrea.cervesato@suse.de
Wed Dec 11 13:20:26 CET 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that it's possible to open a pseudo-terminal via /dev/ptmx,
obtain a slave device and set/get window size.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/ptem02.c | 78 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 80 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index df2074153c2ac01038a0ef0ce5ad8938960ae53d..3ce7160e2776e58973def5893fc269ed035376c0 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -7,5 +7,6 @@ pty05 pty05
pty06 pty06
pty07 pty07
ptem01 ptem01
+ptem02 ptem02
hangup01 hangup01
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index acca3db9a1786f243b31f1fc4a8833d6ed8751a6..e638413a127fad65ed2f58c24dc1ae718219e518 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -1,5 +1,6 @@
/hangup01
/ptem01
+/ptem02
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem02.c b/testcases/kernel/pty/ptem02.c
new file mode 100644
index 0000000000000000000000000000000000000000..78ed40d2ca9cb4d1d9a1f3879f1fdcf9198ee493
--- /dev/null
+++ b/testcases/kernel/pty/ptem02.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that it's possible to open a pseudo-terminal via /dev/ptmx, obtain a
+ * slave device and set/get window size.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+
+static void run(void)
+{
+ int masterfd, slavefd;
+ char *slavename;
+ struct winsize wsz;
+ struct winsize wsz1 = { 24, 80, 5, 10 };
+ struct winsize wsz2 = { 60, 100, 11, 777 };
+
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+
+ slavename = ptsname(masterfd);
+ if (slavename == NULL)
+ tst_res(TFAIL, "Can't get slave device location");
+ else
+ tst_res(TPASS, "pts device location is %s", slavename);
+
+ TST_EXP_PASS(grantpt(masterfd));
+ TST_EXP_PASS(unlockpt(masterfd));
+
+ slavefd = SAFE_OPEN(slavename, O_RDWR);
+
+ TST_EXP_POSITIVE(ioctl(masterfd, TIOCSWINSZ, &wsz1));
+ TST_EXP_POSITIVE(ioctl(slavefd, TIOCGWINSZ, &wsz));
+
+ TST_EXP_EQ_LI(wsz.ws_row, wsz1.ws_row);
+ TST_EXP_EQ_LI(wsz.ws_col, wsz1.ws_col);
+ TST_EXP_EQ_LI(wsz.ws_xpixel, wsz1.ws_xpixel);
+ TST_EXP_EQ_LI(wsz.ws_ypixel, wsz1.ws_ypixel);
+
+ TST_EXP_POSITIVE(ioctl(masterfd, TIOCGWINSZ, &wsz));
+
+ TST_EXP_EQ_LI(wsz.ws_row, wsz1.ws_row);
+ TST_EXP_EQ_LI(wsz.ws_col, wsz1.ws_col);
+ TST_EXP_EQ_LI(wsz.ws_xpixel, wsz1.ws_xpixel);
+ TST_EXP_EQ_LI(wsz.ws_ypixel, wsz1.ws_ypixel);
+
+ TST_EXP_POSITIVE(ioctl(slavefd, TIOCSWINSZ, &wsz2));
+ TST_EXP_POSITIVE(ioctl(slavefd, TIOCGWINSZ, &wsz));
+
+ TST_EXP_EQ_LI(wsz.ws_row, wsz2.ws_row);
+ TST_EXP_EQ_LI(wsz.ws_col, wsz2.ws_col);
+ TST_EXP_EQ_LI(wsz.ws_xpixel, wsz2.ws_xpixel);
+ TST_EXP_EQ_LI(wsz.ws_ypixel, wsz2.ws_ypixel);
+
+ SAFE_CLOSE(slavefd);
+ SAFE_CLOSE(masterfd);
+}
+
+static void setup(void)
+{
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
More information about the ltp
mailing list