From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 09/10] Add pty08 test
Date: Wed, 11 Dec 2024 13:20:32 +0100 [thread overview]
Message-ID: <20241211-fix_setsid_tests-v1-9-e103f36c6462@suse.com> (raw)
In-Reply-To: <20241211-fix_setsid_tests-v1-0-e103f36c6462@suse.com>
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-12-11 12:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 12:20 [LTP] [PATCH 00/10] Fix tests failing with setsid Andrea Cervesato
2024-12-11 12:20 ` [LTP] [PATCH 01/10] Refactor setpgid01 test Andrea Cervesato
2024-12-16 21:04 ` Petr Vorel
2024-12-11 12:20 ` [LTP] [PATCH 02/10] Refactor ptem01 test Andrea Cervesato
2024-12-16 21:22 ` Petr Vorel
2024-12-11 12:20 ` [LTP] [PATCH 03/10] Add ptem02 test Andrea Cervesato
2024-12-11 12:20 ` [LTP] [PATCH 04/10] Add ptem03 test Andrea Cervesato
2024-12-11 12:20 ` [LTP] [PATCH 05/10] Add ptem04 test Andrea Cervesato
2024-12-11 12:20 ` [LTP] [PATCH 06/10] Add ptem05 test Andrea Cervesato
2024-12-11 12:20 ` [LTP] [PATCH 07/10] Add ptem06 test Andrea Cervesato
2024-12-11 12:20 ` [LTP] [PATCH 08/10] Refactor pty01 test Andrea Cervesato
2024-12-11 12:20 ` Andrea Cervesato [this message]
2024-12-11 12:20 ` [LTP] [PATCH 10/10] Add pty09 test Andrea Cervesato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241211-fix_setsid_tests-v1-9-e103f36c6462@suse.com \
--to=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox