[LTP] [PATCH v4 07/12] Add ptem05 test

Andrea Cervesato andrea.cervesato@suse.de
Thu Jan 16 12:36:06 CET 2025


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

Verify that it's possible to open a pseudo-terminal via /dev/ptmx, to
obtain a master + slave pair and to open them multiple times.

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

diff --git a/runtest/pty b/runtest/pty
index 63d927eca07aa3dbd312d5c5cc6b6681dbf3627d..deb04c3f5725647a32f457eaed638eb7071ab4db 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -10,5 +10,6 @@ ptem01 ptem01
 ptem02 ptem02
 ptem03 ptem03
 ptem04 ptem04
+ptem05 ptem05
 hangup01 hangup01
 
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index c9bb33664f9de55038f4638406841f403f1a86c4..ef5751907cad087f5e33132b52a374b52ee7905a 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -3,6 +3,7 @@
 /ptem02
 /ptem03
 /ptem04
+/ptem05
 /pty01
 /pty02
 /pty03
diff --git a/testcases/kernel/pty/ptem05.c b/testcases/kernel/pty/ptem05.c
new file mode 100644
index 0000000000000000000000000000000000000000..9357c469ca8c35117a50e60b19bfbf830b1345cf
--- /dev/null
+++ b/testcases/kernel/pty/ptem05.c
@@ -0,0 +1,55 @@
+// 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, to obtain
+ * a master + slave pair and to open them multiple times.
+ */
+
+#define _GNU_SOURCE
+
+#include "common.h"
+
+#define NUM_OPENS 10
+
+static int masterfd[NUM_OPENS];
+
+static void run(void)
+{
+	int slavefd[NUM_OPENS];
+
+	for (int i = 0; i < NUM_OPENS; i++)
+		slavefd[i] = TST_EXP_FD(open_slave(masterfd[i]));
+
+	for (int i = 0; i < NUM_OPENS; i++)
+		SAFE_CLOSE(slavefd[i]);
+}
+
+static void setup(void)
+{
+	for (int i = 0; i < NUM_OPENS; i++)
+		masterfd[i] = -1;
+
+	for (int i = 0; i < NUM_OPENS; i++)
+		masterfd[i] = open_master();
+}
+
+static void cleanup(void)
+{
+	for (int i = 0; i < NUM_OPENS; i++) {
+		if (masterfd[i] != -1)
+			SAFE_CLOSE(masterfd[i]);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};

-- 
2.43.0



More information about the ltp mailing list