• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *      1.) select(2) of fd of a named-pipe (FIFO) with no I/O and small timeout value
39  */
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 #include <sys/stat.h>
49 
50 #include "test.h"
51 #include "safe_macros.h"
52 
53 #define FILENAME	"select03"
54 
55 static void setup(void);
56 static void cleanup(void);
57 
58 char *TCID = "select03";
59 int TST_TOTAL = 1;
60 
61 int Fd;
62 fd_set saved_Readfds, saved_Writefds;
63 fd_set Readfds, Writefds;
64 
main(int ac,char ** av)65 int main(int ac, char **av)
66 {
67 	int lc;
68 	struct timeval timeout;
69 	long test_time = 0;	/* in usecs */
70 
71 	tst_parse_opts(ac, av, NULL, NULL);
72 
73 	setup();
74 
75 	for (lc = 0; TEST_LOOPING(lc); lc++) {
76 
77 		tst_count = 0;
78 
79 		test_time = ((lc % 2000) * 100000);	/* 100 milli-seconds */
80 
81 		if (test_time > 1000000 * 60)
82 			test_time = test_time % (1000000 * 60);
83 
84 		timeout.tv_sec = test_time / 1000000;
85 		timeout.tv_usec = test_time - (timeout.tv_sec * 1000000);
86 
87 		Readfds = saved_Readfds;
88 		Writefds = saved_Writefds;
89 
90 		TEST(select(5, &Readfds, &Writefds, 0, &timeout));
91 
92 		if (TEST_RETURN == -1) {
93 			tst_resm(TFAIL,
94 				 "%d select(5, &Readfds, &Writefds, 0, &timeout) failed errno=%d\n",
95 				 lc, errno);
96 		} else {
97 			tst_resm(TPASS,
98 				 "select(5, &Readfds, &Writefds, 0, &timeout) timeout = %ld usecs",
99 				 test_time);
100 		}
101 
102 	}
103 
104 	cleanup();
105 	tst_exit();
106 }
107 
setup(void)108 static void setup(void)
109 {
110 
111 	tst_sig(FORK, DEF_HANDLER, cleanup);
112 
113 	TEST_PAUSE;
114 
115 	tst_tmpdir();
116 
117 	SAFE_MKFIFO(cleanup, FILENAME, 0777);
118 
119 	if ((Fd = open(FILENAME, O_RDWR)) == -1) {
120 		tst_brkm(TBROK, cleanup, "open(%s, O_RDWR) failed, errno=%d",
121 			 FILENAME, errno);
122 	}
123 
124 	FD_ZERO(&saved_Readfds);
125 	FD_ZERO(&saved_Writefds);
126 	FD_SET(Fd, &saved_Readfds);
127 	FD_SET(Fd, &saved_Writefds);
128 }
129 
cleanup(void)130 static void cleanup(void)
131 {
132 	close(Fd);
133 	tst_rmdir();
134 }
135