OSDN Git Service

dc7dc5ee49e4c80d40a101c6a6aeb84d86568705
[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 <unistd.h>
106 #include "test.h"
107 #include "usctest.h"
108
109
110 void setup();
111 void cleanup();
112
113
114 char *get_high_address();
115
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 */
119
120 int exp_enos[]={EFAULT, 0};  /* List must end with 0 */
121
122 int main(int ac, char **av)
123 {
124     int lc;             /* loop counter */
125     const char *msg;            /* message returned from parse_opts */
126     
127      
128
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);
134
135     /***************************************************************
136      * perform global setup for test
137      ***************************************************************/
138     setup();
139
140     /* set the expected errnos. */
141     TEST_EXP_ENOS(exp_enos);
142
143     /***************************************************************
144      * check looping state if -c option given
145      ***************************************************************/
146     for (lc=0; TEST_LOOPING(lc); lc++) {
147
148         /* reset Tst_count in case we are looping. */
149         Tst_count=0;
150
151                 
152         /* 
153          * TEST CASE:
154          *  R_OK on low pointer (-1) for path
155          */
156          
157
158         /* Call access(2) */
159         TEST(access( (char *)-1,R_OK));
160         
161
162         /* check return code */
163         if ( TEST_RETURN == -1 ) {
164             TEST_ERROR_LOG(TEST_ERRNO);
165         }
166
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) {
173               tst_resm(TPASS, 
174                        "access((char *)-1,R_OK) failed as expected with errno %d (EFAULT) : %s",
175                        TEST_ERRNO, strerror(TEST_ERRNO));
176             }
177             else {
178               tst_resm(TFAIL, 
179                        "access((char *)-1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
180                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
181             }
182           }
183           else {
184             tst_resm(TFAIL,
185                        "access((char *)-1,R_OK) succeeded unexpectedly.");
186
187           }
188         } 
189         
190         
191         /* 
192          * TEST CASE:
193          *  W_OK on low pointer (-1) for path
194          */
195          
196
197         /* Call access(2) */
198         TEST(access( (char *)-1,W_OK));
199         
200         /* check return code */
201         if ( TEST_RETURN == -1 ) {
202             TEST_ERROR_LOG(TEST_ERRNO);
203         }
204
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) {
211               tst_resm(TPASS, 
212                        "access((char *)-1,W_OK) failed as expected with errno %d (EFAULT) : %s",
213                        TEST_ERRNO, strerror(TEST_ERRNO));
214             }
215             else {
216               tst_resm(TFAIL, 
217                        "access((char *)-1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
218                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
219             }
220           }
221           else {
222             tst_resm(TFAIL,
223                        "access((char *)-1,W_OK) succeeded unexpectedly.");
224
225           }
226         } 
227         
228         
229         /* 
230          * TEST CASE:
231          *  X_OK on low pointer (-1) for path
232          */
233          
234
235         /* Call access(2) */
236         TEST(access( (char *)-1,X_OK));
237         
238
239         /* check return code */
240         if ( TEST_RETURN == -1 ) {
241             TEST_ERROR_LOG(TEST_ERRNO);
242         }
243
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) {
250               tst_resm(TPASS, 
251                        "access((char*)-1,X_OK) failed as expected with errno %d (EFAULT) : %s",
252                        TEST_ERRNO, strerror(TEST_ERRNO));
253             }
254             else {
255               tst_resm(TFAIL, 
256                        "access((char*)-1,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
257                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
258             }
259           }
260           else {
261             tst_resm(TFAIL,
262                        "access((char*)-1,X_OK) succeeded unexpectedly.");
263
264           }
265         } 
266         
267         
268         /* 
269          * TEST CASE:
270          *  F_OK on low pointer (-1) for path
271          */
272          
273
274         /* Call access(2) */
275         TEST(access( (char *)-1,F_OK));
276         
277
278         /* check return code */
279         if ( TEST_RETURN == -1 ) {
280             TEST_ERROR_LOG(TEST_ERRNO);
281         }
282
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) {
289               tst_resm(TPASS, 
290                        "access((char*)-1,F_OK) failed as expected with errno %d (EFAULT) : %s",
291                        TEST_ERRNO, strerror(TEST_ERRNO));
292             }
293             else {
294               tst_resm(TFAIL, 
295                        "access((char*)-1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
296                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
297             }
298           }
299           else {
300             tst_resm(TFAIL,
301                        "access((char*)-1,F_OK) succeeded unexpectedly.");
302
303           }
304         } 
305         
306         
307         /* 
308          * TEST CASE:
309          *  R_OK on high pointer (sbrk(0)+1) for path
310          */
311          
312
313         /* Call access(2) */
314         TEST(access(get_high_address(),R_OK));
315         
316
317         /* check return code */
318         if ( TEST_RETURN == -1 ) {
319             TEST_ERROR_LOG(TEST_ERRNO);
320         }
321
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) {
328               tst_resm(TPASS, 
329                        "access((char*)sbrk(0)+1,R_OK) failed as expected with errno %d (EFAULT) : %s",
330                        TEST_ERRNO, strerror(TEST_ERRNO));
331             }
332             else {
333               tst_resm(TFAIL, 
334                        "access((char*)sbrk(0)+1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
335                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
336             }
337           }
338           else {
339             tst_resm(TFAIL,
340                        "access((char*)sbrk(0)+1,R_OK) succeeded unexpectedly.");
341
342           }
343         } 
344         
345         
346         /* 
347          * TEST CASE:
348          *  W_OK on high pointer (sbrk(0)+1) for path
349          */
350          
351
352         /* Call access(2) */
353         TEST(access(get_high_address(),W_OK));
354         
355
356         /* check return code */
357         if ( TEST_RETURN == -1 ) {
358             TEST_ERROR_LOG(TEST_ERRNO);
359         }
360
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) {
367               tst_resm(TPASS, 
368                        "access((char*)sbrk(0)+1,W_OK) failed as expected with errno %d (EFAULT) : %s",
369                        TEST_ERRNO, strerror(TEST_ERRNO));
370             }
371             else {
372               tst_resm(TFAIL, 
373                        "access((char*)sbrk(0)+1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
374                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
375             }
376           }
377           else {
378             tst_resm(TFAIL,
379                        "access((char*)sbrk(0)+1,W_OK) succeeded unexpectedly.");
380
381           }
382         } 
383         
384         
385         /* 
386          * TEST CASE:
387          *  X_OK on high pointer (sbrk(0)+1) for path
388          */
389          
390
391         /* Call access(2) */
392         TEST(access(get_high_address(),X_OK));
393         
394
395         /* check return code */
396         if ( TEST_RETURN == -1 ) {
397             TEST_ERROR_LOG(TEST_ERRNO);
398         }
399
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) {
406               tst_resm(TPASS, 
407                        "access(high_address,X_OK) failed as expected with errno %d (EFAULT) : %s",
408                        TEST_ERRNO, strerror(TEST_ERRNO));
409             }
410             else {
411               tst_resm(TFAIL, 
412                        "access(high_address,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
413                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
414             }
415           }
416           else {
417             tst_resm(TFAIL,
418                        "access(high_address,X_OK) succeeded unexpectedly.");
419
420           }
421         } 
422         
423         
424         /* 
425          * TEST CASE:
426          *  F_OK on high pointer (sbrk(0)+1) for path
427          */
428          
429
430         /* Call access(2) */
431         TEST(access(get_high_address(),F_OK));
432         
433
434         /* check return code */
435         if ( TEST_RETURN == -1 ) {
436             TEST_ERROR_LOG(TEST_ERRNO);
437         }
438
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) {
445               tst_resm(TPASS, 
446                        "access((char*)sbrk(0)+1,F_OK) failed as expected with errno %d (EFAULT) : %s",
447                        TEST_ERRNO, strerror(TEST_ERRNO));
448             }
449             else {
450               tst_resm(TFAIL, 
451                        "access((char*)sbrk(0)+1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
452                        TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
453             }
454           }
455           else {
456             tst_resm(TFAIL,
457                        "access((char*)sbrk(0)+1,F_OK) succeeded unexpectedly.");
458
459           }
460         } 
461         
462
463     }   /* End for TEST_LOOPING */
464
465     /***************************************************************
466      * cleanup and exit
467      ***************************************************************/
468     cleanup();
469
470     return 0;
471 }       /* End main */
472
473 /***************************************************************
474  * setup() - performs all ONE TIME setup for this test.
475  ***************************************************************/
476 void 
477 setup()
478 {
479     /* capture signals */
480     tst_sig(NOFORK, DEF_HANDLER, cleanup);
481
482     /* make and change to a temporary directory */
483     tst_tmpdir();
484
485     /* Pause if that option was specified */
486     TEST_PAUSE;
487 }       /* End setup() */
488
489
490 /***************************************************************
491  * cleanup() - performs all ONE TIME cleanup for this test at
492  *              completion or premature exit.
493  ***************************************************************/
494 void 
495 cleanup()
496 {
497     /*
498      * print timing stats if that option was specified.
499      * print errno log if that option was specified.
500      */
501     TEST_CLEANUP;
502
503     /* remove the temporary directory and exit with 
504        return code appropriate for results */
505     tst_rmdir();
506     tst_exit();
507 }       /* End cleanup() */