3 # Copyright (C) 1997-2013 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
22 # The common objpfx, used to find libraries and the dynamic loader.
25 # We expect one parameter which is the test program. This must understand
27 # --phys use the FTW_PHYS flag
28 # --chdir use the FTW_CHDIR and print the current directory
30 # --depth use the FTW_DEPTH flag
31 # --early-exit print file@2 item only and return non-zero from the
32 # callback when it is seen
35 # We cannot test this as root.
36 if test `id | sed "s/uid=\([0-9]*\).*/\1/"` = 0; then
40 # Since we use `sort' we must make sure to use the same locale everywhere.
46 # First create our scenario:
50 trap 'chmod -fR a+x $tmpdir; rm -fr $tmpdir $testout' 1 2 3 15
52 if test -d $tmpdir; then
60 mkdir
$tmpdir/foo
/lvl1
61 echo > $tmpdir/foo
/lvl
1/file@
1
62 mkdir
$tmpdir/foo
/lvl
1/lvl2
63 echo > $tmpdir/foo
/lvl
1/lvl
2/file@
2
64 mkdir
$tmpdir/foo
/lvl
1/lvl
2/lvl3
65 echo > $tmpdir/foo
/lvl
1/lvl
2/lvl
3/file@
3
66 ln -s $tmpdir $tmpdir/foo
/lvl
1/lvl
2/lvl
3/link@
3
67 ln -s $tmpdir/foo
/lvl
1/lvl2
$tmpdir/foo
/lvl
1/lvl
2/link@
2
68 ln -s $tmpdir/foo
/lvl
1/lvl
2/lvl
3/lvl4
$tmpdir/foo
/lvl
1/link@
1
70 chmod a-x
,a
+r
$tmpdir/bar
72 testout
=$tmp/ftwtest.out
74 $testprogram $tmpdir |
77 cat <<EOF | cmp $testout - || exit 1
78 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
79 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
80 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
81 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
82 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
83 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
84 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
85 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
86 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
87 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
88 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
89 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
93 $testprogram --depth $tmpdir |
96 cat <<EOF | cmp $testout - || exit 1
97 base = "$tmp/", file = "ftwtest.d", flag = FTW_DP, level = 0
98 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_DP, level = 1
99 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
100 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_DP, level = 1
101 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
102 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_DP, level = 2
103 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
104 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
105 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_DP, level = 3
106 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
107 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_DP, level = 4
108 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
112 $testprogram --phys $tmpdir |
115 cat <<EOF | cmp $testout - || exit 1
116 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
117 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
118 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
119 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
120 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
121 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
122 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
123 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SL, level = 3
124 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
125 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
126 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "link@2", flag = FTW_SL, level = 4
127 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
128 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
129 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "link@3", flag = FTW_SL, level = 5
133 # For the next test everything must be readable.
134 chmod -fR a
+x
$tmpdir
136 $testprogram --chdir $tmpdir |
139 # perhaps $tmp involves some symlinks...
140 tmpreal
=`cd $tmp; /bin/pwd 2>/dev/null || /usr/bin/pwd`
142 cat <<EOF | cmp $testout - || exit 1
143 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, cwd = $tmpreal, level = 0
144 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
145 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
146 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
147 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
148 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
149 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
150 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
151 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
152 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
153 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
154 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
158 curwd
=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
160 $testprogram --chdir ftwtest.d |
164 cat <<EOF | diff -u $testout - || exit 1
165 base = "", file = "ftwtest.d", flag = FTW_D, cwd = $tmpreal, level = 0
166 base = "ftwtest.d/", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
167 base = "ftwtest.d/", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
168 base = "ftwtest.d/", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
169 base = "ftwtest.d/bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
170 base = "ftwtest.d/foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
171 base = "ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
172 base = "ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
173 base = "ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
174 base = "ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
175 base = "ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
176 base = "ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
180 curwd
=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
182 $testprogram --chdir ftwtest.d
/. |
186 cat <<EOF | diff -u $testout - || exit 1
187 base = "ftwtest.d/", file = ".", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 0
188 base = "ftwtest.d/./", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
189 base = "ftwtest.d/./", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
190 base = "ftwtest.d/./", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
191 base = "ftwtest.d/./bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
192 base = "ftwtest.d/./foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
193 base = "ftwtest.d/./foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
194 base = "ftwtest.d/./foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
195 base = "ftwtest.d/./foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
196 base = "ftwtest.d/./foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
197 base = "ftwtest.d/./foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
198 base = "ftwtest.d/./foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
202 curwd
=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
204 $testprogram --chdir ftwtest.d
/foo
/lvl
1/link@
1 |
208 cat <<EOF | diff -u $testout - || exit 1
209 base = "ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 0
213 $testprogram --early-exit $tmpdir |
216 cat <<EOF | cmp $testout - || exit 1
217 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
222 mkdir
$tmpdir/foo
/lvl1b
223 echo > $tmpdir/foo
/lvl1b
/file@
1b
224 echo > $tmpdir/foo
/lvl1b
/file2@
1b
225 echo > $tmpdir/foo
/lvl1b
/file3@
1b
227 $testprogram --skip-subtree=lvl1
$tmpdir |
230 cat <<EOF | diff -u $testout - || exit 1
231 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
232 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
233 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
234 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
235 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, level = 2
236 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
237 base = "$tmp/ftwtest.d/foo/", file = "lvl1b", flag = FTW_D, level = 2
238 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
239 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
240 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3
244 $testprogram --skip-siblings=lvl1
$tmpdir |
247 # The filesystem is not required to put lvl1 before lvl1b.
248 # If lvl1b comes after lvl1, it shouldn't be printed, while if it
249 # comes before, it should.
251 [ -n "`ls -U $tmpdir/foo/ | sed -n '/lvl1$/,${/lvl1b$/p;}'`" ] \
252 && catcmd
="grep -v lvl1b"
254 $catcmd <<EOF | diff -u $testout - || exit 1
255 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
256 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
257 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
258 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
259 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, level = 2
260 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
261 base = "$tmp/ftwtest.d/foo/", file = "lvl1b", flag = FTW_D, level = 2
262 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
263 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
264 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3
268 $testprogram --skip-siblings=file@
1b
$tmpdir |
271 # The filesystem is not required to put file2@1b and file3@1b after file@1b.
272 # If file[23]@1b come after file@1b, it shouldn't be printed, while if they
273 # come before, they should.
274 regexp
=`echo $(ls -U $tmp/ftwtest.d/foo/lvl1b \
275 | sed -n '/file@1b$/,${/file[23]@1b$/p;}') | sed 's, ,|,'`
277 [ -n "$regexp" ] && catcmd
="egrep -v $regexp"
279 $catcmd <<EOF | diff -u $testout - || exit 1
280 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
281 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
282 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
283 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
284 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, level = 2
285 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
286 base = "$tmp/ftwtest.d/foo/", file = "lvl1b", flag = FTW_D, level = 2
287 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
288 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
289 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
290 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
291 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
292 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
293 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
294 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
295 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3