[LTP] [PATCH v3 06/12] Add ptem04 test

Andrea Cervesato
2025-01-09T14:12:12Z

Verify that it's possible to open a pseudo-terminal via /dev/ptmx,
obtain a slave device and to check if it's possible to open it
multiple times.

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

diff --git a/runtest/pty b/runtest/pty
index 329cc84cdc107ab8e814fea72a8088ea62d5ad25..63d927eca07aa3dbd312d5c5cc6b6681dbf3627d 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -9,5 +9,6 @@ pty07 pty07
ptem01 ptem01
ptem02 ptem02
ptem03 ptem03
+ptem04 ptem04
hangup01 hangup01

diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index 61fec1ddae3ea39d20e97123e34888708050c25c..c9bb33664f9de55038f4638406841f403f1a86c4 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -2,6 +2,7 @@
/ptem01
/ptem02
/ptem03
+/ptem04
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem04.c b/testcases/kernel/pty/ptem04.c
new file mode 100644
index 0000000000000000000000000000000000000000..675e6b816dc916e48508af19c1b9f45784accff7
--- /dev/null
+++ b/testcases/kernel/pty/ptem04.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 check if it's possible to open it multiple times.
+ */
+
+#define _GNU_SOURCE
+
+#include "common.h"
+
+#define NUM_SLAVES 10
+
+static int masterfd = -1;
+
+static void run(void)
+{
+ int slavefd[NUM_SLAVES];
+
+ for (int i = 0; i < NUM_SLAVES; i++)
+ slavefd[i] = TST_EXP_FD(open_slave(masterfd));
+
+ for (int i = 0; i < NUM_SLAVES; i++)
+ SAFE_CLOSE(slavefd[i]);
+}
+
+static void setup(void)
+{
+ masterfd = open_master();
+}
+
+static void cleanup(void)
+{
+ if (masterfd != -1)