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 | */ |
vapier | c450e06 | 2009-08-28 14:28:52 +0000 | [diff] [blame] | 33 | /* $Id: select01.c,v 1.6 2009/08/28 14:32:05 vapier Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | /********************************************************** |
| 35 | * |
| 36 | * OS Test - Silicon Graphics, Inc. |
| 37 | * |
| 38 | * TEST IDENTIFIER : select01 |
| 39 | * |
| 40 | * EXECUTED BY : anyone |
| 41 | * |
| 42 | * TEST TITLE : select to a file |
| 43 | * |
| 44 | * PARENT DOCUMENT : usctpl01 |
| 45 | * |
| 46 | * TEST CASE TOTAL : 3 |
| 47 | * |
| 48 | * WALL CLOCK TIME : 1 |
| 49 | * |
| 50 | * CPU TYPES : ALL |
| 51 | * |
| 52 | * AUTHOR : Richard Logan |
| 53 | * |
| 54 | * CO-PILOT : William Roske |
| 55 | * |
| 56 | * DATE STARTED : 02/24/93 |
| 57 | * |
| 58 | * INITIAL RELEASE : UNICOS 7.0 |
| 59 | * |
| 60 | * TEST CASES |
| 61 | * |
| 62 | * 1.) select(2) to a fd of regular file 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. It |
| 92 | * should/will be extended when full functional tests are written for |
| 93 | * join(2). |
| 94 | * |
| 95 | * Setup: |
| 96 | * Setup signal handling. |
| 97 | * Pause for SIGUSR1 if option specified. |
| 98 | * |
| 99 | * Test: |
| 100 | * Loop if the proper options are given. |
| 101 | * Execute system call |
| 102 | * Check return code, if system call failed (return=-1) |
| 103 | * Log the errno and Issue a FAIL message. |
| 104 | * Otherwise, Issue a PASS message. |
| 105 | * |
| 106 | * Cleanup: |
| 107 | * Print errno log and/or timing stats if options given |
| 108 | * |
| 109 | * |
| 110 | *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ |
| 111 | |
| 112 | #include <errno.h> |
| 113 | #include <signal.h> |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 114 | #include <fcntl.h> /* For open system call parameters. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 115 | #include <signal.h> |
| 116 | #include <string.h> |
| 117 | #include <sys/param.h> |
| 118 | #include <sys/types.h> |
| 119 | #include <sys/time.h> |
| 120 | |
| 121 | #include "test.h" |
| 122 | #include "usctest.h" |
| 123 | |
| 124 | #define FILENAME "select01" |
| 125 | |
| 126 | void setup(); |
| 127 | void cleanup(); |
| 128 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 129 | char *TCID = "select01"; /* Test program identifier. */ |
| 130 | int TST_TOTAL = 1; /* Total number of test cases. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | int Fd = -1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | fd_set Readfds; |
| 134 | |
| 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 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 140 | int lc; |
| 141 | char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 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 | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 148 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 149 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 150 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 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 | Tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 164 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 165 | /* |
| 166 | * Assigning the specified seconds within the timeval structure. |
| 167 | */ |
| 168 | test_time = ((lc % 2000) * 100000); /* 100 milli-seconds */ |
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 | /* |
| 171 | * Bound the time to a value less than 60 seconds |
| 172 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 173 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 174 | if (test_time > 1000000 * 60) |
| 175 | test_time = test_time % (1000000 * 60); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 176 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 177 | timeout.tv_sec = test_time / 1000000; |
| 178 | timeout.tv_usec = test_time - (timeout.tv_sec * 1000000); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 179 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 180 | /* Call the system call being tested. */ |
| 181 | TEST(select(4, &Readfds, 0, 0, &timeout)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 182 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 183 | /* check return code */ |
| 184 | if (TEST_RETURN == -1) { |
| 185 | TEST_ERROR_LOG(TEST_ERRNO); |
| 186 | tst_resm(TFAIL, |
| 187 | "%d select(4, &Readfds, 0, 0, &timeout), timeout = %ld usecs, errno=%d", |
| 188 | lc, test_time, errno); |
| 189 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 190 | |
| 191 | /*************************************************************** |
| 192 | * only perform functional verification if flag set (-f not given) |
| 193 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 194 | if (STD_FUNCTIONAL_TEST) { |
| 195 | /* Perform functional verification here */ |
| 196 | tst_resm(TPASS, |
| 197 | "select(4, &Readfds, 0, 0, &timeout) timeout = %ld usecs", |
| 198 | test_time); |
| 199 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 200 | |
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 | * cleanup and exit |
| 205 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 206 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 207 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 208 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 209 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 210 | |
| 211 | /*************************************************************** |
| 212 | * setup() - performs all ONE TIME setup for this test. |
| 213 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 214 | void setup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 215 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 216 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 217 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 218 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 219 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 220 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 221 | /* create a temporary directory and go to it */ |
| 222 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 223 | |
vapier | c450e06 | 2009-08-28 14:28:52 +0000 | [diff] [blame] | 224 | if ((Fd = open(FILENAME, O_CREAT | O_RDWR, 0777)) == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 225 | tst_brkm(TBROK | TERRNO, cleanup, |
vapier | c450e06 | 2009-08-28 14:28:52 +0000 | [diff] [blame] | 226 | "open(%s, O_CREAT | O_RDWR) failed", FILENAME); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 227 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 228 | /* |
| 229 | * Initializing and assigning the standard output file descriptor to |
| 230 | * fd_set for select. |
| 231 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 232 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 233 | FD_ZERO(&Readfds); |
| 234 | FD_SET(Fd, &Readfds); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 235 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 236 | |
| 237 | /*************************************************************** |
| 238 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 239 | * completion or premature exit. |
| 240 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 241 | void cleanup() |
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 | * print timing stats if that option was specified. |
| 245 | * print errno log if that option was specified. |
| 246 | */ |
| 247 | TEST_CLEANUP; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 248 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 249 | if (Fd >= 0) { |
vapier | c450e06 | 2009-08-28 14:28:52 +0000 | [diff] [blame] | 250 | if (close(Fd) == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 251 | tst_resm(TWARN | TERRNO, "close(%s) failed", FILENAME); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 252 | Fd = -1; |
| 253 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 254 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 255 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 256 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 257 | } |