blob: 8522fe44909f3f63db61db6e90eccbf351486e41 [file] [log] [blame]
robbiewb8739092002-12-24 19:55:40 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2002
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiewb8739092002-12-24 19:55:40 +000018 */
19
20/* 12/23/2002 Port to LTP robbiew@us.ibm.com */
21/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
22
23#include <errno.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <stdio.h>
27#include <termio.h>
28#include <sys/fcntl.h>
29#include <sys/stat.h>
30#include <sys/poll.h>
robbiewb8739092002-12-24 19:55:40 +000031#include <sys/types.h>
32
33#ifndef _GNU_SOURCE
34#define _GNU_SOURCE 1
35#endif
36
37/** LTP Port **/
38#include "test.h"
robbiewb8739092002-12-24 19:55:40 +000039
Wanlong Gao354ebb42012-12-07 10:10:04 +080040char *TCID = "ptem01"; /* Test program identifier. */
41int TST_TOTAL = 6; /* Total number of test cases. */
robbiewb8739092002-12-24 19:55:40 +000042/**************/
43
robbiewb8739092002-12-24 19:55:40 +000044/*
45 * pty master clone device
46 */
47#define MASTERCLONE "/dev/ptmx"
48
49#define BUFSZ 4096
50
robbiewb8739092002-12-24 19:55:40 +000051/*
52 * test termio/termios ioctls
53 */
Wanlong Gao354ebb42012-12-07 10:10:04 +080054int test1(void)
robbiewb8739092002-12-24 19:55:40 +000055{
56 int masterfd, slavefd;
57 char *slavename;
58 struct termio termio;
59 struct termios termios;
60
61 masterfd = open(MASTERCLONE, O_RDWR);
62 if (masterfd < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010063 tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
robbiewb8739092002-12-24 19:55:40 +000064 }
subrata_modakbdbaec52009-02-26 12:14:51 +000065
robbiewb8739092002-12-24 19:55:40 +000066 slavename = ptsname(masterfd);
Garrett Cooper0c74e7d2010-10-18 22:45:43 -070067 if (slavename == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010068 tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
robbiewb8739092002-12-24 19:55:40 +000069 }
70
71 if (grantpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010072 tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
robbiewb8739092002-12-24 19:55:40 +000073 }
74
75 if (unlockpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010076 tst_brkm(TBROK, NULL, "unlockpt() call failed");
robbiewb8739092002-12-24 19:55:40 +000077 }
78
79 if ((slavefd = open(slavename, O_RDWR)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010080 tst_brkm(TFAIL, NULL, "Could not open %s", slavename);
robbiewb8739092002-12-24 19:55:40 +000081 }
82
83 if (ioctl(slavefd, TCGETS, &termios) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010084 tst_brkm(TFAIL, NULL, "TCGETS");
robbiewb8739092002-12-24 19:55:40 +000085 }
86
87 if (ioctl(slavefd, TCSETS, &termios) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010088 tst_brkm(TFAIL, NULL, "TCSETS");
robbiewb8739092002-12-24 19:55:40 +000089 }
90
91 if (ioctl(slavefd, TCSETSW, &termios) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010092 tst_brkm(TFAIL, NULL, "TCSETSW");
robbiewb8739092002-12-24 19:55:40 +000093 }
94
95 if (ioctl(slavefd, TCSETSF, &termios) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010096 tst_brkm(TFAIL, NULL, "TCSETSF");
robbiewb8739092002-12-24 19:55:40 +000097 }
98
99 if (ioctl(slavefd, TCSETS, &termios) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100100 tst_brkm(TFAIL, NULL, "TCSETS");
robbiewb8739092002-12-24 19:55:40 +0000101 }
102
103 if (ioctl(slavefd, TCGETA, &termio) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100104 tst_brkm(TFAIL, NULL, "TCGETA");
robbiewb8739092002-12-24 19:55:40 +0000105 }
106
107 if (ioctl(slavefd, TCSETA, &termio) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100108 tst_brkm(TFAIL, NULL, "TCSETA");
robbiewb8739092002-12-24 19:55:40 +0000109 }
110
111 if (ioctl(slavefd, TCSETAW, &termio) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100112 tst_brkm(TFAIL, NULL, "TCSETAW");
robbiewb8739092002-12-24 19:55:40 +0000113 }
114
115 if (ioctl(slavefd, TCSETAF, &termio) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100116 tst_brkm(TFAIL, NULL, "TCSETAF");
robbiewb8739092002-12-24 19:55:40 +0000117 }
118
119 if (close(slavefd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100120 tst_brkm(TBROK, NULL, "close slave");
robbiewb8739092002-12-24 19:55:40 +0000121 }
122
123 if (close(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100124 tst_brkm(TBROK, NULL, "close master");
robbiewb8739092002-12-24 19:55:40 +0000125 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800126 tst_resm(TPASS, "test1");
robbiewb8739092002-12-24 19:55:40 +0000127
128 /** NOT REACHED **/
subrata_modakbdbaec52009-02-26 12:14:51 +0000129 return 0;
robbiewb8739092002-12-24 19:55:40 +0000130}
131
132/*
133 * test window size setting and getting
134 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800135int test2(void)
robbiewb8739092002-12-24 19:55:40 +0000136{
137 int masterfd, slavefd;
138 char *slavename;
139 struct winsize wsz;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800140 struct winsize wsz1 = { 24, 80, 5, 10 };
141 struct winsize wsz2 = { 60, 100, 11, 777 };
robbiewb8739092002-12-24 19:55:40 +0000142
143 masterfd = open(MASTERCLONE, O_RDWR);
144 if (masterfd < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100145 tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
robbiewb8739092002-12-24 19:55:40 +0000146 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000147
robbiewb8739092002-12-24 19:55:40 +0000148 slavename = ptsname(masterfd);
Garrett Cooper0c74e7d2010-10-18 22:45:43 -0700149 if (slavename == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100150 tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
robbiewb8739092002-12-24 19:55:40 +0000151 }
152
153 if (grantpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100154 tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000155 }
156
157 if (unlockpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100158 tst_brkm(TBROK, NULL, "unlockpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000159 }
160
161 if ((slavefd = open(slavename, O_RDWR)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100162 tst_brkm(TBROK, NULL, "Could not open %s", slavename);
robbiewb8739092002-12-24 19:55:40 +0000163 }
164
robbiewb8739092002-12-24 19:55:40 +0000165 if (ioctl(masterfd, TIOCSWINSZ, &wsz1) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100166 tst_brkm(TFAIL, NULL, "TIOCSWINSZ");
robbiewb8739092002-12-24 19:55:40 +0000167 }
168
169 if (ioctl(slavefd, TIOCGWINSZ, &wsz) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100170 tst_brkm(TFAIL, NULL, "TIOCGWINSZ");
robbiewb8739092002-12-24 19:55:40 +0000171 }
172
173 if (wsz.ws_row != wsz1.ws_row || wsz.ws_col != wsz1.ws_col ||
174 wsz.ws_xpixel != wsz1.ws_xpixel ||
175 wsz.ws_ypixel != wsz1.ws_ypixel) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100176 tst_brkm(TFAIL, NULL, "unexpected window size returned");
robbiewb8739092002-12-24 19:55:40 +0000177 }
178
179 if (ioctl(masterfd, TIOCGWINSZ, &wsz) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100180 tst_brkm(TFAIL, NULL, "TIOCGWINSZ");
robbiewb8739092002-12-24 19:55:40 +0000181 }
182
183 if (wsz.ws_row != wsz1.ws_row || wsz.ws_col != wsz1.ws_col ||
184 wsz.ws_xpixel != wsz1.ws_xpixel ||
185 wsz.ws_ypixel != wsz1.ws_ypixel) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100186 tst_brkm(TFAIL, NULL, "unexpected window size returned");
robbiewb8739092002-12-24 19:55:40 +0000187 }
188
189 if (ioctl(slavefd, TIOCSWINSZ, &wsz2) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100190 tst_brkm(TFAIL, NULL, "TIOCSWINSZ");
robbiewb8739092002-12-24 19:55:40 +0000191 }
192
193 if (ioctl(slavefd, TIOCGWINSZ, &wsz) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100194 tst_brkm(TFAIL, NULL, "TIOCGWINSZ");
robbiewb8739092002-12-24 19:55:40 +0000195 }
196
197 if (wsz.ws_row != wsz2.ws_row || wsz.ws_col != wsz2.ws_col ||
198 wsz.ws_xpixel != wsz2.ws_xpixel ||
199 wsz.ws_ypixel != wsz2.ws_ypixel) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100200 tst_brkm(TFAIL, NULL, "unexpected window size returned");
robbiewb8739092002-12-24 19:55:40 +0000201 }
202
robbiewb8739092002-12-24 19:55:40 +0000203 if (close(slavefd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100204 tst_brkm(TBROK, NULL, "close");
robbiewb8739092002-12-24 19:55:40 +0000205 }
206
207 if (close(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100208 tst_brkm(TBROK, NULL, "close");
robbiewb8739092002-12-24 19:55:40 +0000209 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800210 tst_resm(TPASS, "test2");
robbiewb8739092002-12-24 19:55:40 +0000211
212 /** NOT REACHED **/
subrata_modakbdbaec52009-02-26 12:14:51 +0000213 return 0;
robbiewb8739092002-12-24 19:55:40 +0000214}
215
216/*
217 * test sending a break
218 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800219int test3(void)
robbiewb8739092002-12-24 19:55:40 +0000220{
221 int masterfd, slavefd;
222 char *slavename;
223
224 masterfd = open(MASTERCLONE, O_RDWR);
225 if (masterfd < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100226 tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
robbiewb8739092002-12-24 19:55:40 +0000227 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000228
robbiewb8739092002-12-24 19:55:40 +0000229 slavename = ptsname(masterfd);
Garrett Cooper0c74e7d2010-10-18 22:45:43 -0700230 if (slavename == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100231 tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
robbiewb8739092002-12-24 19:55:40 +0000232 }
233
234 if (grantpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100235 tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000236 }
237
238 if (unlockpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100239 tst_brkm(TBROK, NULL, "unlockpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000240 }
241
242 if ((slavefd = open(slavename, O_RDWR)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100243 tst_brkm(TBROK, NULL, "Could not open %s", slavename);
robbiewb8739092002-12-24 19:55:40 +0000244 }
245
246 if (tcsendbreak(masterfd, 10) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100247 tst_brkm(TFAIL, NULL, "tcsendbreak");
robbiewb8739092002-12-24 19:55:40 +0000248 }
249
250 if (tcsendbreak(slavefd, 10) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100251 tst_brkm(TFAIL, NULL, "tcsendbreak");
robbiewb8739092002-12-24 19:55:40 +0000252 }
253
254 if (close(slavefd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100255 tst_brkm(TBROK, NULL, "close slave");
robbiewb8739092002-12-24 19:55:40 +0000256 }
257
258 if (close(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100259 tst_brkm(TBROK, NULL, "close master");
robbiewb8739092002-12-24 19:55:40 +0000260 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800261 tst_resm(TPASS, "test3");
robbiewb8739092002-12-24 19:55:40 +0000262
263 /** NOT REACHED **/
subrata_modakbdbaec52009-02-26 12:14:51 +0000264 return 0;
robbiewb8739092002-12-24 19:55:40 +0000265}
266
robbiewb8739092002-12-24 19:55:40 +0000267/*
268 * test multiple opens of slave side
269 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800270int test4(void)
robbiewb8739092002-12-24 19:55:40 +0000271{
272 int masterfd, slavefd, slavefd2, slavefd3;
273 char *slavename;
274
275 masterfd = open(MASTERCLONE, O_RDWR);
276 if (masterfd < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100277 tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
robbiewb8739092002-12-24 19:55:40 +0000278 }
279
280 slavename = ptsname(masterfd);
Garrett Cooper0c74e7d2010-10-18 22:45:43 -0700281 if (slavename == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100282 tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
robbiewb8739092002-12-24 19:55:40 +0000283 }
284
285 if (grantpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100286 tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000287 }
288
289 if (unlockpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100290 tst_brkm(TBROK, NULL, "unlockpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000291 }
292
293 if ((slavefd = open(slavename, O_RDWR)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100294 tst_brkm(TBROK, NULL, "Could not open %s", slavename);
robbiewb8739092002-12-24 19:55:40 +0000295 }
296
297 if ((slavefd2 = open(slavename, O_RDWR)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100298 tst_brkm(TFAIL, NULL, "Could not open %s (again)", slavename);
robbiewb8739092002-12-24 19:55:40 +0000299 }
300
301 if ((slavefd3 = open(slavename, O_RDWR)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100302 tst_brkm(TFAIL, NULL, "Could not open %s (once more)",
303 slavename);
robbiewb8739092002-12-24 19:55:40 +0000304 }
305
306 if (close(slavefd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100307 tst_brkm(TBROK, NULL, "close slave");
robbiewb8739092002-12-24 19:55:40 +0000308 }
309 if (close(slavefd2) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100310 tst_brkm(TBROK, NULL, "close slave again");
robbiewb8739092002-12-24 19:55:40 +0000311 }
312 if (close(slavefd3) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100313 tst_brkm(TBROK, NULL, "close slave once more");
robbiewb8739092002-12-24 19:55:40 +0000314 }
315 if (close(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100316 tst_brkm(TBROK, NULL, "close master");
robbiewb8739092002-12-24 19:55:40 +0000317 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800318 tst_resm(TPASS, "test4");
robbiewb8739092002-12-24 19:55:40 +0000319
320 /** NOT REACHED **/
subrata_modak43337a32009-02-26 11:43:51 +0000321 return 0;
robbiewb8739092002-12-24 19:55:40 +0000322}
323
324#define NUMOPENS 6
325
326/*
327 * test several simultaneous opens
328 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800329int test5(void)
robbiewb8739092002-12-24 19:55:40 +0000330{
331 static int masterfd[NUMOPENS];
332 static int slavefd[NUMOPENS];
333 char *slavename;
334 int i;
335
336 for (i = 0; i < NUMOPENS; ++i) {
337 masterfd[i] = open(MASTERCLONE, O_RDWR);
338 if (masterfd[i] < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800339 tst_resm(TBROK, "%s", MASTERCLONE);
robbiewb8739092002-12-24 19:55:40 +0000340 tst_resm(TBROK, "out of ptys");
341 for (i = 0; i < NUMOPENS; ++i) {
342 if (masterfd[i] != 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800343 (void)close(masterfd[i]);
robbiewb8739092002-12-24 19:55:40 +0000344 }
345 if (slavefd[i] != 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800346 (void)close(slavefd[i]);
robbiewb8739092002-12-24 19:55:40 +0000347 }
348 }
349 tst_exit();
350 }
351
352 slavename = ptsname(masterfd[i]);
Garrett Cooper0c74e7d2010-10-18 22:45:43 -0700353 if (slavename == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100354 tst_brkm(TBROK | TERRNO, NULL,
355 "ptsname() call failed");
robbiewb8739092002-12-24 19:55:40 +0000356 }
357
358 if (grantpt(masterfd[i]) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100359 tst_brkm(TBROK | TERRNO, NULL,
360 "grantpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000361 }
362
363 if (unlockpt(masterfd[i]) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100364 tst_brkm(TBROK, NULL, "unlockpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000365 }
366
367 if ((slavefd[i] = open(slavename, O_RDWR)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100368 tst_brkm(TFAIL, NULL,
369 "Iteration %d: Could not open %s", i,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800370 slavename);
robbiewb8739092002-12-24 19:55:40 +0000371 }
372
373 }
374
375 for (i = 0; i < NUMOPENS; ++i) {
376 if (close(slavefd[i]) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100377 tst_brkm(TBROK, NULL, "Iteration %d: close slave", i);
robbiewb8739092002-12-24 19:55:40 +0000378 }
379 if (close(masterfd[i]) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100380 tst_brkm(TBROK, NULL, "close master");
robbiewb8739092002-12-24 19:55:40 +0000381 }
382 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800383 tst_resm(TPASS, "test5");
robbiewb8739092002-12-24 19:55:40 +0000384
385 /** NOT REACHED **/
subrata_modak43337a32009-02-26 11:43:51 +0000386 return 0;
robbiewb8739092002-12-24 19:55:40 +0000387}
388
robbiewb8739092002-12-24 19:55:40 +0000389/*
390 * test hangup semantics
391 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800392int test6(void)
robbiewb8739092002-12-24 19:55:40 +0000393{
394 static int masterfd;
395 static int slavefd;
396 char *slavename;
397 struct termios termios;
398
399 masterfd = open(MASTERCLONE, O_RDWR);
400 if (masterfd < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100401 tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
robbiewb8739092002-12-24 19:55:40 +0000402 }
403
404 slavename = ptsname(masterfd);
Garrett Cooper0c74e7d2010-10-18 22:45:43 -0700405 if (slavename == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100406 tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
robbiewb8739092002-12-24 19:55:40 +0000407 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000408
robbiewb8739092002-12-24 19:55:40 +0000409 if (grantpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100410 tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000411 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000412
robbiewb8739092002-12-24 19:55:40 +0000413 if (unlockpt(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100414 tst_brkm(TBROK, NULL, "unlockpt() call failed");
robbiewb8739092002-12-24 19:55:40 +0000415 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000416
robbiewb8739092002-12-24 19:55:40 +0000417 if ((slavefd = open(slavename, O_RDWR)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100418 tst_brkm(TBROK, NULL, "Could not open %s", slavename);
robbiewb8739092002-12-24 19:55:40 +0000419 }
420
421 if (ioctl(slavefd, TCGETS, &termios) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100422 tst_brkm(TFAIL, NULL, "TCGETS");
robbiewb8739092002-12-24 19:55:40 +0000423 }
424
425 termios.c_cflag &= ~CBAUD;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800426 termios.c_cflag |= B0 & CBAUD;
robbiewb8739092002-12-24 19:55:40 +0000427 if (ioctl(slavefd, TCSETS, &termios) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100428 tst_brkm(TFAIL, NULL, "TCGETS");
robbiewb8739092002-12-24 19:55:40 +0000429 }
430
431 if (close(slavefd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100432 tst_brkm(TBROK, NULL, "close");
robbiewb8739092002-12-24 19:55:40 +0000433 }
434 if (close(masterfd) != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100435 tst_brkm(TBROK, NULL, "close");
robbiewb8739092002-12-24 19:55:40 +0000436 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800437 tst_resm(TPASS, "test6");
robbiewb8739092002-12-24 19:55:40 +0000438
439 /** NOT REACHED **/
subrata_modak43337a32009-02-26 11:43:51 +0000440 return 0;
robbiewb8739092002-12-24 19:55:40 +0000441}
442
443/*
444 * main test driver
445 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800446int main(int argc, char **argv)
robbiewb8739092002-12-24 19:55:40 +0000447{
448 test1();
449 test2();
450 test3();
451 test4();
452 test5();
453 test6();
454 /*
Wanlong Gao354ebb42012-12-07 10:10:04 +0800455 * all done
robbiewb8739092002-12-24 19:55:40 +0000456 */
457 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700458}