2.3.4-2.fc3.6
[glibc.git] / io / ftwtest-sh
blob6444ece2a2004bddcb5391edb247153bdab74c1d
1 #! /bin/sh
3 # The common objpfx, used to find libraries and the dynamic loader.
4 objpfx=$1
6 # We expect one parameter which is the test program. This must understand
7 # a number options:
8 # --phys use the FTW_PHYS flag
9 # --chdir use the FTW_CHDIR and print the current directory
10 # in the callback
11 # --depth use the FTW_DEPTH flag
12 # --early-exit print file@2 item only and return non-zero from the
13 # callback when it is seen
14 testprogram=$2
16 # We cannot test this as root.
17 if test `id | sed "s/uid=\([0-9]*\).*/\1/"` = 0; then
18 exit 0
21 # Since we use `sort' we must make sure to use the same locale everywhere.
22 LC_ALL=C
23 export LC_ALL
24 LANG=C
25 export LANG
27 # First create our scenario:
28 tmp=`echo ${TMPDIR:-/tmp} | sed 's|\(.\)/*$|\1|'`
29 tmpdir=$tmp/ftwtest.d
31 [ -f ${objpfx}elf/ld.so ] && ldso=${objpfx}elf/ld.so
33 trap 'chmod -fR a+x $tmpdir; rm -fr $tmpdir $testout' 1 2 3 15
35 if test -d $tmpdir; then
36 chmod -fR a+x $tmpdir
37 rm -fr $tmpdir
39 mkdir $tmpdir
40 mkdir $tmpdir/foo
41 mkdir $tmpdir/bar
42 echo > $tmpdir/baz
43 mkdir $tmpdir/foo/lvl1
44 echo > $tmpdir/foo/lvl1/file@1
45 mkdir $tmpdir/foo/lvl1/lvl2
46 echo > $tmpdir/foo/lvl1/lvl2/file@2
47 mkdir $tmpdir/foo/lvl1/lvl2/lvl3
48 echo > $tmpdir/foo/lvl1/lvl2/lvl3/file@3
49 ln -s $tmpdir $tmpdir/foo/lvl1/lvl2/lvl3/link@3
50 ln -s $tmpdir/foo/lvl1/lvl2 $tmpdir/foo/lvl1/lvl2/link@2
51 ln -s $tmpdir/foo/lvl1/lvl2/lvl3/lvl4 $tmpdir/foo/lvl1/link@1
52 echo > $tmpdir/bar/xo
53 chmod a-x,a+r $tmpdir/bar
55 testout=${TMPDIR:-/tmp}/ftwtest.out
57 LD_LIBRARY_PATH=$objpfx $ldso $testprogram $tmpdir |
58 sort > $testout
60 cat <<EOF | cmp $testout - || exit 1
61 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
62 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
63 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
64 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
65 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
66 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
67 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
68 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
69 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
70 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
71 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
72 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
73 EOF
74 rm $testout
76 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --depth $tmpdir |
77 sort > $testout
79 cat <<EOF | cmp $testout - || exit 1
80 base = "$tmp/", file = "ftwtest.d", flag = FTW_DP, level = 0
81 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_DP, level = 1
82 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
83 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_DP, level = 1
84 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
85 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_DP, level = 2
86 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
87 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
88 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_DP, level = 3
89 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
90 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_DP, level = 4
91 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
92 EOF
93 rm $testout
95 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --phys $tmpdir |
96 sort > $testout
98 cat <<EOF | cmp $testout - || exit 1
99 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
100 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
101 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
102 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
103 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
104 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
105 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
106 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SL, level = 3
107 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
108 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
109 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "link@2", flag = FTW_SL, level = 4
110 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
111 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
112 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "link@3", flag = FTW_SL, level = 5
114 rm $testout
116 # For the next test everything must be readable.
117 chmod -fR a+x $tmpdir
119 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir $tmpdir |
120 sort > $testout
122 # perhaps $tmp involves some symlinks...
123 tmpreal=`cd $tmp; /bin/pwd 2>/dev/null || /usr/bin/pwd`
125 cat <<EOF | cmp $testout - || exit 1
126 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, cwd = $tmpreal, level = 0
127 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
128 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
129 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
130 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
131 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
132 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
133 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
134 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
135 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
136 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
137 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
139 rm $testout
141 curwd=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
142 cd "$tmp"
143 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir ftwtest.d |
144 sort > $testout
145 cd "$curwd"
147 cat <<EOF | diff -u $testout - || exit 1
148 base = "", file = "ftwtest.d", flag = FTW_D, cwd = $tmpreal, level = 0
149 base = "ftwtest.d/", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
150 base = "ftwtest.d/", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
151 base = "ftwtest.d/", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
152 base = "ftwtest.d/bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
153 base = "ftwtest.d/foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
154 base = "ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
155 base = "ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
156 base = "ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
157 base = "ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
158 base = "ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
159 base = "ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
161 rm $testout
163 curwd=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
164 cd "$tmp"
165 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir ftwtest.d/. |
166 sort > $testout
167 cd "$curwd"
169 cat <<EOF | diff -u $testout - || exit 1
170 base = "ftwtest.d/", file = ".", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 0
171 base = "ftwtest.d/./", file = "bar", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
172 base = "ftwtest.d/./", file = "baz", flag = FTW_F, cwd = $tmpreal/ftwtest.d, level = 1
173 base = "ftwtest.d/./", file = "foo", flag = FTW_D, cwd = $tmpreal/ftwtest.d, level = 1
174 base = "ftwtest.d/./bar/", file = "xo", flag = FTW_F, cwd = $tmpreal/ftwtest.d/bar, level = 2
175 base = "ftwtest.d/./foo/", file = "lvl1", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo, level = 2
176 base = "ftwtest.d/./foo/lvl1/", file = "file@1", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
177 base = "ftwtest.d/./foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
178 base = "ftwtest.d/./foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 3
179 base = "ftwtest.d/./foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
180 base = "ftwtest.d/./foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2, level = 4
181 base = "ftwtest.d/./foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = $tmpreal/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
183 rm $testout
185 curwd=`/bin/pwd 2>/dev/null || /usr/bin/pwd`
186 cd "$tmp"
187 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir ftwtest.d/foo/lvl1/link@1 |
188 sort > $testout
189 cd "$curwd"
191 cat <<EOF | diff -u $testout - || exit 1
192 base = "ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = $tmpreal/ftwtest.d/foo/lvl1, level = 0
194 rm $testout
196 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --early-exit $tmpdir |
197 sort > $testout
199 cat <<EOF | cmp $testout - || exit 1
200 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
201 succeeded
203 rm $testout
205 mkdir $tmpdir/foo/lvl1b
206 echo > $tmpdir/foo/lvl1b/file@1b
207 echo > $tmpdir/foo/lvl1b/file2@1b
208 echo > $tmpdir/foo/lvl1b/file3@1b
210 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --skip-subtree=lvl1 $tmpdir |
211 sort > $testout
213 cat <<EOF | diff -u $testout - || exit 1
214 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
215 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
216 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
217 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
218 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, level = 2
219 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
220 base = "$tmp/ftwtest.d/foo/", file = "lvl1b", flag = FTW_D, level = 2
221 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
222 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
223 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3
225 rm $testout
227 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --skip-siblings=lvl1 $tmpdir |
228 sort > $testout
230 # The filesystem is not required to put lvl1 before lvl1b.
231 # If lvl1b comes after lvl1, it shouldn't be printed, while if it
232 # comes before, it should.
233 catcmd=cat
234 [ -n "`ls -U $tmpdir/foo/ | sed -n '/lvl1$/,${/lvl1b$/p;}'`" ] \
235 && catcmd="grep -v lvl1b"
237 $catcmd <<EOF | diff -u $testout - || exit 1
238 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
239 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
240 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
241 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
242 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, level = 2
243 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
244 base = "$tmp/ftwtest.d/foo/", file = "lvl1b", flag = FTW_D, level = 2
245 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
246 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
247 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3
249 rm $testout
251 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --skip-siblings=file@1b $tmpdir |
252 sort > $testout
254 # The filesystem is not required to put file2@1b and file3@1b after file@1b.
255 # If file[23]@1b come after file@1b, it shouldn't be printed, while if they
256 # come before, they should.
257 regexp=`echo $(ls -U $tmp/ftwtest.d/foo/lvl1b \
258 | sed -n '/file@1b$/,${/file[23]@1b$/p;}') | sed 's, ,|,'`
259 catcmd=cat
260 [ -n "$regexp" ] && catcmd="egrep -v $regexp"
262 $catcmd <<EOF | diff -u $testout - || exit 1
263 base = "$tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
264 base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
265 base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
266 base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
267 base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, level = 2
268 base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
269 base = "$tmp/ftwtest.d/foo/", file = "lvl1b", flag = FTW_D, level = 2
270 base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
271 base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
272 base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
273 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
274 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
275 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
276 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file2@1b", flag = FTW_F, level = 3
277 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file3@1b", flag = FTW_F, level = 3
278 base = "$tmp/ftwtest.d/foo/lvl1b/", file = "file@1b", flag = FTW_F, level = 3
280 rm $testout
282 rm -fr $tmpdir
284 exit 0