blob: 69611bc6209208ff07f3028cd17577d365f28648 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, 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 */
subrata_modak56207ce2009-03-23 13:35:39 +000033/* $Id: select03.c,v 1.6 2009/03/23 13:36:02 subrata_modak Exp $ */
plars865695b2001-08-27 22:15:12 +000034/**********************************************************
35 *
36 * OS Test - Silicon Graphics, Inc.
37 *
38 * TEST IDENTIFIER : select03
39 *
40 * EXECUTED BY : anyone
41 *
42 * TEST TITLE : select of fd of a named-pipe (FIFO)
43 *
44 * PARENT DOCUMENT : usctpl01
45 *
46 * TEST CASE TOTAL : 1
47 *
48 * WALL CLOCK TIME : 1
49 *
50 * CPU TYPES : ALL
51 *
52 * AUTHOR : Richard Logan
53 *
54 * CO-PILOT : Glen Overby
55 *
56 * DATE STARTED : 02/24/93
57 *
58 * INITIAL RELEASE : UNICOS 7.0
59 *
60 * TEST CASES
61 *
62 * 1.) select(2) of fd of a named-pipe (FIFO) with no I/O and small timeout value
63 *
64 * INPUT SPECIFICATIONS
65 * The standard options for system call tests are accepted.
66 * (See the parse_opts(3) man page).
67 *
68 * OUTPUT SPECIFICATIONS
69 *
70 * DURATION
71 * Terminates - with frequency and infinite modes.
72 *
73 * SIGNALS
74 * Uses SIGUSR1 to pause before test if option set.
75 * (See the parse_opts(3) man page).
76 *
77 * RESOURCES
78 * None
79 *
80 * ENVIRONMENTAL NEEDS
81 * No run-time environmental needs.
82 *
83 * SPECIAL PROCEDURAL REQUIREMENTS
84 * None
85 *
86 * INTERCASE DEPENDENCIES
87 * None
88 *
89 * DETAILED DESCRIPTION
90 * This is a Phase I test for the select(2) system call. It is intended
91 * to provide a limited exposure of the system call, for now.
92 *
93 * Setup:
94 * Setup signal handling.
95 * Pause for SIGUSR1 if option specified.
96 *
97 * Test:
98 * Loop if the proper options are given.
99 * Execute system call
100 * Check return code, if system call failed (return=-1)
101 * Log the errno and Issue a FAIL message.
102 * Otherwise, Issue a PASS message.
103 *
104 * Cleanup:
105 * Print errno log and/or timing stats if options given
106 *
107 *
108 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
109
110#include <errno.h>
111#include <signal.h>
subrata_modak56207ce2009-03-23 13:35:39 +0000112#include <fcntl.h> /* For open system call parameters. */
plars865695b2001-08-27 22:15:12 +0000113#include <signal.h>
114#include <sys/param.h>
115#include <sys/types.h>
116#include <sys/time.h>
117#include <sys/stat.h>
118
plars865695b2001-08-27 22:15:12 +0000119#include "test.h"
120#include "usctest.h"
121
122#define FILENAME "select03"
123
vapieraa354722006-05-26 06:26:37 +0000124void setup();
125void cleanup();
plars865695b2001-08-27 22:15:12 +0000126
subrata_modak56207ce2009-03-23 13:35:39 +0000127char *TCID = "select03"; /* Test program identifier. */
128int TST_TOTAL = 1; /* Total number of test cases. */
plars865695b2001-08-27 22:15:12 +0000129extern int Tst_count; /* Test Case counter for tst_* routines */
130
131int Fd;
132fd_set saved_Readfds, saved_Writefds;
133fd_set Readfds, Writefds;
134
plars865695b2001-08-27 22:15:12 +0000135/***********************************************************************
136 * MAIN
137 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000138int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000139{
subrata_modak56207ce2009-03-23 13:35:39 +0000140 int lc; /* loop counter */
141 char *msg; /* message returned from parse_opts */
142 struct timeval timeout;
143 long test_time = 0; /* in usecs */
plars865695b2001-08-27 22:15:12 +0000144
145 /***************************************************************
146 * parse standard options, and exit if there is an error
147 ***************************************************************/
Garrett Coopere1f008e2010-12-14 00:21:59 -0800148 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000149 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
150 tst_exit();
151 }
plars865695b2001-08-27 22:15:12 +0000152
153 /***************************************************************
154 * perform global setup for test
155 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000156 setup();
plars865695b2001-08-27 22:15:12 +0000157
158 /***************************************************************
159 * check looping state if -c option given
160 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000161 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000162
subrata_modak56207ce2009-03-23 13:35:39 +0000163 /* reset Tst_count in case we are looping. */
164 Tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000165
subrata_modak56207ce2009-03-23 13:35:39 +0000166 /*
167 * Assigning the specified seconds within the timeval structure.
168 */
plars865695b2001-08-27 22:15:12 +0000169
subrata_modak56207ce2009-03-23 13:35:39 +0000170 test_time = ((lc % 2000) * 100000); /* 100 milli-seconds */
subrata_modakbdbaec52009-02-26 12:14:51 +0000171
subrata_modak56207ce2009-03-23 13:35:39 +0000172 /*
173 * Bound the time to a value less than 60 seconds
174 */
plars865695b2001-08-27 22:15:12 +0000175
subrata_modak56207ce2009-03-23 13:35:39 +0000176 if (test_time > 1000000 * 60)
177 test_time = test_time % (1000000 * 60);
plars865695b2001-08-27 22:15:12 +0000178
subrata_modak56207ce2009-03-23 13:35:39 +0000179 timeout.tv_sec = test_time / 1000000;
180 timeout.tv_usec = test_time - (timeout.tv_sec * 1000000);
plars865695b2001-08-27 22:15:12 +0000181
subrata_modak56207ce2009-03-23 13:35:39 +0000182 Readfds = saved_Readfds;
183 Writefds = saved_Writefds;
plars865695b2001-08-27 22:15:12 +0000184
subrata_modak56207ce2009-03-23 13:35:39 +0000185 /* Call the system call being tested. */
plars865695b2001-08-27 22:15:12 +0000186
subrata_modak56207ce2009-03-23 13:35:39 +0000187 TEST(select(5, &Readfds, &Writefds, 0, &timeout));
subrata_modakbdbaec52009-02-26 12:14:51 +0000188
subrata_modak56207ce2009-03-23 13:35:39 +0000189 /* check return code */
190 if (TEST_RETURN == -1) {
191 TEST_ERROR_LOG(TEST_ERRNO);
192 tst_resm(TFAIL,
193 "%d select(5, &Readfds, &Writefds, 0, &timeout) failed errno=%d\n",
194 lc, errno);
195 } else {
plars865695b2001-08-27 22:15:12 +0000196
197 /***************************************************************
198 * only perform functional verification if flag set (-f not given)
199 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000200 if (STD_FUNCTIONAL_TEST) {
201 /* Perform functional verification here */
202 tst_resm(TPASS,
203 "select(5, &Readfds, &Writefds, 0, &timeout) timeout = %ld usecs",
204 test_time);
205 }
206 }
plars865695b2001-08-27 22:15:12 +0000207
subrata_modak56207ce2009-03-23 13:35:39 +0000208 } /* End for TEST_LOOPING */
plars865695b2001-08-27 22:15:12 +0000209
210 /***************************************************************
211 * cleanup and exit
212 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000213 cleanup();
plars865695b2001-08-27 22:15:12 +0000214
subrata_modak56207ce2009-03-23 13:35:39 +0000215 return 0;
216} /* End main */
plars865695b2001-08-27 22:15:12 +0000217
218/***************************************************************
219 * setup() - performs all ONE TIME setup for this test.
220 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000221void setup()
plars865695b2001-08-27 22:15:12 +0000222{
subrata_modak56207ce2009-03-23 13:35:39 +0000223 /* capture signals */
224 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000225
subrata_modak56207ce2009-03-23 13:35:39 +0000226 /* Pause if that option was specified */
227 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000228
subrata_modak56207ce2009-03-23 13:35:39 +0000229 /* create a temporary directory and go to it */
230 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +0000231
subrata_modak56207ce2009-03-23 13:35:39 +0000232 /* make and open FIFO */
233 if (mkfifo(FILENAME, 0777) == -1) {
234 tst_brkm(TBROK, cleanup, "mkfifo(%s, 0777) failed, errno=%d",
235 FILENAME, errno);
236 }
plars865695b2001-08-27 22:15:12 +0000237
subrata_modak56207ce2009-03-23 13:35:39 +0000238 if ((Fd = open(FILENAME, O_RDWR)) == -1) {
239 tst_brkm(TBROK, cleanup, "open(%s, O_RDWR) failed, errno=%d",
240 FILENAME, errno);
241 }
plars865695b2001-08-27 22:15:12 +0000242
subrata_modak56207ce2009-03-23 13:35:39 +0000243 /*
244 * Initializing and assigning the standard output file descriptor to
245 * fd_set for select.
246 */
plars865695b2001-08-27 22:15:12 +0000247
subrata_modak56207ce2009-03-23 13:35:39 +0000248 FD_ZERO(&saved_Readfds);
249 FD_ZERO(&saved_Writefds);
250 FD_SET(Fd, &saved_Readfds);
251 FD_SET(Fd, &saved_Writefds);
plars865695b2001-08-27 22:15:12 +0000252
subrata_modak56207ce2009-03-23 13:35:39 +0000253} /* End setup() */
plars865695b2001-08-27 22:15:12 +0000254
255/***************************************************************
256 * cleanup() - performs all ONE TIME cleanup for this test at
257 * completion or premature exit.
258 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000259void cleanup()
plars865695b2001-08-27 22:15:12 +0000260{
subrata_modak56207ce2009-03-23 13:35:39 +0000261 /*
262 * print timing stats if that option was specified.
263 * print errno log if that option was specified.
264 */
265 close(Fd);
mridge1fcfd872004-08-25 16:21:16 +0000266
subrata_modak56207ce2009-03-23 13:35:39 +0000267 TEST_CLEANUP;
plars865695b2001-08-27 22:15:12 +0000268
subrata_modak56207ce2009-03-23 13:35:39 +0000269 /* remove temporary directory and all files in it. */
270 tst_rmdir();
plars865695b2001-08-27 22:15:12 +0000271
subrata_modak56207ce2009-03-23 13:35:39 +0000272 /* exit with return code appropriate for results */
273 tst_exit();
274} /* End cleanup() */