OSDN Git Service

f0870a6fad289dbcdbf6bb69cdb6a17a98978e67
[pf3gnuchains/pf3gnuchains3x.git] / winsup / testsuite / winsup.api / ltp / access03.c
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  */
33 /* $Id$ */
34 /**********************************************************
35  * 
36  *    OS Test - Silicon Graphics, Inc.
37  * 
38  *    TEST IDENTIFIER   : access03
39  * 
40  *    EXECUTED BY       : anyone
41  * 
42  *    TEST TITLE        : EFAULT error testing for access(2)
43  * 
44  *    PARENT DOCUMENT   : acstds01
45  * 
46  *    TEST CASE TOTAL   : 8
47  * 
48  *    WALL CLOCK TIME   : 1
49  * 
50  *    CPU TYPES         : ALL
51  * 
52  *    AUTHOR            : Kathy Olmsted
53  * 
54  *    CO-PILOT          : Tom Hampson
55  * 
56  *    DATE STARTED      : 05/13/92
57  * 
58  *    INITIAL RELEASE   : UNICOS 7.0
59  * 
60  *    TEST CASES
61  * 
62  *      access(2) test for errno(s) EFAULT.
63  *      
64  *    INPUT SPECIFICATIONS
65  *      The standard options for system call tests are accepted.
66  *      (See the parse_opts(3) man page).
67  * 
68  *    DURATION
69  *      Terminates - with frequency and infinite modes.
70  * 
71  *    SIGNALS
72  *      Uses SIGUSR1 to pause before test if option set.
73  *      (See the parse_opts(3) man page).
74  *
75  *    ENVIRONMENTAL NEEDS
76  *      No run-time environmental needs.
77  * 
78  *    DETAILED DESCRIPTION
79  *
80  *      Setup:
81  *        Setup signal handling.
82  *        Make and change to a temporary directory.
83  *        Pause for SIGUSR1 if option specified.
84  * 
85  *      Test:
86  *       Loop if the proper options are given.
87  *        Execute system call
88  *        Check return code, if system call failed (return=-1)
89  *              Log the errno.
90  *        If doing functional test
91  *            check the errno returned and print result message
92  * 
93  *      Cleanup:
94  *        Print errno log and/or timing stats if options given
95  *        Remove the temporary directory and exit. 
96  * 
97  * 
98  *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
99
100 #include <errno.h>
101 #include <string.h>
102 #include <signal.h>
103
104  
105 #include "test.h"
106 #include "usctest.h"
107
108
109 void setup();
110 void cleanup(void) __attribute__((noreturn));
111
112
113 char *get_high_address();
114
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 */
118
119 int exp_enos[]={EFAULT, 0};  /* List must end with 0 */
120
121 int main(int ac, char **av)
122 {
123     int lc;             /* loop counter */
124     const char *msg;            /* message returned from parse_opts */
125     
126      
127
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);
133
134     /***************************************************************
135      * perform global setup for test
136      ***************************************************************/
137     setup();
138
139     /* set the expected errnos. */
140     TEST_EXP_ENOS(exp_enos);
141
142     /***************************************************************
143      * check looping state if -c option given
144      ***************************************************************/
145     for (lc=0; TEST_LOOPING(lc); lc++) {
146
147         /* reset Tst_count in case we are looping. */
148         Tst_count=0;
149
150                 
151         /* 
152          * TEST CASE:
153          *  R_OK on low pointer (-1) for path
154          */
155          
156
157         /* Call access(2) */
158         TEST(access( (char *)-1,R_OK));
159         
160
161         /* check return code */
162         if ( TEST_RETURN == -1 ) {
163             TEST_ERROR_LOG(TEST_ERRNO);
164         }
165
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) {
172               tst_resm(TPASS, 
173                        "access((char *)-1,R_OK) failed as expected with errno %d (EFAULT) : %s",
174                        TEST_ERRNO, strerror(TEST_ERRNO));
175             }
176             else {
177               tst_resm(TFAIL, 
178                        "access((char *)-1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
179                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
180             }
181           }
182           else {
183             tst_resm(TFAIL,
184                        "access((char *)-1,R_OK) succeeded unexpectedly.");
185
186           }
187         } 
188         
189         
190         /* 
191          * TEST CASE:
192          *  W_OK on low pointer (-1) for path
193          */
194          
195
196         /* Call access(2) */
197         TEST(access( (char *)-1,W_OK));
198         
199         /* check return code */
200         if ( TEST_RETURN == -1 ) {
201             TEST_ERROR_LOG(TEST_ERRNO);
202         }
203
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) {
210               tst_resm(TPASS, 
211                        "access((char *)-1,W_OK) failed as expected with errno %d (EFAULT) : %s",
212                        TEST_ERRNO, strerror(TEST_ERRNO));
213             }
214             else {
215               tst_resm(TFAIL, 
216                        "access((char *)-1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
217                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
218             }
219           }
220           else {
221             tst_resm(TFAIL,
222                        "access((char *)-1,W_OK) succeeded unexpectedly.");
223
224           }
225         } 
226         
227         
228         /* 
229          * TEST CASE:
230          *  X_OK on low pointer (-1) for path
231          */
232          
233
234         /* Call access(2) */
235         TEST(access( (char *)-1,X_OK));
236         
237
238         /* check return code */
239         if ( TEST_RETURN == -1 ) {
240             TEST_ERROR_LOG(TEST_ERRNO);
241         }
242
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) {
249               tst_resm(TPASS, 
250                        "access((char*)-1,X_OK) failed as expected with errno %d (EFAULT) : %s",
251                        TEST_ERRNO, strerror(TEST_ERRNO));
252             }
253             else {
254               tst_resm(TFAIL, 
255                        "access((char*)-1,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
256                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
257             }
258           }
259           else {
260             tst_resm(TFAIL,
261                        "access((char*)-1,X_OK) succeeded unexpectedly.");
262
263           }
264         } 
265         
266         
267         /* 
268          * TEST CASE:
269          *  F_OK on low pointer (-1) for path
270          */
271          
272
273         /* Call access(2) */
274         TEST(access( (char *)-1,F_OK));
275         
276
277         /* check return code */
278         if ( TEST_RETURN == -1 ) {
279             TEST_ERROR_LOG(TEST_ERRNO);
280         }
281
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) {
288               tst_resm(TPASS, 
289                        "access((char*)-1,F_OK) failed as expected with errno %d (EFAULT) : %s",
290                        TEST_ERRNO, strerror(TEST_ERRNO));
291             }
292             else {
293               tst_resm(TFAIL, 
294                        "access((char*)-1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
295                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
296             }
297           }
298           else {
299             tst_resm(TFAIL,
300                        "access((char*)-1,F_OK) succeeded unexpectedly.");
301
302           }
303         } 
304         
305         
306         /* 
307          * TEST CASE:
308          *  R_OK on high pointer (sbrk(0)+1) for path
309          */
310          
311
312         /* Call access(2) */
313         TEST(access(get_high_address(),R_OK));
314         
315
316         /* check return code */
317         if ( TEST_RETURN == -1 ) {
318             TEST_ERROR_LOG(TEST_ERRNO);
319         }
320
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) {
327               tst_resm(TPASS, 
328                        "access((char*)sbrk(0)+1,R_OK) failed as expected with errno %d (EFAULT) : %s",
329                        TEST_ERRNO, strerror(TEST_ERRNO));
330             }
331             else {
332               tst_resm(TFAIL, 
333                        "access((char*)sbrk(0)+1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
334                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
335             }
336           }
337           else {
338             tst_resm(TFAIL,
339                        "access((char*)sbrk(0)+1,R_OK) succeeded unexpectedly.");
340
341           }
342         } 
343         
344         
345         /* 
346          * TEST CASE:
347          *  W_OK on high pointer (sbrk(0)+1) for path
348          */
349          
350
351         /* Call access(2) */
352         TEST(access(get_high_address(),W_OK));
353         
354
355         /* check return code */
356         if ( TEST_RETURN == -1 ) {
357             TEST_ERROR_LOG(TEST_ERRNO);
358         }
359
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) {
366               tst_resm(TPASS, 
367                        "access((char*)sbrk(0)+1,W_OK) failed as expected with errno %d (EFAULT) : %s",
368                        TEST_ERRNO, strerror(TEST_ERRNO));
369             }
370             else {
371               tst_resm(TFAIL, 
372                        "access((char*)sbrk(0)+1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
373                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
374             }
375           }
376           else {
377             tst_resm(TFAIL,
378                        "access((char*)sbrk(0)+1,W_OK) succeeded unexpectedly.");
379
380           }
381         } 
382         
383         
384         /* 
385          * TEST CASE:
386          *  X_OK on high pointer (sbrk(0)+1) for path
387          */
388          
389
390         /* Call access(2) */
391         TEST(access(get_high_address(),X_OK));
392         
393
394         /* check return code */
395         if ( TEST_RETURN == -1 ) {
396             TEST_ERROR_LOG(TEST_ERRNO);
397         }
398
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) {
405               tst_resm(TPASS, 
406                        "access(high_address,X_OK) failed as expected with errno %d (EFAULT) : %s",
407                        TEST_ERRNO, strerror(TEST_ERRNO));
408             }
409             else {
410               tst_resm(TFAIL, 
411                        "access(high_address,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
412                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
413             }
414           }
415           else {
416             tst_resm(TFAIL,
417                        "access(high_address,X_OK) succeeded unexpectedly.");
418
419           }
420         } 
421         
422         
423         /* 
424          * TEST CASE:
425          *  F_OK on high pointer (sbrk(0)+1) for path
426          */
427          
428
429         /* Call access(2) */
430         TEST(access(get_high_address(),F_OK));
431         
432
433         /* check return code */
434         if ( TEST_RETURN == -1 ) {
435             TEST_ERROR_LOG(TEST_ERRNO);
436         }
437
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) {
444               tst_resm(TPASS, 
445                        "access((char*)sbrk(0)+1,F_OK) failed as expected with errno %d (EFAULT) : %s",
446                        TEST_ERRNO, strerror(TEST_ERRNO));
447             }
448             else {
449               tst_resm(TFAIL, 
450                        "access((char*)sbrk(0)+1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
451                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
452             }
453           }
454           else {
455             tst_resm(TFAIL,
456                        "access((char*)sbrk(0)+1,F_OK) succeeded unexpectedly.");
457
458           }
459         } 
460         
461
462     }   /* End for TEST_LOOPING */
463
464     /***************************************************************
465      * cleanup and exit
466      ***************************************************************/
467     cleanup();
468
469     return 0;
470 }       /* End main */
471
472 /***************************************************************
473  * setup() - performs all ONE TIME setup for this test.
474  ***************************************************************/
475 void 
476 setup()
477 {
478     /* capture signals */
479     tst_sig(NOFORK, DEF_HANDLER, cleanup);
480
481     /* make and change to a temporary directory */
482     tst_tmpdir();
483
484     /* Pause if that option was specified */
485     TEST_PAUSE;
486 }       /* End setup() */
487
488
489 /***************************************************************
490  * cleanup() - performs all ONE TIME cleanup for this test at
491  *              completion or premature exit.
492  ***************************************************************/
493 void 
494 cleanup()
495 {
496     /*
497      * print timing stats if that option was specified.
498      * print errno log if that option was specified.
499      */
500     TEST_CLEANUP;
501
502     /* remove the temporary directory and exit with 
503        return code appropriate for results */
504     tst_rmdir();
505     tst_exit();
506 }       /* End cleanup() */