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
47 #include "test.h"
48 #include "safe_macros.h"
49 #include "select.h"
50
51 static void setup(void);
52
53 char *TCID = SELECT_TEST_FILENAME("select02");
54 int TST_TOTAL = 1;
55
56 int Fd[2];
57 fd_set saved_Readfds, saved_Writefds;
58 fd_set Readfds, Writefds;
59
main(int ac,char ** av)60 int main(int ac, char **av)
61 {
62 int lc;
63 struct timeval timeout;
64 long test_time = 0; /* in usecs */
65
66 tst_parse_opts(ac, av, NULL, NULL);
67
68 setup();
69
70 for (lc = 0; TEST_LOOPING(lc); lc++) {
71 tst_count = 0;
72
73 test_time = ((lc % 2000) * 100000); /* 100 milli-seconds */
74
75 if (test_time > 1000000 * 60)
76 test_time = test_time % (1000000 * 60);
77
78 timeout.tv_sec = test_time / 1000000;
79 timeout.tv_usec = test_time - (timeout.tv_sec * 1000000);
80
81 Readfds = saved_Readfds;
82 Writefds = saved_Writefds;
83
84 TEST(select(5, &Readfds, &Writefds, 0, &timeout));
85
86 if (TEST_RETURN == -1) {
87 tst_resm(TFAIL,
88 "%d select(5, &Readfds, &Writefds, 0, &timeout) failed, errno=%d\n",
89 lc, errno);
90 } else {
91 tst_resm(TPASS,
92 "select(5, &Readfds, &Writefds, 0, &timeout) timeout = %ld usecs",
93 test_time);
94 }
95
96 }
97
98 tst_exit();
99 }
100
setup(void)101 static void setup(void)
102 {
103 tst_sig(FORK, DEF_HANDLER, NULL);
104
105 TEST_PAUSE;
106
107 SAFE_PIPE(NULL, Fd);
108
109 FD_ZERO(&saved_Readfds);
110 FD_ZERO(&saved_Writefds);
111 FD_SET(Fd[0], &saved_Readfds);
112 FD_SET(Fd[1], &saved_Writefds);
113 }
114