summary refs log tree commit diff
path: root/io/ftwtest-sh
blob: f0cd56ab0235fc2455678e4b68ba2ab58ebe681e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#! /bin/sh

# The common objpfx, used to find libraries and the dynamic loader.
objpfx=$1

# We expect one parameter which is the test program.  This must understand
# a number options:
#   --phys	use the FTW_PHYS flag
#   --chdir	use the FTW_CHDIR and print the current directory in the
#		callback
#   --depth	use the FTW_DEPTH flag
testprogram=$2


# First create our scenario:
tmp=${TMPDIR:-/tmp}
tmpdir=$tmp/ftwtest.d

[ -f ${objpfx}elf/ld.so ] && ldso=${objpfx}elf/ld.so

trap 'chmod -R a+x $tmpdir; rm -fr $tmpdir $testout' 1 2 3 15

if test -d $tmpdir; then
  chmod -R a+x $tmpdir
  rm -fr $tmpdir
fi
mkdir $tmpdir
mkdir $tmpdir/foo
mkdir $tmpdir/bar
echo > $tmpdir/baz
mkdir $tmpdir/foo/lvl1
echo > $tmpdir/foo/lvl1/file@1
mkdir $tmpdir/foo/lvl1/lvl2
echo > $tmpdir/foo/lvl1/lvl2/file@2
mkdir $tmpdir/foo/lvl1/lvl2/lvl3
echo > $tmpdir/foo/lvl1/lvl2/lvl3/file@3
ln -s $tmpdir $tmpdir/foo/lvl1/lvl2/lvl3/link@3
ln -s $tmpdir/foo/lvl1/lvl2 $tmpdir/foo/lvl1/lvl2/link@2
ln -s $tmpdir/foo/lvl1/lvl2/lvl3/lvl4 $tmpdir/foo/lvl1/link@1
echo > $tmpdir/bar/xo
chmod a-x,a+r $tmpdir/bar

testout=${TMPDIR:-/tmp}/ftwtest.out

LD_LIBRARY_PATH=$objpfx $ldso $testprogram $tmpdir |
    sort > $testout

cat <<EOF | cmp $testout - || exit 1
base = "/tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
base = "/tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
base = "/tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
base = "/tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
base = "/tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
base = "/tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
base = "/tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
EOF
rm $testout

LD_LIBRARY_PATH=$objpfx $ldso $testprogram --depth $tmpdir |
    sort > $testout

cat <<EOF | cmp $testout - || exit 1
base = "/tmp/", file = "ftwtest.d", flag = FTW_DP, level = 0
base = "/tmp/ftwtest.d/", file = "bar", flag = FTW_DP, level = 1
base = "/tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
base = "/tmp/ftwtest.d/", file = "foo", flag = FTW_DP, level = 1
base = "/tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
base = "/tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_DP, level = 2
base = "/tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_DP, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_DP, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
EOF
rm $testout

LD_LIBRARY_PATH=$objpfx $ldso $testprogram --phys $tmpdir |
    sort > $testout

cat <<EOF | cmp $testout - || exit 1
base = "/tmp/", file = "ftwtest.d", flag = FTW_D, level = 0
base = "/tmp/ftwtest.d/", file = "bar", flag = FTW_D, level = 1
base = "/tmp/ftwtest.d/", file = "baz", flag = FTW_F, level = 1
base = "/tmp/ftwtest.d/", file = "foo", flag = FTW_D, level = 1
base = "/tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS, level = 2
base = "/tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, level = 2
base = "/tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SL, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "link@2", flag = FTW_SL, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, level = 5
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "link@3", flag = FTW_SL, level = 5
EOF
rm $testout

# For the next test everything must be readable.
chmod -R a+x $tmpdir

LD_LIBRARY_PATH=$objpfx $ldso $testprogram --chdir $tmpdir |
    sort > $testout

cat <<EOF | cmp $testout - || exit 1
base = "/tmp/", file = "ftwtest.d", flag = FTW_D, cwd = /tmp, level = 0
base = "/tmp/ftwtest.d/", file = "bar", flag = FTW_D, cwd = /tmp/ftwtest.d, level = 1
base = "/tmp/ftwtest.d/", file = "baz", flag = FTW_F, cwd = /tmp/ftwtest.d, level = 1
base = "/tmp/ftwtest.d/", file = "foo", flag = FTW_D, cwd = /tmp/ftwtest.d, level = 1
base = "/tmp/ftwtest.d/bar/", file = "xo", flag = FTW_F, cwd = /tmp/ftwtest.d/bar, level = 2
base = "/tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D, cwd = /tmp/ftwtest.d/foo, level = 2
base = "/tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F, cwd = /tmp/ftwtest.d/foo/lvl1, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN, cwd = /tmp/ftwtest.d/foo/lvl1, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D, cwd = /tmp/ftwtest.d/foo/lvl1, level = 3
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F, cwd = /tmp/ftwtest.d/foo/lvl1/lvl2, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D, cwd = /tmp/ftwtest.d/foo/lvl1/lvl2, level = 4
base = "/tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F, cwd = /tmp/ftwtest.d/foo/lvl1/lvl2/lvl3, level = 5
EOF
rm $testout

rm -fr $tmpdir

exit 0