]>
sourceware.org Git - newlib-cygwin.git/blob - winsup/testsuite/winsup.api/ltp/readdir01.c
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 : readdir01
40 * EXECUTED BY : anyone
42 * TEST TITLE : write multiple files and try to find them with readdir
54 * DATE STARTED : 02/16/2001
56 * INITIAL RELEASE : Linux 2.4.x
60 * 1.) Create n files and check that readdir() finds n files
62 * INPUT SPECIFICATIONS
63 * The standard options for system call tests are accepted.
64 * (See the parse_opts(3) man page).
66 * OUTPUT SPECIFICATIONS
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).
79 * No run-time environmental needs.
81 * SPECIAL PROCEDURAL REQUIREMENTS
84 * INTERCASE DEPENDENCIES
87 * DETAILED DESCRIPTION
88 * This is a Phase I test for the readdir(2) system call. It is intended
89 * to provide a limited exposure of the system call, for now. It
90 * should/will be extended when full functional tests are written for
94 * Setup signal handling.
95 * Pause for SIGUSR1 if option specified.
98 * Loop if the proper options are given.
100 * Check return code, if system call failed (return=-1)
101 * Log the errno and Issue a FAIL message.
102 * Otherwise, Issue a PASS message.
105 * Print errno log and/or timing stats if options given
108 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
110 #include <sys/types.h>
111 #include <sys/stat.h>
118 /* test.h and usctest.h are the two header files that are required by the
119 * quickhit package. They contain function and macro declarations which you
120 * can use in your test programs
125 /* The setup and cleanup functions are basic parts of a test case. These
126 * steps are usually put in separate functions for clarity. The help function
127 * is only needed when you are adding new command line options.
133 char *TCID
="readdir01"; /* Test program identifier. */
134 int TST_TOTAL
=2; /* Total number of test cases. */
135 extern int Tst_count
; /* Test Case counter for tst_* routines */
136 extern int Tst_nobuf
;
138 int exp_enos
[]={0, 0};
140 #define BASENAME "readdirfile"
146 /* To add command line options you need to declare a structure to pass to
147 * parse_opts(). options is the structure used in this example. The format is
148 * the string that should be added to optstring in getopt(3), an integer that
149 * will be used as a flag if the option is given, and a pointer to a string that
150 * should receive the optarg parameter from getopt(3). Here we add a -N
151 * option. Long options are not supported at this time.
156 /* for test specific parse_opts options */
157 option_t options
[] = {
158 { "N:", &Nflag
, &Nfilearg
}, /* -N #files */
162 /***********************************************************************
164 ***********************************************************************/
166 main(int ac
, char **av
)
168 int lc
; /* loop counter */
169 const char *msg
; /* message returned from parse_opts */
178 /***************************************************************
179 * parse standard options
180 ***************************************************************/
181 /* start off by parsing the command line options. We provide a function
182 * that understands many common options to control looping. If you are not
183 * adding any new options, pass NULL in place of options and &help.
185 if ( (msg
=parse_opts(ac
, av
, options
, &help
)) ) {
186 tst_brkm(TBROK
, NULL
, "OPTION PARSING ERROR - %s", msg
);
191 if (sscanf(Nfilearg
, "%i", &Nfiles
) != 1 ) {
192 tst_brkm(TBROK
, NULL
, "--N option arg is not a number");
197 /***************************************************************
198 * perform global setup for test
199 ***************************************************************/
200 /* Next you should run a setup routine to make sure your environment is
205 /* set the expected errnos... */
206 TEST_EXP_ENOS(exp_enos
);
208 /***************************************************************
209 * check looping state
210 ***************************************************************/
211 /* TEST_LOOPING() is a macro that will make sure the test continues
212 * looping according to the standard command line args.
214 for (lc
=0; TEST_LOOPING(lc
); lc
++) {
216 /* reset Tst_count in case we are looping. */
222 /* min of 10 links and max of a 100 links */
225 /* create a bunch of files to look at */
226 for(cnt
=0; cnt
< nfiles
; cnt
++) {
228 sprintf(fname
, "%s%d", Basename
, cnt
);
229 if ((fd
= open(fname
, O_RDWR
|O_CREAT
, 0700)) == -1) {
230 tst_brkm(TBROK
, cleanup
,
231 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s", fname
, errno
, strerror(errno
));
232 } else if (write(fd
, "hello\n", 6) < 0) {
233 tst_brkm(TBROK
, cleanup
,
234 "write(%s, \"hello\\n\", 6) Failed, errno=%d : %s", fname
, errno
, strerror(errno
));
235 } else if (close(fd
) < 0) {
236 tst_res(TWARN
, "close(%s) Failed, errno=%d : %s",
237 fname
, errno
, strerror(errno
));
241 if ((test_dir
= opendir(".")) == NULL
) {
242 tst_resm(TFAIL
, "opendir(\".\") Failed, errno=%d : %s",
243 errno
, strerror(errno
));
245 /* count the entries we find to see if any are missing */
248 while ( (dptr
= readdir(test_dir
)) ) {
249 if (strcmp(dptr
->d_name
, ".") && strcmp(dptr
->d_name
, ".."))
254 tst_resm(TFAIL
, "readir(test_dir) Failed on try %d, errno=%d : %s",
255 cnt
, errno
, strerror(errno
));
258 tst_resm(TPASS
, "found all %d that were created", nfiles
);
259 } else if (cnt
> nfiles
) {
260 tst_resm(TFAIL
, "found more files than were created");
261 tst_resm(TINFO
, "created: %d, found: %d", nfiles
, cnt
);
263 tst_resm(TFAIL
, "found less files than were created");
264 tst_resm(TINFO
, "created: %d, found: %d", nfiles
, cnt
);
268 /* Here we clean up after the test case so we can do another iteration.
270 for(cnt
=0; cnt
< nfiles
; cnt
++) {
272 sprintf(fname
, "%s%d", Basename
, cnt
);
274 if (unlink(fname
) == -1) {
275 tst_res(TWARN
, "unlink(%s) Failed, errno=%d : %s",
276 Fname
, errno
, strerror(errno
));
280 } /* End for TEST_LOOPING */
282 /***************************************************************
284 ***************************************************************/
290 /***************************************************************
292 ***************************************************************/
293 /* The custom help() function is really simple. Just write your help message to
294 * standard out. Your help function will be called after the standard options
300 printf(" -N #files : create #files files every iteration\n");
303 /***************************************************************
304 * setup() - performs all ONE TIME setup for this test.
305 ***************************************************************/
309 /* You will want to enable some signal handling so you can capture
310 * unexpected signals like SIGSEGV.
312 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
314 /* Pause if that option was specified */
315 /* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to
316 * fork the test with the -c option. You want to make sure you do this
317 * before you create your temporary directory.
321 /* If you are doing any file work, you should use a temporary directory. We
322 * provide tst_tmpdir() which will create a uniquely named temporary
323 * directory and cd into it. You can now create files in the current
324 * directory without worrying.
328 sprintf(Basename
, "%s_%d.", BASENAME
, getpid());
331 /***************************************************************
332 * cleanup() - performs all ONE TIME cleanup for this test at
333 * completion or premature exit.
334 ***************************************************************/
339 * print timing stats if that option was specified.
340 * print errno log if that option was specified.
344 /* If you use a temporary directory, you need to be sure you remove it. Use
345 * tst_rmdir() to do it automatically.
349 /* exit with return code appropriate for results */
This page took 0.053639 seconds and 5 git commands to generate.