* elf/Makefile (test-extras): Define this instead of test-srcs.
[glibc.git] / io / ftwtest-sh
blob7fc82088ecf81588a98f4bdcb9752397c27812af
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 LD_LIBRARY_PATH=$objpfx $ldso $testprogram --early-exit $tmpdir |
142 sort > $testout
144 cat <<EOF | cmp $testout - || exit 1
145 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
146 succeeded
148 rm $testout
150 rm -fr $tmpdir
152 exit 0