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 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
114 char *get_high_address();
116 char *TCID="access03"; /* Test program identifier. */
117 int TST_TOTAL=8; /* Total number of test cases. */
118 extern int Tst_count; /* Test Case counter for tst_* routines */
120 int exp_enos[]={EFAULT, 0}; /* List must end with 0 */
122 int main(int ac, char **av)
124 int lc; /* loop counter */
125 const char *msg; /* message returned from parse_opts */
129 /***************************************************************
130 * parse standard options
131 ***************************************************************/
132 if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
133 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
135 /***************************************************************
136 * perform global setup for test
137 ***************************************************************/
140 /* set the expected errnos. */
141 TEST_EXP_ENOS(exp_enos);
143 /***************************************************************
144 * check looping state if -c option given
145 ***************************************************************/
146 for (lc=0; TEST_LOOPING(lc); lc++) {
148 /* reset Tst_count in case we are looping. */
154 * R_OK on low pointer (-1) for path
159 TEST(access( (char *)-1,R_OK));
162 /* check return code */
163 if ( TEST_RETURN == -1 ) {
164 TEST_ERROR_LOG(TEST_ERRNO);
167 /***************************************************************
168 * only perform functional verification if flag set (-f not given)
169 ***************************************************************/
170 if ( STD_FUNCTIONAL_TEST ) {
171 if ( TEST_RETURN == -1 ) {
172 if (TEST_ERRNO == EFAULT) {
174 "access((char *)-1,R_OK) failed as expected with errno %d (EFAULT) : %s",
175 TEST_ERRNO, strerror(TEST_ERRNO));
179 "access((char *)-1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
180 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
185 "access((char *)-1,R_OK) succeeded unexpectedly.");
193 * W_OK on low pointer (-1) for path
198 TEST(access( (char *)-1,W_OK));
200 /* check return code */
201 if ( TEST_RETURN == -1 ) {
202 TEST_ERROR_LOG(TEST_ERRNO);
205 /***************************************************************
206 * only perform functional verification if flag set (-f not given)
207 ***************************************************************/
208 if ( STD_FUNCTIONAL_TEST ) {
209 if ( TEST_RETURN == -1 ) {
210 if (TEST_ERRNO == EFAULT) {
212 "access((char *)-1,W_OK) failed as expected with errno %d (EFAULT) : %s",
213 TEST_ERRNO, strerror(TEST_ERRNO));
217 "access((char *)-1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
218 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
223 "access((char *)-1,W_OK) succeeded unexpectedly.");
231 * X_OK on low pointer (-1) for path
236 TEST(access( (char *)-1,X_OK));
239 /* check return code */
240 if ( TEST_RETURN == -1 ) {
241 TEST_ERROR_LOG(TEST_ERRNO);
244 /***************************************************************
245 * only perform functional verification if flag set (-f not given)
246 ***************************************************************/
247 if ( STD_FUNCTIONAL_TEST ) {
248 if ( TEST_RETURN == -1 ) {
249 if (TEST_ERRNO == EFAULT) {
251 "access((char*)-1,X_OK) failed as expected with errno %d (EFAULT) : %s",
252 TEST_ERRNO, strerror(TEST_ERRNO));
256 "access((char*)-1,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
257 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
262 "access((char*)-1,X_OK) succeeded unexpectedly.");
270 * F_OK on low pointer (-1) for path
275 TEST(access( (char *)-1,F_OK));
278 /* check return code */
279 if ( TEST_RETURN == -1 ) {
280 TEST_ERROR_LOG(TEST_ERRNO);
283 /***************************************************************
284 * only perform functional verification if flag set (-f not given)
285 ***************************************************************/
286 if ( STD_FUNCTIONAL_TEST ) {
287 if ( TEST_RETURN == -1 ) {
288 if (TEST_ERRNO == EFAULT) {
290 "access((char*)-1,F_OK) failed as expected with errno %d (EFAULT) : %s",
291 TEST_ERRNO, strerror(TEST_ERRNO));
295 "access((char*)-1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
296 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
301 "access((char*)-1,F_OK) succeeded unexpectedly.");
309 * R_OK on high pointer (sbrk(0)+1) for path
314 TEST(access(get_high_address(),R_OK));
317 /* check return code */
318 if ( TEST_RETURN == -1 ) {
319 TEST_ERROR_LOG(TEST_ERRNO);
322 /***************************************************************
323 * only perform functional verification if flag set (-f not given)
324 ***************************************************************/
325 if ( STD_FUNCTIONAL_TEST ) {
326 if ( TEST_RETURN == -1 ) {
327 if (TEST_ERRNO == EFAULT) {
329 "access((char*)sbrk(0)+1,R_OK) failed as expected with errno %d (EFAULT) : %s",
330 TEST_ERRNO, strerror(TEST_ERRNO));
334 "access((char*)sbrk(0)+1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
335 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
340 "access((char*)sbrk(0)+1,R_OK) succeeded unexpectedly.");
348 * W_OK on high pointer (sbrk(0)+1) for path
353 TEST(access(get_high_address(),W_OK));
356 /* check return code */
357 if ( TEST_RETURN == -1 ) {
358 TEST_ERROR_LOG(TEST_ERRNO);
361 /***************************************************************
362 * only perform functional verification if flag set (-f not given)
363 ***************************************************************/
364 if ( STD_FUNCTIONAL_TEST ) {
365 if ( TEST_RETURN == -1 ) {
366 if (TEST_ERRNO == EFAULT) {
368 "access((char*)sbrk(0)+1,W_OK) failed as expected with errno %d (EFAULT) : %s",
369 TEST_ERRNO, strerror(TEST_ERRNO));
373 "access((char*)sbrk(0)+1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
374 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
379 "access((char*)sbrk(0)+1,W_OK) succeeded unexpectedly.");
387 * X_OK on high pointer (sbrk(0)+1) for path
392 TEST(access(get_high_address(),X_OK));
395 /* check return code */
396 if ( TEST_RETURN == -1 ) {
397 TEST_ERROR_LOG(TEST_ERRNO);
400 /***************************************************************
401 * only perform functional verification if flag set (-f not given)
402 ***************************************************************/
403 if ( STD_FUNCTIONAL_TEST ) {
404 if ( TEST_RETURN == -1 ) {
405 if (TEST_ERRNO == EFAULT) {
407 "access(high_address,X_OK) failed as expected with errno %d (EFAULT) : %s",
408 TEST_ERRNO, strerror(TEST_ERRNO));
412 "access(high_address,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
413 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
418 "access(high_address,X_OK) succeeded unexpectedly.");
426 * F_OK on high pointer (sbrk(0)+1) for path
431 TEST(access(get_high_address(),F_OK));
434 /* check return code */
435 if ( TEST_RETURN == -1 ) {
436 TEST_ERROR_LOG(TEST_ERRNO);
439 /***************************************************************
440 * only perform functional verification if flag set (-f not given)
441 ***************************************************************/
442 if ( STD_FUNCTIONAL_TEST ) {
443 if ( TEST_RETURN == -1 ) {
444 if (TEST_ERRNO == EFAULT) {
446 "access((char*)sbrk(0)+1,F_OK) failed as expected with errno %d (EFAULT) : %s",
447 TEST_ERRNO, strerror(TEST_ERRNO));
451 "access((char*)sbrk(0)+1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
452 TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
457 "access((char*)sbrk(0)+1,F_OK) succeeded unexpectedly.");
463 } /* End for TEST_LOOPING */
465 /***************************************************************
467 ***************************************************************/
473 /***************************************************************
474 * setup() - performs all ONE TIME setup for this test.
475 ***************************************************************/
479 /* capture signals */
480 tst_sig(NOFORK, DEF_HANDLER, cleanup);
482 /* make and change to a temporary directory */
485 /* Pause if that option was specified */
490 /***************************************************************
491 * cleanup() - performs all ONE TIME cleanup for this test at
492 * completion or premature exit.
493 ***************************************************************/
498 * print timing stats if that option was specified.
499 * print errno log if that option was specified.
503 /* remove the temporary directory and exit with
504 return code appropriate for results */
507 } /* End cleanup() */