1b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 2b87390939c55e574c5b4c66a341d80df3863762frobbiew * 3b87390939c55e574c5b4c66a341d80df3863762frobbiew * Copyright (c) International Business Machines Corp., 2002 4b87390939c55e574c5b4c66a341d80df3863762frobbiew * 5b87390939c55e574c5b4c66a341d80df3863762frobbiew * This program is free software; you can redistribute it and/or modify 6b87390939c55e574c5b4c66a341d80df3863762frobbiew * it under the terms of the GNU General Public License as published by 7b87390939c55e574c5b4c66a341d80df3863762frobbiew * the Free Software Foundation; either version 2 of the License, or 8b87390939c55e574c5b4c66a341d80df3863762frobbiew * (at your option) any later version. 9b87390939c55e574c5b4c66a341d80df3863762frobbiew * 10b87390939c55e574c5b4c66a341d80df3863762frobbiew * This program is distributed in the hope that it will be useful, 11b87390939c55e574c5b4c66a341d80df3863762frobbiew * but WITHOUT ANY WARRANTY; without even the implied warranty of 12b87390939c55e574c5b4c66a341d80df3863762frobbiew * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13b87390939c55e574c5b4c66a341d80df3863762frobbiew * the GNU General Public License for more details. 14b87390939c55e574c5b4c66a341d80df3863762frobbiew * 15b87390939c55e574c5b4c66a341d80df3863762frobbiew * You should have received a copy of the GNU General Public License 16b87390939c55e574c5b4c66a341d80df3863762frobbiew * along with this program; if not, write to the Free Software 174548c6cf9bcdd96d8303caa4130ab638b61f8a30Wanlong Gao * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 19b87390939c55e574c5b4c66a341d80df3863762frobbiew 20b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 12/23/2002 Port to LTP robbiew@us.ibm.com */ 21b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ 22b87390939c55e574c5b4c66a341d80df3863762frobbiew 23b87390939c55e574c5b4c66a341d80df3863762frobbiew#include <errno.h> 24b87390939c55e574c5b4c66a341d80df3863762frobbiew#include <stdio.h> 25b87390939c55e574c5b4c66a341d80df3863762frobbiew#include <stdlib.h> 26b87390939c55e574c5b4c66a341d80df3863762frobbiew#include <stdio.h> 27b87390939c55e574c5b4c66a341d80df3863762frobbiew#include <termio.h> 28a7fa8561a5a095faf6e202a80b0c7729be8bb82dSteven Jackson#include <fcntl.h> 29b87390939c55e574c5b4c66a341d80df3863762frobbiew#include <sys/stat.h> 30b87390939c55e574c5b4c66a341d80df3863762frobbiew#include <sys/poll.h> 31b87390939c55e574c5b4c66a341d80df3863762frobbiew#include <sys/types.h> 32b87390939c55e574c5b4c66a341d80df3863762frobbiew 33b87390939c55e574c5b4c66a341d80df3863762frobbiew#ifndef _GNU_SOURCE 34b87390939c55e574c5b4c66a341d80df3863762frobbiew#define _GNU_SOURCE 1 35b87390939c55e574c5b4c66a341d80df3863762frobbiew#endif 36b87390939c55e574c5b4c66a341d80df3863762frobbiew 37b87390939c55e574c5b4c66a341d80df3863762frobbiew/** LTP Port **/ 38b87390939c55e574c5b4c66a341d80df3863762frobbiew#include "test.h" 39d8cd45ca8cb268a3fcf4d0679d5fdd24f499ece6Cyril Hrubis#include "safe_macros.h" 40b87390939c55e574c5b4c66a341d80df3863762frobbiew 41354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaochar *TCID = "ptem01"; /* Test program identifier. */ 42354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint TST_TOTAL = 6; /* Total number of test cases. */ 43b87390939c55e574c5b4c66a341d80df3863762frobbiew/**************/ 44b87390939c55e574c5b4c66a341d80df3863762frobbiew 45b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 46b87390939c55e574c5b4c66a341d80df3863762frobbiew * pty master clone device 47b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 48b87390939c55e574c5b4c66a341d80df3863762frobbiew#define MASTERCLONE "/dev/ptmx" 49b87390939c55e574c5b4c66a341d80df3863762frobbiew 50b87390939c55e574c5b4c66a341d80df3863762frobbiew#define BUFSZ 4096 51b87390939c55e574c5b4c66a341d80df3863762frobbiew 52b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 53b87390939c55e574c5b4c66a341d80df3863762frobbiew * test termio/termios ioctls 54b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 55354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint test1(void) 56b87390939c55e574c5b4c66a341d80df3863762frobbiew{ 57b87390939c55e574c5b4c66a341d80df3863762frobbiew int masterfd, slavefd; 58b87390939c55e574c5b4c66a341d80df3863762frobbiew char *slavename; 59b87390939c55e574c5b4c66a341d80df3863762frobbiew struct termio termio; 60b87390939c55e574c5b4c66a341d80df3863762frobbiew struct termios termios; 61b87390939c55e574c5b4c66a341d80df3863762frobbiew 62d8cd45ca8cb268a3fcf4d0679d5fdd24f499ece6Cyril Hrubis masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR); 63bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 64b87390939c55e574c5b4c66a341d80df3863762frobbiew slavename = ptsname(masterfd); 650c74e7d7d4d4484b7605c417dc0e751a39260356Garrett Cooper if (slavename == NULL) { 66526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed"); 67b87390939c55e574c5b4c66a341d80df3863762frobbiew } 68b87390939c55e574c5b4c66a341d80df3863762frobbiew 69b87390939c55e574c5b4c66a341d80df3863762frobbiew if (grantpt(masterfd) != 0) { 70526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed"); 71b87390939c55e574c5b4c66a341d80df3863762frobbiew } 72b87390939c55e574c5b4c66a341d80df3863762frobbiew 73b87390939c55e574c5b4c66a341d80df3863762frobbiew if (unlockpt(masterfd) != 0) { 74526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "unlockpt() call failed"); 75b87390939c55e574c5b4c66a341d80df3863762frobbiew } 76b87390939c55e574c5b4c66a341d80df3863762frobbiew 77b87390939c55e574c5b4c66a341d80df3863762frobbiew if ((slavefd = open(slavename, O_RDWR)) < 0) { 78526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "Could not open %s", slavename); 79b87390939c55e574c5b4c66a341d80df3863762frobbiew } 80b87390939c55e574c5b4c66a341d80df3863762frobbiew 81b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCGETS, &termios) != 0) { 82526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCGETS"); 83b87390939c55e574c5b4c66a341d80df3863762frobbiew } 84b87390939c55e574c5b4c66a341d80df3863762frobbiew 85b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCSETS, &termios) != 0) { 86526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCSETS"); 87b87390939c55e574c5b4c66a341d80df3863762frobbiew } 88b87390939c55e574c5b4c66a341d80df3863762frobbiew 89b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCSETSW, &termios) != 0) { 90526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCSETSW"); 91b87390939c55e574c5b4c66a341d80df3863762frobbiew } 92b87390939c55e574c5b4c66a341d80df3863762frobbiew 93b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCSETSF, &termios) != 0) { 94526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCSETSF"); 95b87390939c55e574c5b4c66a341d80df3863762frobbiew } 96b87390939c55e574c5b4c66a341d80df3863762frobbiew 97b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCSETS, &termios) != 0) { 98526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCSETS"); 99b87390939c55e574c5b4c66a341d80df3863762frobbiew } 100b87390939c55e574c5b4c66a341d80df3863762frobbiew 101b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCGETA, &termio) != 0) { 102526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCGETA"); 103b87390939c55e574c5b4c66a341d80df3863762frobbiew } 104b87390939c55e574c5b4c66a341d80df3863762frobbiew 105b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCSETA, &termio) != 0) { 106526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCSETA"); 107b87390939c55e574c5b4c66a341d80df3863762frobbiew } 108b87390939c55e574c5b4c66a341d80df3863762frobbiew 109b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCSETAW, &termio) != 0) { 110526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCSETAW"); 111b87390939c55e574c5b4c66a341d80df3863762frobbiew } 112b87390939c55e574c5b4c66a341d80df3863762frobbiew 113b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCSETAF, &termio) != 0) { 114526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCSETAF"); 115b87390939c55e574c5b4c66a341d80df3863762frobbiew } 116b87390939c55e574c5b4c66a341d80df3863762frobbiew 117b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(slavefd) != 0) { 118526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close slave"); 119b87390939c55e574c5b4c66a341d80df3863762frobbiew } 120b87390939c55e574c5b4c66a341d80df3863762frobbiew 121b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(masterfd) != 0) { 122526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close master"); 123b87390939c55e574c5b4c66a341d80df3863762frobbiew } 124354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao tst_resm(TPASS, "test1"); 125b87390939c55e574c5b4c66a341d80df3863762frobbiew 126b87390939c55e574c5b4c66a341d80df3863762frobbiew /** NOT REACHED **/ 127bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak return 0; 128b87390939c55e574c5b4c66a341d80df3863762frobbiew} 129b87390939c55e574c5b4c66a341d80df3863762frobbiew 130b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 131b87390939c55e574c5b4c66a341d80df3863762frobbiew * test window size setting and getting 132b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 133354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint test2(void) 134b87390939c55e574c5b4c66a341d80df3863762frobbiew{ 135b87390939c55e574c5b4c66a341d80df3863762frobbiew int masterfd, slavefd; 136b87390939c55e574c5b4c66a341d80df3863762frobbiew char *slavename; 137b87390939c55e574c5b4c66a341d80df3863762frobbiew struct winsize wsz; 138354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao struct winsize wsz1 = { 24, 80, 5, 10 }; 139354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao struct winsize wsz2 = { 60, 100, 11, 777 }; 140b87390939c55e574c5b4c66a341d80df3863762frobbiew 141d8cd45ca8cb268a3fcf4d0679d5fdd24f499ece6Cyril Hrubis masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR); 142bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 143b87390939c55e574c5b4c66a341d80df3863762frobbiew slavename = ptsname(masterfd); 1440c74e7d7d4d4484b7605c417dc0e751a39260356Garrett Cooper if (slavename == NULL) { 145526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed"); 146b87390939c55e574c5b4c66a341d80df3863762frobbiew } 147b87390939c55e574c5b4c66a341d80df3863762frobbiew 148b87390939c55e574c5b4c66a341d80df3863762frobbiew if (grantpt(masterfd) != 0) { 149526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed"); 150b87390939c55e574c5b4c66a341d80df3863762frobbiew } 151b87390939c55e574c5b4c66a341d80df3863762frobbiew 152b87390939c55e574c5b4c66a341d80df3863762frobbiew if (unlockpt(masterfd) != 0) { 153526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "unlockpt() call failed"); 154b87390939c55e574c5b4c66a341d80df3863762frobbiew } 155b87390939c55e574c5b4c66a341d80df3863762frobbiew 156b87390939c55e574c5b4c66a341d80df3863762frobbiew if ((slavefd = open(slavename, O_RDWR)) < 0) { 157526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "Could not open %s", slavename); 158b87390939c55e574c5b4c66a341d80df3863762frobbiew } 159b87390939c55e574c5b4c66a341d80df3863762frobbiew 160b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(masterfd, TIOCSWINSZ, &wsz1) != 0) { 161526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TIOCSWINSZ"); 162b87390939c55e574c5b4c66a341d80df3863762frobbiew } 163b87390939c55e574c5b4c66a341d80df3863762frobbiew 164b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TIOCGWINSZ, &wsz) != 0) { 165526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TIOCGWINSZ"); 166b87390939c55e574c5b4c66a341d80df3863762frobbiew } 167b87390939c55e574c5b4c66a341d80df3863762frobbiew 168b87390939c55e574c5b4c66a341d80df3863762frobbiew if (wsz.ws_row != wsz1.ws_row || wsz.ws_col != wsz1.ws_col || 169b87390939c55e574c5b4c66a341d80df3863762frobbiew wsz.ws_xpixel != wsz1.ws_xpixel || 170b87390939c55e574c5b4c66a341d80df3863762frobbiew wsz.ws_ypixel != wsz1.ws_ypixel) { 171526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "unexpected window size returned"); 172b87390939c55e574c5b4c66a341d80df3863762frobbiew } 173b87390939c55e574c5b4c66a341d80df3863762frobbiew 174b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(masterfd, TIOCGWINSZ, &wsz) != 0) { 175526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TIOCGWINSZ"); 176b87390939c55e574c5b4c66a341d80df3863762frobbiew } 177b87390939c55e574c5b4c66a341d80df3863762frobbiew 178b87390939c55e574c5b4c66a341d80df3863762frobbiew if (wsz.ws_row != wsz1.ws_row || wsz.ws_col != wsz1.ws_col || 179b87390939c55e574c5b4c66a341d80df3863762frobbiew wsz.ws_xpixel != wsz1.ws_xpixel || 180b87390939c55e574c5b4c66a341d80df3863762frobbiew wsz.ws_ypixel != wsz1.ws_ypixel) { 181526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "unexpected window size returned"); 182b87390939c55e574c5b4c66a341d80df3863762frobbiew } 183b87390939c55e574c5b4c66a341d80df3863762frobbiew 184b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TIOCSWINSZ, &wsz2) != 0) { 185526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TIOCSWINSZ"); 186b87390939c55e574c5b4c66a341d80df3863762frobbiew } 187b87390939c55e574c5b4c66a341d80df3863762frobbiew 188b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TIOCGWINSZ, &wsz) != 0) { 189526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TIOCGWINSZ"); 190b87390939c55e574c5b4c66a341d80df3863762frobbiew } 191b87390939c55e574c5b4c66a341d80df3863762frobbiew 192b87390939c55e574c5b4c66a341d80df3863762frobbiew if (wsz.ws_row != wsz2.ws_row || wsz.ws_col != wsz2.ws_col || 193b87390939c55e574c5b4c66a341d80df3863762frobbiew wsz.ws_xpixel != wsz2.ws_xpixel || 194b87390939c55e574c5b4c66a341d80df3863762frobbiew wsz.ws_ypixel != wsz2.ws_ypixel) { 195526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "unexpected window size returned"); 196b87390939c55e574c5b4c66a341d80df3863762frobbiew } 197b87390939c55e574c5b4c66a341d80df3863762frobbiew 198b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(slavefd) != 0) { 199526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close"); 200b87390939c55e574c5b4c66a341d80df3863762frobbiew } 201b87390939c55e574c5b4c66a341d80df3863762frobbiew 202b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(masterfd) != 0) { 203526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close"); 204b87390939c55e574c5b4c66a341d80df3863762frobbiew } 205354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao tst_resm(TPASS, "test2"); 206b87390939c55e574c5b4c66a341d80df3863762frobbiew 207b87390939c55e574c5b4c66a341d80df3863762frobbiew /** NOT REACHED **/ 208bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak return 0; 209b87390939c55e574c5b4c66a341d80df3863762frobbiew} 210b87390939c55e574c5b4c66a341d80df3863762frobbiew 211b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 212b87390939c55e574c5b4c66a341d80df3863762frobbiew * test sending a break 213b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 214354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint test3(void) 215b87390939c55e574c5b4c66a341d80df3863762frobbiew{ 216b87390939c55e574c5b4c66a341d80df3863762frobbiew int masterfd, slavefd; 217b87390939c55e574c5b4c66a341d80df3863762frobbiew char *slavename; 218b87390939c55e574c5b4c66a341d80df3863762frobbiew 219d8cd45ca8cb268a3fcf4d0679d5fdd24f499ece6Cyril Hrubis masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR); 220bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 221b87390939c55e574c5b4c66a341d80df3863762frobbiew slavename = ptsname(masterfd); 2220c74e7d7d4d4484b7605c417dc0e751a39260356Garrett Cooper if (slavename == NULL) { 223526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed"); 224b87390939c55e574c5b4c66a341d80df3863762frobbiew } 225b87390939c55e574c5b4c66a341d80df3863762frobbiew 226b87390939c55e574c5b4c66a341d80df3863762frobbiew if (grantpt(masterfd) != 0) { 227526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed"); 228b87390939c55e574c5b4c66a341d80df3863762frobbiew } 229b87390939c55e574c5b4c66a341d80df3863762frobbiew 230b87390939c55e574c5b4c66a341d80df3863762frobbiew if (unlockpt(masterfd) != 0) { 231526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "unlockpt() call failed"); 232b87390939c55e574c5b4c66a341d80df3863762frobbiew } 233b87390939c55e574c5b4c66a341d80df3863762frobbiew 234b87390939c55e574c5b4c66a341d80df3863762frobbiew if ((slavefd = open(slavename, O_RDWR)) < 0) { 235526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "Could not open %s", slavename); 236b87390939c55e574c5b4c66a341d80df3863762frobbiew } 237b87390939c55e574c5b4c66a341d80df3863762frobbiew 238b87390939c55e574c5b4c66a341d80df3863762frobbiew if (tcsendbreak(masterfd, 10) != 0) { 239526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "tcsendbreak"); 240b87390939c55e574c5b4c66a341d80df3863762frobbiew } 241b87390939c55e574c5b4c66a341d80df3863762frobbiew 242b87390939c55e574c5b4c66a341d80df3863762frobbiew if (tcsendbreak(slavefd, 10) != 0) { 243526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "tcsendbreak"); 244b87390939c55e574c5b4c66a341d80df3863762frobbiew } 245b87390939c55e574c5b4c66a341d80df3863762frobbiew 246b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(slavefd) != 0) { 247526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close slave"); 248b87390939c55e574c5b4c66a341d80df3863762frobbiew } 249b87390939c55e574c5b4c66a341d80df3863762frobbiew 250b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(masterfd) != 0) { 251526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close master"); 252b87390939c55e574c5b4c66a341d80df3863762frobbiew } 253354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao tst_resm(TPASS, "test3"); 254b87390939c55e574c5b4c66a341d80df3863762frobbiew 255b87390939c55e574c5b4c66a341d80df3863762frobbiew /** NOT REACHED **/ 256bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak return 0; 257b87390939c55e574c5b4c66a341d80df3863762frobbiew} 258b87390939c55e574c5b4c66a341d80df3863762frobbiew 259b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 260b87390939c55e574c5b4c66a341d80df3863762frobbiew * test multiple opens of slave side 261b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 262354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint test4(void) 263b87390939c55e574c5b4c66a341d80df3863762frobbiew{ 264b87390939c55e574c5b4c66a341d80df3863762frobbiew int masterfd, slavefd, slavefd2, slavefd3; 265b87390939c55e574c5b4c66a341d80df3863762frobbiew char *slavename; 266b87390939c55e574c5b4c66a341d80df3863762frobbiew 267d8cd45ca8cb268a3fcf4d0679d5fdd24f499ece6Cyril Hrubis masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR); 268b87390939c55e574c5b4c66a341d80df3863762frobbiew 269b87390939c55e574c5b4c66a341d80df3863762frobbiew slavename = ptsname(masterfd); 2700c74e7d7d4d4484b7605c417dc0e751a39260356Garrett Cooper if (slavename == NULL) { 271526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed"); 272b87390939c55e574c5b4c66a341d80df3863762frobbiew } 273b87390939c55e574c5b4c66a341d80df3863762frobbiew 274b87390939c55e574c5b4c66a341d80df3863762frobbiew if (grantpt(masterfd) != 0) { 275526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed"); 276b87390939c55e574c5b4c66a341d80df3863762frobbiew } 277b87390939c55e574c5b4c66a341d80df3863762frobbiew 278b87390939c55e574c5b4c66a341d80df3863762frobbiew if (unlockpt(masterfd) != 0) { 279526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "unlockpt() call failed"); 280b87390939c55e574c5b4c66a341d80df3863762frobbiew } 281b87390939c55e574c5b4c66a341d80df3863762frobbiew 282b87390939c55e574c5b4c66a341d80df3863762frobbiew if ((slavefd = open(slavename, O_RDWR)) < 0) { 283526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "Could not open %s", slavename); 284b87390939c55e574c5b4c66a341d80df3863762frobbiew } 285b87390939c55e574c5b4c66a341d80df3863762frobbiew 286b87390939c55e574c5b4c66a341d80df3863762frobbiew if ((slavefd2 = open(slavename, O_RDWR)) < 0) { 287526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "Could not open %s (again)", slavename); 288b87390939c55e574c5b4c66a341d80df3863762frobbiew } 289b87390939c55e574c5b4c66a341d80df3863762frobbiew 290b87390939c55e574c5b4c66a341d80df3863762frobbiew if ((slavefd3 = open(slavename, O_RDWR)) < 0) { 291526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "Could not open %s (once more)", 292526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis slavename); 293b87390939c55e574c5b4c66a341d80df3863762frobbiew } 294b87390939c55e574c5b4c66a341d80df3863762frobbiew 295b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(slavefd) != 0) { 296526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close slave"); 297b87390939c55e574c5b4c66a341d80df3863762frobbiew } 298b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(slavefd2) != 0) { 299526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close slave again"); 300b87390939c55e574c5b4c66a341d80df3863762frobbiew } 301b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(slavefd3) != 0) { 302526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close slave once more"); 303b87390939c55e574c5b4c66a341d80df3863762frobbiew } 304b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(masterfd) != 0) { 305526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close master"); 306b87390939c55e574c5b4c66a341d80df3863762frobbiew } 307354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao tst_resm(TPASS, "test4"); 308b87390939c55e574c5b4c66a341d80df3863762frobbiew 309b87390939c55e574c5b4c66a341d80df3863762frobbiew /** NOT REACHED **/ 31043337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak return 0; 311b87390939c55e574c5b4c66a341d80df3863762frobbiew} 312b87390939c55e574c5b4c66a341d80df3863762frobbiew 313b87390939c55e574c5b4c66a341d80df3863762frobbiew#define NUMOPENS 6 314b87390939c55e574c5b4c66a341d80df3863762frobbiew 315b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 316b87390939c55e574c5b4c66a341d80df3863762frobbiew * test several simultaneous opens 317b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 318354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint test5(void) 319b87390939c55e574c5b4c66a341d80df3863762frobbiew{ 320b87390939c55e574c5b4c66a341d80df3863762frobbiew static int masterfd[NUMOPENS]; 321b87390939c55e574c5b4c66a341d80df3863762frobbiew static int slavefd[NUMOPENS]; 322b87390939c55e574c5b4c66a341d80df3863762frobbiew char *slavename; 323b87390939c55e574c5b4c66a341d80df3863762frobbiew int i; 324b87390939c55e574c5b4c66a341d80df3863762frobbiew 325b87390939c55e574c5b4c66a341d80df3863762frobbiew for (i = 0; i < NUMOPENS; ++i) { 326b87390939c55e574c5b4c66a341d80df3863762frobbiew masterfd[i] = open(MASTERCLONE, O_RDWR); 327b87390939c55e574c5b4c66a341d80df3863762frobbiew if (masterfd[i] < 0) { 328354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao tst_resm(TBROK, "%s", MASTERCLONE); 329b87390939c55e574c5b4c66a341d80df3863762frobbiew tst_resm(TBROK, "out of ptys"); 330b87390939c55e574c5b4c66a341d80df3863762frobbiew for (i = 0; i < NUMOPENS; ++i) { 331b87390939c55e574c5b4c66a341d80df3863762frobbiew if (masterfd[i] != 0) { 332354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao (void)close(masterfd[i]); 333b87390939c55e574c5b4c66a341d80df3863762frobbiew } 334b87390939c55e574c5b4c66a341d80df3863762frobbiew if (slavefd[i] != 0) { 335354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao (void)close(slavefd[i]); 336b87390939c55e574c5b4c66a341d80df3863762frobbiew } 337b87390939c55e574c5b4c66a341d80df3863762frobbiew } 338b87390939c55e574c5b4c66a341d80df3863762frobbiew tst_exit(); 339b87390939c55e574c5b4c66a341d80df3863762frobbiew } 340b87390939c55e574c5b4c66a341d80df3863762frobbiew 341b87390939c55e574c5b4c66a341d80df3863762frobbiew slavename = ptsname(masterfd[i]); 3420c74e7d7d4d4484b7605c417dc0e751a39260356Garrett Cooper if (slavename == NULL) { 343526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, 344526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis "ptsname() call failed"); 345b87390939c55e574c5b4c66a341d80df3863762frobbiew } 346b87390939c55e574c5b4c66a341d80df3863762frobbiew 347b87390939c55e574c5b4c66a341d80df3863762frobbiew if (grantpt(masterfd[i]) != 0) { 348526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, 349526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis "grantpt() call failed"); 350b87390939c55e574c5b4c66a341d80df3863762frobbiew } 351b87390939c55e574c5b4c66a341d80df3863762frobbiew 352b87390939c55e574c5b4c66a341d80df3863762frobbiew if (unlockpt(masterfd[i]) != 0) { 353526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "unlockpt() call failed"); 354b87390939c55e574c5b4c66a341d80df3863762frobbiew } 355b87390939c55e574c5b4c66a341d80df3863762frobbiew 356b87390939c55e574c5b4c66a341d80df3863762frobbiew if ((slavefd[i] = open(slavename, O_RDWR)) < 0) { 357526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, 358526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis "Iteration %d: Could not open %s", i, 359354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao slavename); 360b87390939c55e574c5b4c66a341d80df3863762frobbiew } 361b87390939c55e574c5b4c66a341d80df3863762frobbiew 362b87390939c55e574c5b4c66a341d80df3863762frobbiew } 363b87390939c55e574c5b4c66a341d80df3863762frobbiew 364b87390939c55e574c5b4c66a341d80df3863762frobbiew for (i = 0; i < NUMOPENS; ++i) { 365b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(slavefd[i]) != 0) { 366526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "Iteration %d: close slave", i); 367b87390939c55e574c5b4c66a341d80df3863762frobbiew } 368b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(masterfd[i]) != 0) { 369526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close master"); 370b87390939c55e574c5b4c66a341d80df3863762frobbiew } 371b87390939c55e574c5b4c66a341d80df3863762frobbiew } 372354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao tst_resm(TPASS, "test5"); 373b87390939c55e574c5b4c66a341d80df3863762frobbiew 374b87390939c55e574c5b4c66a341d80df3863762frobbiew /** NOT REACHED **/ 37543337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak return 0; 376b87390939c55e574c5b4c66a341d80df3863762frobbiew} 377b87390939c55e574c5b4c66a341d80df3863762frobbiew 378b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 379b87390939c55e574c5b4c66a341d80df3863762frobbiew * test hangup semantics 380b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 381354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint test6(void) 382b87390939c55e574c5b4c66a341d80df3863762frobbiew{ 383b87390939c55e574c5b4c66a341d80df3863762frobbiew static int masterfd; 384b87390939c55e574c5b4c66a341d80df3863762frobbiew static int slavefd; 385b87390939c55e574c5b4c66a341d80df3863762frobbiew char *slavename; 386b87390939c55e574c5b4c66a341d80df3863762frobbiew struct termios termios; 387b87390939c55e574c5b4c66a341d80df3863762frobbiew 388d8cd45ca8cb268a3fcf4d0679d5fdd24f499ece6Cyril Hrubis masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR); 389b87390939c55e574c5b4c66a341d80df3863762frobbiew 390b87390939c55e574c5b4c66a341d80df3863762frobbiew slavename = ptsname(masterfd); 3910c74e7d7d4d4484b7605c417dc0e751a39260356Garrett Cooper if (slavename == NULL) { 392526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed"); 393b87390939c55e574c5b4c66a341d80df3863762frobbiew } 394bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 395b87390939c55e574c5b4c66a341d80df3863762frobbiew if (grantpt(masterfd) != 0) { 396526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed"); 397b87390939c55e574c5b4c66a341d80df3863762frobbiew } 398bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 399b87390939c55e574c5b4c66a341d80df3863762frobbiew if (unlockpt(masterfd) != 0) { 400526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "unlockpt() call failed"); 401b87390939c55e574c5b4c66a341d80df3863762frobbiew } 402bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 403b87390939c55e574c5b4c66a341d80df3863762frobbiew if ((slavefd = open(slavename, O_RDWR)) < 0) { 404526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "Could not open %s", slavename); 405b87390939c55e574c5b4c66a341d80df3863762frobbiew } 406b87390939c55e574c5b4c66a341d80df3863762frobbiew 407b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCGETS, &termios) != 0) { 408526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCGETS"); 409b87390939c55e574c5b4c66a341d80df3863762frobbiew } 410b87390939c55e574c5b4c66a341d80df3863762frobbiew 411b87390939c55e574c5b4c66a341d80df3863762frobbiew termios.c_cflag &= ~CBAUD; 412354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao termios.c_cflag |= B0 & CBAUD; 413b87390939c55e574c5b4c66a341d80df3863762frobbiew if (ioctl(slavefd, TCSETS, &termios) != 0) { 414526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TFAIL, NULL, "TCGETS"); 415b87390939c55e574c5b4c66a341d80df3863762frobbiew } 416b87390939c55e574c5b4c66a341d80df3863762frobbiew 417b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(slavefd) != 0) { 418526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close"); 419b87390939c55e574c5b4c66a341d80df3863762frobbiew } 420b87390939c55e574c5b4c66a341d80df3863762frobbiew if (close(masterfd) != 0) { 421526fdf8d8ea3b43b73de7cc25eb754f12702c8d2Cyril Hrubis tst_brkm(TBROK, NULL, "close"); 422b87390939c55e574c5b4c66a341d80df3863762frobbiew } 423354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao tst_resm(TPASS, "test6"); 424b87390939c55e574c5b4c66a341d80df3863762frobbiew 425b87390939c55e574c5b4c66a341d80df3863762frobbiew /** NOT REACHED **/ 42643337a3cf6f8809647cf9fc6c0054241f44b1fb1subrata_modak return 0; 427b87390939c55e574c5b4c66a341d80df3863762frobbiew} 428b87390939c55e574c5b4c66a341d80df3863762frobbiew 429b87390939c55e574c5b4c66a341d80df3863762frobbiew/* 430b87390939c55e574c5b4c66a341d80df3863762frobbiew * main test driver 431b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 432354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint main(int argc, char **argv) 433b87390939c55e574c5b4c66a341d80df3863762frobbiew{ 434b87390939c55e574c5b4c66a341d80df3863762frobbiew test1(); 435b87390939c55e574c5b4c66a341d80df3863762frobbiew test2(); 436b87390939c55e574c5b4c66a341d80df3863762frobbiew test3(); 437b87390939c55e574c5b4c66a341d80df3863762frobbiew test4(); 438b87390939c55e574c5b4c66a341d80df3863762frobbiew test5(); 439b87390939c55e574c5b4c66a341d80df3863762frobbiew test6(); 440b87390939c55e574c5b4c66a341d80df3863762frobbiew /* 441354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao * all done 442b87390939c55e574c5b4c66a341d80df3863762frobbiew */ 443b87390939c55e574c5b4c66a341d80df3863762frobbiew tst_exit(); 444ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 445