[LTP] [PATCH v3 04/12] Add ptem02 test

Andrea Cervesato
2025-01-09T14:13:02Z

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 | 71 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 73 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..0fc69aa1d8d487fba9c6022d77254660b678c6e0
--- /dev/null
+++ b/testcases/kernel/pty/ptem02.c
@@ -0,0 +1,71 @@
+// 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 "common.h"
+
+static int masterfd = -1;
+
+static void run(void)
+{
+ int slavefd;
+ struct winsize wsz;
+ struct winsize wsz1 = { 24, 80, 5, 10 };
+ struct winsize wsz2 = { 60, 100, 11, 777 };
+
+ slavefd = open_slave(masterfd);
+
+ TST_EXP_PASS(ioctl(masterfd, TIOCSWINSZ, &wsz1));
+ TST_EXP_PASS(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_PASS(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_PASS(ioctl(slavefd, TIOCSWINSZ, &wsz2));
+ TST_EXP_PASS(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);
+}
+
+static void setup(void)
+{
+ masterfd = open_master();
+}
+
+static void cleanup(void)
+{
+ if (masterfd != -1)