2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 /**********************************************************
36 * OS Test - Silicon Graphics, Inc.
38 * TEST IDENTIFIER : access03
40 * EXECUTED BY : anyone
42 * TEST TITLE : EFAULT error testing for access(2)
44 * PARENT DOCUMENT : acstds01
52 * AUTHOR : Kathy Olmsted
54 * CO-PILOT : Tom Hampson
56 * DATE STARTED : 05/13/92
58 * INITIAL RELEASE : UNICOS 7.0
62 * access(2) test for errno(s) EFAULT.
64 * INPUT SPECIFICATIONS
65 * The standard options for system call tests are accepted.
66 * (See the parse_opts(3) man page).
69 * Terminates - with frequency and infinite modes.
72 * Uses SIGUSR1 to pause before test if option set.
73 * (See the parse_opts(3) man page).
76 * No run-time environmental needs.
78 * DETAILED DESCRIPTION
81 * Setup signal handling.
82 * Make and change to a temporary directory.
83 * Pause for SIGUSR1 if option specified.
86 * Loop if the proper options are given.
88 * Check return code, if system call failed (return=-1)
90 * If doing functional test
91 * check the errno returned and print result message
94 * Print errno log and/or timing stats if options given
95 * Remove the temporary directory and exit.
98 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
110 void cleanup(void) __attribute__((noreturn));
113 char *get_high_address();
115 const char *TCID="access03"; /* Test program identifier. */
116 int TST_TOTAL=8; /* Total number of test cases. */
117 extern int Tst_count; /* Test Case counter for tst_* routines */
119 int exp_enos[]={EFAULT, 0}; /* List must end with 0 */
121 int main(int ac, char **av)
123 int lc; /* loop counter */
124 const char *msg; /* message returned from parse_opts */
128 /***************************************************************
129 * parse standard options
130 ***************************************************************/
131 if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
132 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
134 /***************************************************************
135 * perform global setup for test
136 ***************************************************************/
139 /* set the expected errnos. */
140 TEST_EXP_ENOS(exp_enos);
142 /***************************************************************
143 * check looping state if -c option given
144 ***************************************************************/
145 for (lc=0; TEST_LOOPING(lc); lc++) {
147 /* reset Tst_count in case we are looping. */
153 * R_OK on low pointer (-1) for path
158 TEST(access( (char *)-1,R_OK));
161 /* check return code */
162 if ( TEST_RETURN == -1 ) {
163 TEST_ERROR_LOG(TEST_ERRNO);
166 /***************************************************************
167 * only perform functional verification if flag set (-f not given)
168 ***************************************************************/
169 if ( STD_FUNCTIONAL_TEST ) {
170 if ( TEST_RETURN == -1 ) {
171 if (TEST_ERRNO == EFAULT) {
173 "access((char *)-1,R_OK) failed as expected with errno %d (EFAULT) : %s",
174 TEST_ERRNO, strerror(TEST_ERRNO));
178 "access((char *)-1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
179 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
184 "access((char *)-1,R_OK) succeeded unexpectedly.");
192 * W_OK on low pointer (-1) for path
197 TEST(access( (char *)-1,W_OK));
199 /* check return code */
200 if ( TEST_RETURN == -1 ) {
201 TEST_ERROR_LOG(TEST_ERRNO);
204 /***************************************************************
205 * only perform functional verification if flag set (-f not given)
206 ***************************************************************/
207 if ( STD_FUNCTIONAL_TEST ) {
208 if ( TEST_RETURN == -1 ) {
209 if (TEST_ERRNO == EFAULT) {
211 "access((char *)-1,W_OK) failed as expected with errno %d (EFAULT) : %s",
212 TEST_ERRNO, strerror(TEST_ERRNO));
216 "access((char *)-1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
217 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
222 "access((char *)-1,W_OK) succeeded unexpectedly.");
230 * X_OK on low pointer (-1) for path
235 TEST(access( (char *)-1,X_OK));
238 /* check return code */
239 if ( TEST_RETURN == -1 ) {
240 TEST_ERROR_LOG(TEST_ERRNO);
243 /***************************************************************
244 * only perform functional verification if flag set (-f not given)
245 ***************************************************************/
246 if ( STD_FUNCTIONAL_TEST ) {
247 if ( TEST_RETURN == -1 ) {
248 if (TEST_ERRNO == EFAULT) {
250 "access((char*)-1,X_OK) failed as expected with errno %d (EFAULT) : %s",
251 TEST_ERRNO, strerror(TEST_ERRNO));
255 "access((char*)-1,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
256 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
261 "access((char*)-1,X_OK) succeeded unexpectedly.");
269 * F_OK on low pointer (-1) for path
274 TEST(access( (char *)-1,F_OK));
277 /* check return code */
278 if ( TEST_RETURN == -1 ) {
279 TEST_ERROR_LOG(TEST_ERRNO);
282 /***************************************************************
283 * only perform functional verification if flag set (-f not given)
284 ***************************************************************/
285 if ( STD_FUNCTIONAL_TEST ) {
286 if ( TEST_RETURN == -1 ) {
287 if (TEST_ERRNO == EFAULT) {
289 "access((char*)-1,F_OK) failed as expected with errno %d (EFAULT) : %s",
290 TEST_ERRNO, strerror(TEST_ERRNO));
294 "access((char*)-1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
295 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
300 "access((char*)-1,F_OK) succeeded unexpectedly.");
308 * R_OK on high pointer (sbrk(0)+1) for path
313 TEST(access(get_high_address(),R_OK));
316 /* check return code */
317 if ( TEST_RETURN == -1 ) {
318 TEST_ERROR_LOG(TEST_ERRNO);
321 /***************************************************************
322 * only perform functional verification if flag set (-f not given)
323 ***************************************************************/
324 if ( STD_FUNCTIONAL_TEST ) {
325 if ( TEST_RETURN == -1 ) {
326 if (TEST_ERRNO == EFAULT) {
328 "access((char*)sbrk(0)+1,R_OK) failed as expected with errno %d (EFAULT) : %s",
329 TEST_ERRNO, strerror(TEST_ERRNO));
333 "access((char*)sbrk(0)+1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
334 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
339 "access((char*)sbrk(0)+1,R_OK) succeeded unexpectedly.");
347 * W_OK on high pointer (sbrk(0)+1) for path
352 TEST(access(get_high_address(),W_OK));
355 /* check return code */
356 if ( TEST_RETURN == -1 ) {
357 TEST_ERROR_LOG(TEST_ERRNO);
360 /***************************************************************
361 * only perform functional verification if flag set (-f not given)
362 ***************************************************************/
363 if ( STD_FUNCTIONAL_TEST ) {
364 if ( TEST_RETURN == -1 ) {
365 if (TEST_ERRNO == EFAULT) {
367 "access((char*)sbrk(0)+1,W_OK) failed as expected with errno %d (EFAULT) : %s",
368 TEST_ERRNO, strerror(TEST_ERRNO));
372 "access((char*)sbrk(0)+1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
373 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
378 "access((char*)sbrk(0)+1,W_OK) succeeded unexpectedly.");
386 * X_OK on high pointer (sbrk(0)+1) for path
391 TEST(access(get_high_address(),X_OK));
394 /* check return code */
395 if ( TEST_RETURN == -1 ) {
396 TEST_ERROR_LOG(TEST_ERRNO);
399 /***************************************************************
400 * only perform functional verification if flag set (-f not given)
401 ***************************************************************/
402 if ( STD_FUNCTIONAL_TEST ) {
403 if ( TEST_RETURN == -1 ) {
404 if (TEST_ERRNO == EFAULT) {
406 "access(high_address,X_OK) failed as expected with errno %d (EFAULT) : %s",
407 TEST_ERRNO, strerror(TEST_ERRNO));
411 "access(high_address,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
412 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
417 "access(high_address,X_OK) succeeded unexpectedly.");
425 * F_OK on high pointer (sbrk(0)+1) for path
430 TEST(access(get_high_address(),F_OK));
433 /* check return code */
434 if ( TEST_RETURN == -1 ) {
435 TEST_ERROR_LOG(TEST_ERRNO);
438 /***************************************************************
439 * only perform functional verification if flag set (-f not given)
440 ***************************************************************/
441 if ( STD_FUNCTIONAL_TEST ) {
442 if ( TEST_RETURN == -1 ) {
443 if (TEST_ERRNO == EFAULT) {
445 "access((char*)sbrk(0)+1,F_OK) failed as expected with errno %d (EFAULT) : %s",
446 TEST_ERRNO, strerror(TEST_ERRNO));
450 "access((char*)sbrk(0)+1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
451 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
456 "access((char*)sbrk(0)+1,F_OK) succeeded unexpectedly.");
462 } /* End for TEST_LOOPING */
464 /***************************************************************
466 ***************************************************************/
472 /***************************************************************
473 * setup() - performs all ONE TIME setup for this test.
474 ***************************************************************/
478 /* capture signals */
479 tst_sig(NOFORK, DEF_HANDLER, cleanup);
481 /* make and change to a temporary directory */
484 /* Pause if that option was specified */
489 /***************************************************************
490 * cleanup() - performs all ONE TIME cleanup for this test at
491 * completion or premature exit.
492 ***************************************************************/
497 * print timing stats if that option was specified.
498 * print errno log if that option was specified.
502 /* remove the temporary directory and exit with
503 return code appropriate for results */
506 } /* End cleanup() */