[LTP] [PATCH v3 08/12] Add ptem06 test
Andrea Cervesato
andrea.cervesato@suse.de
Thu Jan 9 15:11:11 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 slave device and to set baudrate to B0 (which means hang
up).
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/ptem06.c | 52 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index deb04c3f5725647a32f457eaed638eb7071ab4db..6343da391ba17627abaf09aa5a23509e4f745556 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -11,5 +11,6 @@ ptem02 ptem02
ptem03 ptem03
ptem04 ptem04
ptem05 ptem05
+ptem06 ptem06
hangup01 hangup01
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index ef5751907cad087f5e33132b52a374b52ee7905a..630d7fcf7b0e0adfbc21b793fa456d6c5f5e4ad9 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -4,6 +4,7 @@
/ptem03
/ptem04
/ptem05
+/ptem06
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem06.c b/testcases/kernel/pty/ptem06.c
new file mode 100644
index 0000000000000000000000000000000000000000..810b7c1d6a774290baf24c12cedccb85242367c4
--- /dev/null
+++ b/testcases/kernel/pty/ptem06.c
@@ -0,0 +1,52 @@
+// 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 slave device and to set baudrate to B0 (which means hang up).
+ */
+
+#define _GNU_SOURCE
+
+#include <termios.h>
+#include "common.h"
+
+static int masterfd = -1;
+
+static void run(void)
+{
+ int slavefd;
+ struct termios termios;
+
+ slavefd = open_slave(masterfd);
+
+ TST_EXP_PASS(ioctl(slavefd, TCGETS, &termios));
+ termios.c_cflag &= ~CBAUD;
+ termios.c_cflag |= B0 & CBAUD;
+ TST_EXP_PASS(ioctl(slavefd, TCSETS, &termios));
+
+ SAFE_CLOSE(slavefd);
+}
+
+static void setup(void)
+{
+ masterfd = open_master();
+}
+
+static void cleanup(void)
+{
+ if (masterfd != -1)
+ SAFE_CLOSE(masterfd);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+};
--
2.43.0
More information about the ltp
mailing list