2 * Copyright (c) 2012 Jilles Tjoelker
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Limited test program for nftw() as specified by IEEE Std. 1003.1-2008.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
48 extern char **environ;
50 static char template[] = "testftw.XXXXXXXXXX";
51 static char dir[PATH_MAX];
55 cb(const char *path, const struct stat *st, int type, struct FTW *f)
60 if ((ftwflags & FTW_DEPTH) == 0)
64 if ((ftwflags & FTW_DEPTH) != 0)
68 if ((ftwflags & FTW_PHYS) != 0)
73 "unexpected path=%s type=%d f.level=%d\n",
74 path, type, f->level);
78 ATF_TC_WITHOUT_HEAD(ftw_test);
79 ATF_TC_BODY(ftw_test, tc)
83 ATF_REQUIRE_MSG(mkdtemp(template) != NULL, "mkdtemp failed");
85 /* XXX: the path needs to be absolute for the 0/FTW_DEPTH testcases */
86 ATF_REQUIRE_MSG(realpath(template, dir) != NULL,
87 "realpath failed; errno=%d", errno);
89 fd = open(dir, O_DIRECTORY|O_RDONLY);
90 ATF_REQUIRE_MSG(fd != -1, "open failed; errno=%d", errno);
92 ATF_REQUIRE_MSG(mkdirat(fd, "d1", 0777) == 0,
93 "mkdirat failed; errno=%d", errno);
95 ATF_REQUIRE_MSG(symlinkat(dir, fd, "d1/looper") == 0,
96 "symlinkat failed; errno=%d", errno);
98 printf("ftwflags=FTW_PHYS\n");
100 ATF_REQUIRE_MSG(nftw(dir, cb, 10, ftwflags) != -1,
101 "nftw FTW_PHYS failed; errno=%d", errno);
103 printf("ftwflags=FTW_PHYS|FTW_DEPTH\n");
104 ftwflags = FTW_PHYS|FTW_DEPTH;
105 ATF_REQUIRE_MSG(nftw(dir, cb, 10, ftwflags) != -1,
106 "nftw FTW_PHYS|FTW_DEPTH failed; errno=%d", errno);
108 printf("ftwflags=0\n");
110 ATF_REQUIRE_MSG(nftw(dir, cb, 10, ftwflags) != -1,
111 "nftw 0 failed; errno=%d", errno);
113 printf("ftwflags=FTW_DEPTH\n");
114 ftwflags = FTW_DEPTH;
115 ATF_REQUIRE_MSG(nftw(dir, cb, 10, ftwflags) != -1,
116 "nftw FTW_DEPTH failed; errno=%d", errno);
124 ATF_TP_ADD_TC(tp, ftw_test);
126 return (atf_no_error());