Pass a valid pointer to pthread_setspecific to avoid GCC 11 warning.
[glibc.git] / io / ftwtest-sh
blobb0d1389a73540eb2fbb4c3f5e59a1584809a4e27
1 #!/bin/sh
2 # Test for nftw(3).
3 # Copyright (C) 1997-2021 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 # <https://www.gnu.org/licenses/>.
20 set -e
22 # The common objpfx, used to find libraries and the dynamic loader.
23 objpfx=$1
25 # We expect one parameter which is the test program. This must understand
26 # a number options:
27 # --phys use the FTW_PHYS flag
28 # --chdir use the FTW_CHDIR and print the current directory
29 # in the callback
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
33 testprogram=$2
35 # We cannot test this as root.
36 if test `id | sed "s/uid=\([0-9]*\).*/\1/"` = 0; then
37 exit 0
40 # Since we use `sort' we must make sure to use the same locale everywhere.
41 LC_ALL=C
42 export LC_ALL
44 # First create our scenario:
45 tmp=${objpfx}io
46 tmpdir=$(mktemp -d $tmp/ftwtest.d.XXXXXX)
47 ftwtest=$(basename $tmpdir)
49 trap 'chmod -fR a+x $tmpdir; rm -fr $tmpdir $testout' 0 1 2 3 15
51 mkdir $tmpdir/foo
52 mkdir $tmpdir/bar
53 echo > $tmpdir/baz
54 mkdir $tmpdir/foo/lvl1
55 echo > $tmpdir/foo/lvl1/file@1
56 mkdir $tmpdir/foo/lvl1/lvl2
57 echo > $tmpdir/foo/lvl1/lvl2/file@2
58 mkdir $tmpdir/foo/lvl1/lvl2/lvl3
59 echo > $tmpdir/foo/lvl1/lvl2/lvl3/file@3
60 ln -s $tmpdir $tmpdir/foo/lvl1/lvl2/lvl3/link@3
61 ln -s $tmpdir/foo/lvl1/lvl2 $tmpdir/foo/lvl1/lvl2/link@2
62 ln -s $tmpdir/foo/lvl1/lvl2/lvl3/lvl4 $tmpdir/foo/lvl1/link@1
63 echo > $tmpdir/bar/xo
64 chmod a-x,a+r $tmpdir/bar
66 testout=$(mktemp $tmp/ftwtest-tmp-XXXXXX.out)
68 $testprogram $tmpdir |
69 sort > $testout
71 cat <<EOF | cmp $testout - || exit 1
72 base = "$tmp/", file = "$ftwtest", flag = FTW_D, level = 0
73 base = "$tmp/$ftwtest/", file = "bar", flag = FTW_D, level = 1
74 base = "$tmp/$ftwtest/", file = "baz", flag = FTW_F, level = 1
75 base = "$tmp/$ftwtest/", file = "foo", flag = FTW_D, level = 1
76 base = "$tmp/$ftwtest/bar/", file = "xo", flag = FTW_NS, level = 2
77 base = "$tmp/$ftwtest/foo/", file = "lvl1", flag = FTW_D, level = 2
78 base = "$tmp/$ftwtest/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
79 base = "$tmp/$ftwtest/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
80 base = "$tmp/$ftwtest/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
81 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
82 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
83 base = "$tmp/$ftwtest/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
84 EOF
85 rm $testout
87 $testprogram --depth $tmpdir |
88 sort > $testout
90 cat <<EOF | cmp $testout - || exit 1
91 base = "$tmp/", file = "$ftwtest", flag = FTW_DP, level = 0
92 base = "$tmp/$ftwtest/", file = "bar", flag = FTW_DP, level = 1
93 base = "$tmp/$ftwtest/", file = "baz", flag = FTW_F, level = 1
94 base = "$tmp/$ftwtest/", file = "foo", flag = FTW_DP, level = 1
95 base = "$tmp/$ftwtest/bar/", file = "xo", flag = FTW_NS, level = 2
96 base = "$tmp/$ftwtest/foo/", file = "lvl1", flag = FTW_DP, level = 2
97 base = "$tmp/$ftwtest/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
98 base = "$tmp/$ftwtest/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
99 base = "$tmp/$ftwtest/foo/lvl1/", file = "lvl2", flag = FTW_DP, level = 3
100 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
101 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_DP, level = 4
102 base = "$tmp/$ftwtest/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
104 rm $testout
106 $testprogram --phys $tmpdir |
107 sort > $testout
109 cat <<EOF | cmp $testout - || exit 1
110 base = "$tmp/", file = "$ftwtest", flag = FTW_D, level = 0
111 base = "$tmp/$ftwtest/", file = "bar", flag = FTW_D, level = 1
112 base = "$tmp/$ftwtest/", file = "baz", flag = FTW_F, level = 1
113 base = "$tmp/$ftwtest/", file = "foo", flag = FTW_D, level = 1
114 base = "$tmp/$ftwtest/bar/", file = "xo", flag = FTW_NS, level = 2
115 base = "$tmp/$ftwtest/foo/", file = "lvl1", flag = FTW_D, level = 2
116 base = "$tmp/$ftwtest/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
117 base = "$tmp/$ftwtest/foo/lvl1/", file = "link@1", flag = FTW_SL, level = 3
118 base = "$tmp/$ftwtest/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
119 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
120 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "link@2", flag = FTW_SL, level = 4
121 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
122 base = "$tmp/$ftwtest/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
123 base = "$tmp/$ftwtest/foo/lvl1/lvl2/lvl3/", file = "link@3", flag = FTW_SL, level = 5
125 rm $testout
127 # For the next test everything must be readable.
128 chmod -fR a+x $tmpdir
130 $testprogram --chdir $tmpdir |
131 sort > $testout
133 # perhaps $tmp involves some symlinks...
134 tmpreal=`cd $tmp; pwd -P 2>/dev/null`
136 cat <<EOF | cmp $testout - || exit 1
137 base = "$tmp/", file = "$ftwtest", flag = FTW_D, cwd = $tmpreal, level = 0
138 base = "$tmp/$ftwtest/", file = "bar", flag = FTW_D, cwd = $tmpreal/$ftwtest, level = 1
139 base = "$tmp/$ftwtest/", file = "baz", flag = FTW_F, cwd = $tmpreal/$ftwtest, level = 1
140 base = "$tmp/$ftwtest/", file = "foo", flag = FTW_D, cwd = $tmpreal/$ftwtest, level = 1
141 base = "$tmp/$ftwtest/bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/$ftwtest/bar, level = 2
142 base = "$tmp/$ftwtest/foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo, level = 2
143 base = "$tmp/$ftwtest/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
144 base = "$tmp/$ftwtest/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
145 base = "$tmp/$ftwtest/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
146 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2, level = 4
147 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2, level = 4
148 base = "$tmp/$ftwtest/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2/lvl3, level = 5
150 rm $testout
152 curwd=`pwd -P 2>/dev/null`
153 cd "$tmp"
154 $testprogram --chdir $ftwtest |
155 sort > $testout
156 cd "$curwd"
158 cat <<EOF | diff -u $testout - || exit 1
159 base = "", file = "$ftwtest", flag = FTW_D, cwd = $tmpreal, level = 0
160 base = "$ftwtest/", file = "bar", flag = FTW_D, cwd = $tmpreal/$ftwtest, level = 1
161 base = "$ftwtest/", file = "baz", flag = FTW_F, cwd = $tmpreal/$ftwtest, level = 1
162 base = "$ftwtest/", file = "foo", flag = FTW_D, cwd = $tmpreal/$ftwtest, level = 1
163 base = "$ftwtest/bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/$ftwtest/bar, level = 2
164 base = "$ftwtest/foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo, level = 2
165 base = "$ftwtest/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
166 base = "$ftwtest/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
167 base = "$ftwtest/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
168 base = "$ftwtest/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2, level = 4
169 base = "$ftwtest/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2, level = 4
170 base = "$ftwtest/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2/lvl3, level = 5
172 rm $testout
174 curwd=`pwd -P`
175 cd "$tmp"
176 $testprogram --chdir $ftwtest/. |
177 sort > $testout
178 cd "$curwd"
180 cat <<EOF | diff -u $testout - || exit 1
181 base = "$ftwtest/", file = ".", flag = FTW_D, cwd = $tmpreal/$ftwtest, level = 0
182 base = "$ftwtest/./", file = "bar", flag = FTW_D, cwd = $tmpreal/$ftwtest, level = 1
183 base = "$ftwtest/./", file = "baz", flag = FTW_F, cwd = $tmpreal/$ftwtest, level = 1
184 base = "$ftwtest/./", file = "foo", flag = FTW_D, cwd = $tmpreal/$ftwtest, level = 1
185 base = "$ftwtest/./bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/$ftwtest/bar, level = 2
186 base = "$ftwtest/./foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo, level = 2
187 base = "$ftwtest/./foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
188 base = "$ftwtest/./foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
189 base = "$ftwtest/./foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 3
190 base = "$ftwtest/./foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2, level = 4
191 base = "$ftwtest/./foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2, level = 4
192 base = "$ftwtest/./foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/$ftwtest/foo/lvl1/lvl2/lvl3, level = 5
194 rm $testout
196 curwd=`pwd -P 2>/dev/null`
197 cd "$tmp"
198 $testprogram --chdir $ftwtest/foo/lvl1/link@1 |
199 sort > $testout
200 cd "$curwd"
202 cat <<EOF | diff -u $testout - || exit 1
203 base = "$ftwtest/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/$ftwtest/foo/lvl1, level = 0
205 rm $testout
207 $testprogram --early-exit $tmpdir |
208 sort > $testout
210 cat <<EOF | cmp $testout - || exit 1
211 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
212 succeeded
214 rm $testout
216 mkdir $tmpdir/foo/lvl1b
217 echo > $tmpdir/foo/lvl1b/file@1b
218 echo > $tmpdir/foo/lvl1b/file2@1b
219 echo > $tmpdir/foo/lvl1b/file3@1b
221 $testprogram --skip-subtree=lvl1 $tmpdir |
222 sort > $testout
224 cat <<EOF | diff -u $testout - || exit 1
225 base = "$tmp/", file = "$ftwtest", flag = FTW_D, level = 0
226 base = "$tmp/$ftwtest/", file = "bar", flag = FTW_D, level = 1
227 base = "$tmp/$ftwtest/", file = "baz", flag = FTW_F, level = 1
228 base = "$tmp/$ftwtest/", file = "foo", flag = FTW_D, level = 1
229 base = "$tmp/$ftwtest/bar/", file = "xo", flag = FTW_F, level = 2
230 base = "$tmp/$ftwtest/foo/", file = "lvl1", flag = FTW_D, level = 2
231 base = "$tmp/$ftwtest/foo/", file = "lvl1b", flag = FTW_D, level = 2
232 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
233 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
234 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3
236 rm $testout
238 $testprogram --skip-siblings=lvl1 $tmpdir |
239 sort > $testout
241 # The filesystem is not required to put lvl1 before lvl1b.
242 # If lvl1b comes after lvl1, it shouldn't be printed, while if it
243 # comes before, it should.
244 catcmd=cat
245 [ -n "`ls -U $tmpdir/foo/ | sed -n '/lvl1$/,${/lvl1b$/p;}'`" ] \
246 && catcmd="grep -v lvl1b"
248 $catcmd <<EOF | diff -u $testout - || exit 1
249 base = "$tmp/", file = "$ftwtest", flag = FTW_D, level = 0
250 base = "$tmp/$ftwtest/", file = "bar", flag = FTW_D, level = 1
251 base = "$tmp/$ftwtest/", file = "baz", flag = FTW_F, level = 1
252 base = "$tmp/$ftwtest/", file = "foo", flag = FTW_D, level = 1
253 base = "$tmp/$ftwtest/bar/", file = "xo", flag = FTW_F, level = 2
254 base = "$tmp/$ftwtest/foo/", file = "lvl1", flag = FTW_D, level = 2
255 base = "$tmp/$ftwtest/foo/", file = "lvl1b", flag = FTW_D, level = 2
256 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
257 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
258 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3
260 rm $testout
262 $testprogram --skip-siblings=file@1b $tmpdir |
263 sort > $testout
265 # The filesystem is not required to put file2@1b and file3@1b after file@1b.
266 # If file[23]@1b come after file@1b, it shouldn't be printed, while if they
267 # come before, they should.
268 regexp=`echo $(ls -U $tmp/$ftwtest/foo/lvl1b \
269 | sed -n '/file@1b$/,${/file[23]@1b$/p;}') | sed 's, ,|,'`
270 catcmd=cat
271 [ -n "$regexp" ] && catcmd="egrep -v $regexp"
273 $catcmd <<EOF | diff -u $testout - || exit 1
274 base = "$tmp/", file = "$ftwtest", flag = FTW_D, level = 0
275 base = "$tmp/$ftwtest/", file = "bar", flag = FTW_D, level = 1
276 base = "$tmp/$ftwtest/", file = "baz", flag = FTW_F, level = 1
277 base = "$tmp/$ftwtest/", file = "foo", flag = FTW_D, level = 1
278 base = "$tmp/$ftwtest/bar/", file = "xo", flag = FTW_F, level = 2
279 base = "$tmp/$ftwtest/foo/", file = "lvl1", flag = FTW_D, level = 2
280 base = "$tmp/$ftwtest/foo/", file = "lvl1b", flag = FTW_D, level = 2
281 base = "$tmp/$ftwtest/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
282 base = "$tmp/$ftwtest/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
283 base = "$tmp/$ftwtest/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
284 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
285 base = "$tmp/$ftwtest/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
286 base = "$tmp/$ftwtest/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
287 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
288 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
289 base = "$tmp/$ftwtest/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3
291 rm $testout
293 rm -fr $tmpdir
295 trap '' 0
297 exit 0