• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 to check if it's possible to open it multiple times.
13  */
14 
15 #define _GNU_SOURCE
16 
17 #include "common.h"
18 
19 #define NUM_SLAVES 10
20 
21 static int masterfd = -1;
22 
run(void)23 static void run(void)
24 {
25 	int slavefd[NUM_SLAVES];
26 
27 	for (int i = 0; i < NUM_SLAVES; i++)
28 		slavefd[i] = TST_EXP_FD(open_slave(masterfd));
29 
30 	for (int i = 0; i < NUM_SLAVES; i++)
31 		SAFE_CLOSE(slavefd[i]);
32 }
33 
setup(void)34 static void setup(void)
35 {
36 	masterfd = open_master();
37 }
38 
cleanup(void)39 static void cleanup(void)
40 {
41 	if (masterfd != -1)
42 		SAFE_CLOSE(masterfd);
43 }
44 
45 static struct tst_test test = {
46 	.test_all = run,
47 	.setup = setup,
48 	.cleanup = cleanup,
49 };
50