plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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., 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 33 | /* $Id: select03.c,v 1.6 2009/03/23 13:36:02 subrata_modak Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | /********************************************************** |
| 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 112 | #include <fcntl.h> /* For open system call parameters. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 113 | #include <signal.h> |
| 114 | #include <sys/param.h> |
| 115 | #include <sys/types.h> |
| 116 | #include <sys/time.h> |
| 117 | #include <sys/stat.h> |
| 118 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | #include "test.h" |
| 120 | #include "usctest.h" |
| 121 | |
| 122 | #define FILENAME "select03" |
| 123 | |
vapier | aa35472 | 2006-05-26 06:26:37 +0000 | [diff] [blame] | 124 | void setup(); |
| 125 | void cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 127 | char *TCID = "select03"; /* Test program identifier. */ |
| 128 | int TST_TOTAL = 1; /* Total number of test cases. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 129 | extern int Tst_count; /* Test Case counter for tst_* routines */ |
| 130 | |
| 131 | int Fd; |
| 132 | fd_set saved_Readfds, saved_Writefds; |
| 133 | fd_set Readfds, Writefds; |
| 134 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 135 | /*********************************************************************** |
| 136 | * MAIN |
| 137 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 140 | int lc; /* loop counter */ |
| 141 | char *msg; /* message returned from parse_opts */ |
| 142 | struct timeval timeout; |
| 143 | long test_time = 0; /* in usecs */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 144 | |
| 145 | /*************************************************************** |
| 146 | * parse standard options, and exit if there is an error |
| 147 | ***************************************************************/ |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 148 | if ((msg = parse_opts(ac, av, NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 149 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 150 | tst_exit(); |
| 151 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 152 | |
| 153 | /*************************************************************** |
| 154 | * perform global setup for test |
| 155 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 156 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 157 | |
| 158 | /*************************************************************** |
| 159 | * check looping state if -c option given |
| 160 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 161 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 162 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 163 | /* reset Tst_count in case we are looping. */ |
| 164 | Tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 165 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 166 | /* |
| 167 | * Assigning the specified seconds within the timeval structure. |
| 168 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 169 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 170 | test_time = ((lc % 2000) * 100000); /* 100 milli-seconds */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 171 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 172 | /* |
| 173 | * Bound the time to a value less than 60 seconds |
| 174 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 175 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 176 | if (test_time > 1000000 * 60) |
| 177 | test_time = test_time % (1000000 * 60); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 178 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 179 | timeout.tv_sec = test_time / 1000000; |
| 180 | timeout.tv_usec = test_time - (timeout.tv_sec * 1000000); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 181 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 182 | Readfds = saved_Readfds; |
| 183 | Writefds = saved_Writefds; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 184 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 185 | /* Call the system call being tested. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 186 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 187 | TEST(select(5, &Readfds, &Writefds, 0, &timeout)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 188 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 189 | /* 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 { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 196 | |
| 197 | /*************************************************************** |
| 198 | * only perform functional verification if flag set (-f not given) |
| 199 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 200 | 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 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 207 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 208 | } /* End for TEST_LOOPING */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 209 | |
| 210 | /*************************************************************** |
| 211 | * cleanup and exit |
| 212 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 213 | cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 214 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 215 | return 0; |
| 216 | } /* End main */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 217 | |
| 218 | /*************************************************************** |
| 219 | * setup() - performs all ONE TIME setup for this test. |
| 220 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 221 | void setup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 222 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 223 | /* capture signals */ |
| 224 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 225 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 226 | /* Pause if that option was specified */ |
| 227 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 228 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 229 | /* create a temporary directory and go to it */ |
| 230 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 231 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 232 | /* 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 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 237 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 238 | if ((Fd = open(FILENAME, O_RDWR)) == -1) { |
| 239 | tst_brkm(TBROK, cleanup, "open(%s, O_RDWR) failed, errno=%d", |
| 240 | FILENAME, errno); |
| 241 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 242 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 243 | /* |
| 244 | * Initializing and assigning the standard output file descriptor to |
| 245 | * fd_set for select. |
| 246 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 247 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 248 | FD_ZERO(&saved_Readfds); |
| 249 | FD_ZERO(&saved_Writefds); |
| 250 | FD_SET(Fd, &saved_Readfds); |
| 251 | FD_SET(Fd, &saved_Writefds); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 252 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 253 | } /* End setup() */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 254 | |
| 255 | /*************************************************************** |
| 256 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 257 | * completion or premature exit. |
| 258 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 259 | void cleanup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 260 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 261 | /* |
| 262 | * print timing stats if that option was specified. |
| 263 | * print errno log if that option was specified. |
| 264 | */ |
| 265 | close(Fd); |
mridge | 1fcfd87 | 2004-08-25 16:21:16 +0000 | [diff] [blame] | 266 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 267 | TEST_CLEANUP; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 268 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 269 | /* remove temporary directory and all files in it. */ |
| 270 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 271 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 272 | /* exit with return code appropriate for results */ |
| 273 | tst_exit(); |
| 274 | } /* End cleanup() */ |