[LTP] [PATCH v3 05/12] Add ptem03 test

Andrea Cervesato
2025-01-09T14:14:28Z

Verify that it's possible to open a pseudo-terminal via /dev/ptmx,
obtain a slave device and to send a break to both master and slave.

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

diff --git a/runtest/pty b/runtest/pty
index 3ce7160e2776e58973def5893fc269ed035376c0..329cc84cdc107ab8e814fea72a8088ea62d5ad25 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -8,5 +8,6 @@ pty06 pty06
pty07 pty07
ptem01 ptem01
ptem02 ptem02
+ptem03 ptem03
hangup01 hangup01

diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index e638413a127fad65ed2f58c24dc1ae718219e518..61fec1ddae3ea39d20e97123e34888708050c25c 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -1,6 +1,7 @@
/hangup01
/ptem01
/ptem02
+/ptem03
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem03.c b/testcases/kernel/pty/ptem03.c
new file mode 100644
index 0000000000000000000000000000000000000000..fb0fdf6612d94a35728bed773fd7dd363922f454
--- /dev/null
+++ b/testcases/kernel/pty/ptem03.c
@@ -0,0 +1,49 @@
+// 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 to send a break to both master and slave.
+ */
+
+#define _GNU_SOURCE
+
+#include <termios.h>
+#include "common.h"
+
+static int masterfd = -1;
+
+static void run(void)
+{
+ int slavefd;
+
+ slavefd = open_slave(masterfd);
+
+ TST_EXP_PASS(tcsendbreak(masterfd, 10));
+ TST_EXP_PASS(tcsendbreak(slavefd, 10));
+
+ SAFE_CLOSE(slavefd);
+}
+
+static void setup(void)
+{
+ masterfd = open_master();
+}
+
+static void cleanup(void)
+{
+ if (masterfd != -1)