[LTP] [PATCH v3 11/12] Add pty08 test

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

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 | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 40 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..45e99d18ba898ce24b4151f79554b5f49a9b7586
--- /dev/null
+++ b/testcases/kernel/pty/pty08.c
@@ -0,0 +1,38 @@
+// 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 "common.h"
+
+static void run(void)
+{
+ int slavefd;
+ int masterfd;
+ char buf;
+
+ masterfd = open_master();
+ slavefd = open_slave(masterfd);
+
+ tst_res(TINFO, "Closing master communication");
+ SAFE_CLOSE(masterfd);
+
+ TST_EXP_EQ_LI(read(slavefd, &buf, 1), 0);
+ TST_EXP_FAIL(write(slavefd, &buf, 1), EIO);
+
+ SAFE_CLOSE(slavefd);