about summary refs log tree commit diff
path: root/io/ftwtest-sh
blob: 79c35d4f9c711120502170fd3faac032566ae946 (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
#! /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
base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D
base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F
base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D
base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS
base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D
base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F
base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN
base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F
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
base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_DP
base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F
base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_DP
base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS
base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_DP
base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F
base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SLN
base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_DP
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_DP
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F
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
base = "$tmp/ftwtest.d/", file = "bar", flag = FTW_D
base = "$tmp/ftwtest.d/", file = "baz", flag = FTW_F
base = "$tmp/ftwtest.d/", file = "foo", flag = FTW_D
base = "$tmp/ftwtest.d/bar/", file = "xo", flag = FTW_NS
base = "$tmp/ftwtest.d/foo/", file = "lvl1", flag = FTW_D
base = "$tmp/ftwtest.d/foo/lvl1/", file = "file@1", flag = FTW_F
base = "$tmp/ftwtest.d/foo/lvl1/", file = "link@1", flag = FTW_SL
base = "$tmp/ftwtest.d/foo/lvl1/", file = "lvl2", flag = FTW_D
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "file@2", flag = FTW_F
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "link@2", flag = FTW_SL
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/", file = "lvl3", flag = FTW_D
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "file@3", flag = FTW_F
base = "$tmp/ftwtest.d/foo/lvl1/lvl2/lvl3/", file = "link@3", flag = FTW_SL
EOF
rm $testout

chmod -R a+x $tmpdir
rm -fr $tmpdir

exit 0