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 * AUTHOR : Richard Logan 34 * CO-PILOT : William Roske 35 * DATE STARTED : 02/24/93 36 * 37 * 1.) select(2) to a fd of regular file with no I/O and small timeout 38 */ 39 40 #include <errno.h> 41 #include <signal.h> 42 #include <fcntl.h> 43 #include <signal.h> 44 #include <string.h> 45 #include <sys/param.h> 46 47 #include "test.h" 48 #include "select.h" 49 50 #define FILENAME SELECT_TEST_FILENAME("select01") 51 52 static void setup(void); 53 static void cleanup(void); 54 55 char *TCID = FILENAME; 56 int TST_TOTAL = 1; 57 58 int Fd = -1; 59 fd_set Readfds; 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 TEST(select(4, &Readfds, 0, 0, &timeout)); 83 84 if (TEST_RETURN == -1) { 85 tst_resm(TFAIL, 86 "%d select(4, &Readfds, 0, 0, &timeout), timeout = %ld usecs, errno=%d", 87 lc, test_time, errno); 88 } 89 90 tst_resm(TPASS, 91 "select(4, &Readfds, 0, 0, &timeout) timeout = %ld usecs", 92 test_time); 93 94 } 95 96 cleanup(); 97 tst_exit(); 98 } 99 100 static void setup(void) 101 { 102 tst_sig(FORK, DEF_HANDLER, cleanup); 103 104 TEST_PAUSE; 105 106 tst_tmpdir(); 107 108 if ((Fd = open(FILENAME, O_CREAT | O_RDWR, 0777)) == -1) 109 tst_brkm(TBROK | TERRNO, cleanup, 110 "open(%s, O_CREAT | O_RDWR) failed", FILENAME); 111 112 FD_ZERO(&Readfds); 113 FD_SET(Fd, &Readfds); 114 } 115 116 static void cleanup(void) 117 { 118 if (Fd >= 0) { 119 if (close(Fd) == -1) 120 tst_resm(TWARN | TERRNO, "close(%s) failed", FILENAME); 121 Fd = -1; 122 } 123 124 tst_rmdir(); 125 } 126