3 # The common objpfx, used to find libraries and the dynamic loader.
6 # We expect one parameter which is the test program. This must understand
8 # --phys use the FTW_PHYS flag
9 # --chdir use the FTW_CHDIR and print the current directory
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
16 # We cannot test this as root.
17 if test `id | sed "s/uid=\([0-9]*\).*/\1/"` = 0; then
21 # Since we use `sort' we must make sure to use the same locale everywhere.
27 # First create our scenario:
28 tmp
=`echo ${TMPDIR:-/tmp} | sed 's|\(.\)/*$|\1|'`
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
43 mkdir
$tmpdir/foo
/lvl1
44 echo > $tmpdir/foo
/lvl
1/file@
1
45 mkdir
$tmpdir/foo
/lvl
1/lvl2
46 echo > $tmpdir/foo
/lvl
1/lvl
2/file@
2
47 mkdir
$tmpdir/foo
/lvl
1/lvl
2/lvl3
48 echo > $tmpdir/foo
/lvl
1/lvl
2/lvl
3/file@
3
49 ln -s $tmpdir $tmpdir/foo
/lvl
1/lvl
2/lvl
3/link@
3
50 ln -s $tmpdir/foo
/lvl
1/lvl2
$tmpdir/foo
/lvl
1/lvl
2/link@
2
51 ln -s $tmpdir/foo
/lvl
1/lvl
2/lvl
3/lvl4
$tmpdir/foo
/lvl
1/link@
1
53 chmod a-x
,a
+r
$tmpdir/bar
55 testout
=${TMPDIR:-/tmp}/ftwtest.out
57 LD_LIBRARY_PATH
=$objpfx $ldso $testprogram $tmpdir |
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
76 LD_LIBRARY_PATH
=$objpfx $ldso $testprogram --depth $tmpdir |
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
95 LD_LIBRARY_PATH
=$objpfx $ldso $testprogram --phys $tmpdir |
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
116 # For the next test everything must be readable.
117 chmod -fR a
+x
$tmpdir
119 LD_LIBRARY_PATH
=$objpfx $ldso $testprogram --chdir $tmpdir |
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
141 LD_LIBRARY_PATH
=$objpfx $ldso $testprogram --early-exit $tmpdir |
144 cat <<EOF | cmp $testout - || exit 1
145 base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4