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 |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | |
| 121 | #define FILENAME "select03" |
| 122 | |
vapier | aa35472 | 2006-05-26 06:26:37 +0000 | [diff] [blame] | 123 | void setup(); |
| 124 | void cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 125 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 126 | char *TCID = "select03"; |
| 127 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 128 | |
| 129 | int Fd; |
| 130 | fd_set saved_Readfds, saved_Writefds; |
| 131 | fd_set Readfds, Writefds; |
| 132 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | /*********************************************************************** |
| 134 | * MAIN |
| 135 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 137 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 138 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 139 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 140 | struct timeval timeout; |
| 141 | long test_time = 0; /* in usecs */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 142 | |
| 143 | /*************************************************************** |
| 144 | * parse standard options, and exit if there is an error |
| 145 | ***************************************************************/ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 146 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 147 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 148 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 149 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 150 | |
| 151 | /*************************************************************** |
| 152 | * perform global setup for test |
| 153 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 154 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 155 | |
| 156 | /*************************************************************** |
| 157 | * check looping state if -c option given |
| 158 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 159 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 160 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 161 | tst_count = 0; |
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 | /* |
| 164 | * Assigning the specified seconds within the timeval structure. |
| 165 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 166 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 167 | test_time = ((lc % 2000) * 100000); /* 100 milli-seconds */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 168 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 169 | /* |
| 170 | * Bound the time to a value less than 60 seconds |
| 171 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 172 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 173 | if (test_time > 1000000 * 60) |
| 174 | test_time = test_time % (1000000 * 60); |
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 | timeout.tv_sec = test_time / 1000000; |
| 177 | timeout.tv_usec = test_time - (timeout.tv_sec * 1000000); |
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 | Readfds = saved_Readfds; |
| 180 | Writefds = saved_Writefds; |
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 | /* Call the system call being tested. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 183 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 184 | TEST(select(5, &Readfds, &Writefds, 0, &timeout)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 185 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 186 | /* check return code */ |
| 187 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 188 | tst_resm(TFAIL, |
| 189 | "%d select(5, &Readfds, &Writefds, 0, &timeout) failed errno=%d\n", |
| 190 | lc, errno); |
| 191 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 192 | tst_resm(TPASS, |
| 193 | "select(5, &Readfds, &Writefds, 0, &timeout) timeout = %ld usecs", |
| 194 | test_time); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 195 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 196 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 197 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 198 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 199 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 200 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 201 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 202 | |
| 203 | /*************************************************************** |
| 204 | * setup() - performs all ONE TIME setup for this test. |
| 205 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 206 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 207 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 208 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 209 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 210 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 211 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 212 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 213 | /* create a temporary directory and go to it */ |
| 214 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 215 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 216 | /* make and open FIFO */ |
| 217 | if (mkfifo(FILENAME, 0777) == -1) { |
| 218 | tst_brkm(TBROK, cleanup, "mkfifo(%s, 0777) failed, errno=%d", |
| 219 | FILENAME, errno); |
| 220 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 221 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 222 | if ((Fd = open(FILENAME, O_RDWR)) == -1) { |
| 223 | tst_brkm(TBROK, cleanup, "open(%s, O_RDWR) failed, errno=%d", |
| 224 | FILENAME, errno); |
| 225 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 226 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 227 | /* |
| 228 | * Initializing and assigning the standard output file descriptor to |
| 229 | * fd_set for select. |
| 230 | */ |
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 | FD_ZERO(&saved_Readfds); |
| 233 | FD_ZERO(&saved_Writefds); |
| 234 | FD_SET(Fd, &saved_Readfds); |
| 235 | FD_SET(Fd, &saved_Writefds); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 236 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 237 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 238 | |
| 239 | /*************************************************************** |
| 240 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 241 | * completion or premature exit. |
| 242 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 243 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 244 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 245 | /* |
| 246 | * print timing stats if that option was specified. |
| 247 | * print errno log if that option was specified. |
| 248 | */ |
| 249 | close(Fd); |
mridge | 1fcfd87 | 2004-08-25 16:21:16 +0000 | [diff] [blame] | 250 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 251 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 252 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 253 | } |