1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2002
4 * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
5 * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Verify that it's possible to open a pseudo-terminal via /dev/ptmx, obtain a
12 * slave device and configure termos/termios ioctls.
13 */
14
15 #define _GNU_SOURCE
16
17 #include <termios.h>
18 #include "common.h"
19 #include "lapi/ioctl.h"
20
21 static int masterfd = -1;
22
run(void)23 static void run(void)
24 {
25 int slavefd;
26 struct termio termio;
27 struct termios termios;
28
29 slavefd = open_slave(masterfd);
30
31 TST_EXP_PASS(ioctl(slavefd, TCGETS, &termios));
32 TST_EXP_PASS(ioctl(slavefd, TCSETS, &termios));
33 TST_EXP_PASS(ioctl(slavefd, TCSETSW, &termios));
34 TST_EXP_PASS(ioctl(slavefd, TCSETSF, &termios));
35 TST_EXP_PASS(ioctl(slavefd, TCSETS, &termios));
36 TST_EXP_PASS(ioctl(slavefd, TCGETA, &termio));
37 TST_EXP_PASS(ioctl(slavefd, TCSETA, &termio));
38 TST_EXP_PASS(ioctl(slavefd, TCSETAW, &termio));
39 TST_EXP_PASS(ioctl(slavefd, TCSETAF, &termio));
40
41 SAFE_CLOSE(slavefd);
42 }
43
setup(void)44 static void setup(void)
45 {
46 masterfd = open_master();
47 }
48
cleanup(void)49 static void cleanup(void)
50 {
51 if (masterfd != -1)
52 SAFE_CLOSE(masterfd);
53 }
54
55 static struct tst_test test = {
56 .test_all = run,
57 .setup = setup,
58 .cleanup = cleanup,
59 };
60