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 #include <sys/types.h>
47 #include <sys/time.h>
48
49 #include "test.h"
50
51 #define FILENAME "select01"
52
53 static void setup(void);
54 static void cleanup(void);
55
56 char *TCID = "select01";
57 int TST_TOTAL = 1;
58
59 int Fd = -1;
60 fd_set Readfds;
61
main(int ac,char ** av)62 int main(int ac, char **av)
63 {
64 int lc;
65 struct timeval timeout;
66 long test_time = 0; /* in usecs */
67
68 tst_parse_opts(ac, av, NULL, NULL);
69
70 setup();
71
72 for (lc = 0; TEST_LOOPING(lc); lc++) {
73 tst_count = 0;
74
75 test_time = ((lc % 2000) * 100000); /* 100 milli-seconds */
76
77 if (test_time > 1000000 * 60)
78 test_time = test_time % (1000000 * 60);
79
80 timeout.tv_sec = test_time / 1000000;
81 timeout.tv_usec = test_time - (timeout.tv_sec * 1000000);
82
83 TEST(select(4, &Readfds, 0, 0, &timeout));
84
85 if (TEST_RETURN == -1) {
86 tst_resm(TFAIL,
87 "%d select(4, &Readfds, 0, 0, &timeout), timeout = %ld usecs, errno=%d",
88 lc, test_time, errno);
89 }
90
91 tst_resm(TPASS,
92 "select(4, &Readfds, 0, 0, &timeout) timeout = %ld usecs",
93 test_time);
94
95 }
96
97 cleanup();
98 tst_exit();
99 }
100
setup(void)101 static void setup(void)
102 {
103 tst_sig(FORK, DEF_HANDLER, cleanup);
104
105 TEST_PAUSE;
106
107 tst_tmpdir();
108
109 if ((Fd = open(FILENAME, O_CREAT | O_RDWR, 0777)) == -1)
110 tst_brkm(TBROK | TERRNO, cleanup,
111 "open(%s, O_CREAT | O_RDWR) failed", FILENAME);
112
113 FD_ZERO(&Readfds);
114 FD_SET(Fd, &Readfds);
115 }
116
cleanup(void)117 static void cleanup(void)
118 {
119 if (Fd >= 0) {
120 if (close(Fd) == -1)
121 tst_resm(TWARN | TERRNO, "close(%s) failed", FILENAME);
122 Fd = -1;
123 }
124
125 tst_rmdir();
126 }
127