1 /* 2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it would be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * Further, this software is distributed without any warranty that it is 13 * free of the rightful claim of any third person regarding infringement 14 * or the like. Any license provided herein, whether implied or 15 * otherwise, applies only to this software file. Patent licenses, if 16 * any, provided herein do not apply to combinations of this program with 17 * other software, or any other product whatsoever. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write the Free Software Foundation, Inc., 21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 24 * Mountain View, CA 94043, or: 25 * 26 * http://www.sgi.com 27 * 28 * For further information regarding this notice, see: 29 * 30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 31 * 32 */ 33 /* 34 * AUTHOR : Richard Logan 35 * CO-PILOT : Glen Overby 36 * DATE STARTED : 02/24/93 37 * 38 * TEST CASES 39 * 1.) select(2) to fd of system pipe with no I/O and small timeout 40 */ 41 #include <errno.h> 42 #include <signal.h> 43 #include <fcntl.h> 44 #include <signal.h> 45 #include <sys/param.h> 46 #include <sys/types.h> 47 #include <sys/time.h> 48 49 #include "test.h" 50 #include "safe_macros.h" 51 52 static void setup(void); 53 54 char *TCID = "select02"; 55 int TST_TOTAL = 1; 56 57 int Fd[2]; 58 fd_set saved_Readfds, saved_Writefds; 59 fd_set Readfds, Writefds; 60 61 int main(int ac, char **av) 62 { 63 int lc; 64 struct timeval timeout; 65 long test_time = 0; /* in usecs */ 66 67 tst_parse_opts(ac, av, NULL, NULL); 68 69 setup(); 70 71 for (lc = 0; TEST_LOOPING(lc); lc++) { 72 tst_count = 0; 73 74 test_time = ((lc % 2000) * 100000); /* 100 milli-seconds */ 75 76 if (test_time > 1000000 * 60) 77 test_time = test_time % (1000000 * 60); 78 79 timeout.tv_sec = test_time / 1000000; 80 timeout.tv_usec = test_time - (timeout.tv_sec * 1000000); 81 82 Readfds = saved_Readfds; 83 Writefds = saved_Writefds; 84 85 TEST(select(5, &Readfds, &Writefds, 0, &timeout)); 86 87 if (TEST_RETURN == -1) { 88 tst_resm(TFAIL, 89 "%d select(5, &Readfds, &Writefds, 0, &timeout) failed, errno=%d\n", 90 lc, errno); 91 } else { 92 tst_resm(TPASS, 93 "select(5, &Readfds, &Writefds, 0, &timeout) timeout = %ld usecs", 94 test_time); 95 } 96 97 } 98 99 tst_exit(); 100 } 101 102 static void setup(void) 103 { 104 tst_sig(FORK, DEF_HANDLER, NULL); 105 106 TEST_PAUSE; 107 108 SAFE_PIPE(NULL, Fd); 109 110 FD_ZERO(&saved_Readfds); 111 FD_ZERO(&saved_Writefds); 112 FD_SET(Fd[0], &saved_Readfds); 113 FD_SET(Fd[1], &saved_Writefds); 114 } 115