[LTP] [PATCH 09/10] Add pty08 test

Andrea Cervesato andrea.cervesato@suse.de
Wed Dec 11 13:20:32 CET 2024


From: Andrea Cervesato <andrea.cervesato@suse.com>

Verify that slave pseudo-terminal fails reading/writing if master has
been closed.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/pty                     |  1 +
 testcases/kernel/pty/.gitignore |  1 +
 testcases/kernel/pty/pty08.c    | 60 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/runtest/pty b/runtest/pty
index 6343da391ba17627abaf09aa5a23509e4f745556..365a46ee9730aa36b22dbbdbfba82ac0d491ac94 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -6,6 +6,7 @@ pty04 pty04
 pty05 pty05
 pty06 pty06
 pty07 pty07
+pty08 pty08
 ptem01 ptem01
 ptem02 ptem02
 ptem03 ptem03
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index 630d7fcf7b0e0adfbc21b793fa456d6c5f5e4ad9..7d8d4dceda84f2e2695a8bee39abfe894288b8b6 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -12,3 +12,4 @@
 /pty05
 /pty06
 /pty07
+/pty08
diff --git a/testcases/kernel/pty/pty08.c b/testcases/kernel/pty/pty08.c
new file mode 100644
index 0000000000000000000000000000000000000000..1e3eb191b2e2a88258319da90e29ed582cdfa7b7
--- /dev/null
+++ b/testcases/kernel/pty/pty08.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines  Corp., 2002
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that slave pseudo-terminal fails reading/writing if master has been
+ * closed.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+
+static void run(void)
+{
+	int masterfd, slavefd;
+	char *slavename;
+	char buf;
+
+	masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+
+	slavename = ptsname(masterfd);
+	if (slavename == NULL)
+		tst_brk(TBROK | TERRNO, "ptsname() error");
+
+	tst_res(TINFO, "pts device location is %s", slavename);
+
+	if (grantpt(masterfd) == -1)
+		tst_brk(TBROK | TERRNO, "grantpt() error");
+
+	if (unlockpt(masterfd) == -1)
+		tst_brk(TBROK | TERRNO, "unlockpt() error");
+
+	slavefd = SAFE_OPEN(slavename, O_RDWR);
+
+	tst_res(TINFO, "Closing master communication");
+	SAFE_CLOSE(masterfd);
+
+	TST_EXP_FAIL(read(slavefd, &buf, 1), EIO);
+	TST_EXP_FAIL(write(slavefd, &buf, 1), EIO);
+
+	SAFE_CLOSE(slavefd);
+}
+
+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