blob: 6aad8b2160e807385c2cef48067f0d176dd10e04 [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
Wanlong Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000022 *
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: select02.c,v 1.4 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 : select02
39 *
40 * EXECUTED BY : anyone
41 *
42 * TEST TITLE : select of system pipe fds
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) to fd of system pipe with no I/O and small timeout
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#include <errno.h>
110#include <signal.h>
subrata_modak56207ce2009-03-23 13:35:39 +0000111#include <fcntl.h> /* For open system call parameters. */
plars865695b2001-08-27 22:15:12 +0000112#include <signal.h>
113#include <sys/param.h>
114#include <sys/types.h>
115#include <sys/time.h>
116
117#include "test.h"
plars865695b2001-08-27 22:15:12 +0000118
119void setup();
120void cleanup();
121
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200122char *TCID = "select02";
123int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +0000124
125int Fd[2];
126fd_set saved_Readfds, saved_Writefds;
127fd_set Readfds, Writefds;
128
129/***********************************************************************
130 * MAIN
131 ***********************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000132int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000133{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200134 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200135 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +0000136 struct timeval timeout;
137 long test_time = 0; /* in usecs */
plars865695b2001-08-27 22:15:12 +0000138
139 /***************************************************************
140 * parse standard options, and exit if there is an error
141 ***************************************************************/
Garrett Cooper45e285d2010-11-22 12:19:25 -0800142 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000143 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -0800144
subrata_modak56207ce2009-03-23 13:35:39 +0000145 }
plars865695b2001-08-27 22:15:12 +0000146
147 /***************************************************************
148 * perform global setup for test
149 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000150 setup();
plars865695b2001-08-27 22:15:12 +0000151
152 /***************************************************************
153 * check looping state if -c option given
154 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000155 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000156
Caspar Zhangd59a6592013-03-07 14:59:12 +0800157 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000158
subrata_modak56207ce2009-03-23 13:35:39 +0000159 /*
160 * Assigning the specified seconds within the timeval structure.
161 */
plars865695b2001-08-27 22:15:12 +0000162
subrata_modak56207ce2009-03-23 13:35:39 +0000163 test_time = ((lc % 2000) * 100000); /* 100 milli-seconds */
plars865695b2001-08-27 22:15:12 +0000164
subrata_modak56207ce2009-03-23 13:35:39 +0000165 /*
166 * Bound the time to a value less than 60 seconds
167 */
plars865695b2001-08-27 22:15:12 +0000168
subrata_modak56207ce2009-03-23 13:35:39 +0000169 if (test_time > 1000000 * 60)
170 test_time = test_time % (1000000 * 60);
plars865695b2001-08-27 22:15:12 +0000171
subrata_modak56207ce2009-03-23 13:35:39 +0000172 timeout.tv_sec = test_time / 1000000;
173 timeout.tv_usec = test_time - (timeout.tv_sec * 1000000);
plars865695b2001-08-27 22:15:12 +0000174
subrata_modak56207ce2009-03-23 13:35:39 +0000175 Readfds = saved_Readfds;
176 Writefds = saved_Writefds;
plars865695b2001-08-27 22:15:12 +0000177
subrata_modak56207ce2009-03-23 13:35:39 +0000178 /* Call the system call being tested. */
plars865695b2001-08-27 22:15:12 +0000179
subrata_modak56207ce2009-03-23 13:35:39 +0000180 TEST(select(5, &Readfds, &Writefds, 0, &timeout));
subrata_modakbdbaec52009-02-26 12:14:51 +0000181
subrata_modak56207ce2009-03-23 13:35:39 +0000182 /* check return code */
183 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000184 tst_resm(TFAIL,
185 "%d select(5, &Readfds, &Writefds, 0, &timeout) failed, errno=%d\n",
186 lc, errno);
187 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200188 tst_resm(TPASS,
189 "select(5, &Readfds, &Writefds, 0, &timeout) timeout = %ld usecs",
190 test_time);
subrata_modak56207ce2009-03-23 13:35:39 +0000191 }
plars865695b2001-08-27 22:15:12 +0000192
Garrett Cooper2c282152010-12-16 00:55:50 -0800193 }
plars865695b2001-08-27 22:15:12 +0000194
subrata_modak56207ce2009-03-23 13:35:39 +0000195 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800196 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800197}
plars865695b2001-08-27 22:15:12 +0000198
199/***************************************************************
200 * setup() - performs all ONE TIME setup for this test.
201 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400202void setup(void)
plars865695b2001-08-27 22:15:12 +0000203{
Garrett Cooper2c282152010-12-16 00:55:50 -0800204
subrata_modak56207ce2009-03-23 13:35:39 +0000205 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000206
subrata_modak56207ce2009-03-23 13:35:39 +0000207 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000208
subrata_modak56207ce2009-03-23 13:35:39 +0000209 /* create a temporary directory and go to it */
210 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +0000211
subrata_modak56207ce2009-03-23 13:35:39 +0000212 if (pipe(Fd) == -1) {
213 tst_brkm(TBROK, cleanup, "pipe(&Fd) failed, errno=%d", errno);
214 }
plars865695b2001-08-27 22:15:12 +0000215
subrata_modak56207ce2009-03-23 13:35:39 +0000216 /*
217 * Initializing and assigning the standard output file descriptor to
218 * fd_set for select.
219 */
plars865695b2001-08-27 22:15:12 +0000220
subrata_modak56207ce2009-03-23 13:35:39 +0000221 FD_ZERO(&saved_Readfds);
222 FD_ZERO(&saved_Writefds);
223 FD_SET(Fd[0], &saved_Readfds);
224 FD_SET(Fd[1], &saved_Writefds);
plars865695b2001-08-27 22:15:12 +0000225
Garrett Cooper2c282152010-12-16 00:55:50 -0800226}
plars865695b2001-08-27 22:15:12 +0000227
228/***************************************************************
229 * cleanup() - performs all ONE TIME cleanup for this test at
230 * completion or premature exit.
231 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400232void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000233{
plars865695b2001-08-27 22:15:12 +0000234
subrata_modak56207ce2009-03-23 13:35:39 +0000235 tst_rmdir();
plars865695b2001-08-27 22:15:12 +0000236
Chris Dearmanec6edca2012-10-17 19:54:01 -0700237}