tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / du / long-sloop
1 #!/bin/sh
2 # Use du to exercise a corner of fts's FTS_LOGICAL code.
3 # Show that du fails with ELOOP (Too many levels of symbolic links)
4 # when it encounters that condition.
5
6 # Copyright (C) 2006-2009 Free Software Foundation, Inc.
7
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   du --version
24 fi
25
26 . $srcdir/test-lib.sh
27
28 # Create lots of directories, each containing a single symlink
29 # pointing at the next directory in the list.
30
31 # This number should be larger than the number of symlinks allowed in
32 # file name resolution, but not too large as a number of entries
33 # in a single directory.
34 n=400
35
36 dir_list=`seq $n`
37 mkdir $dir_list || framework_failure
38 file=1
39 i_minus_1=0
40 for i in $dir_list `expr $n + 1`; do
41   case $i_minus_1 in
42   0) ;;
43   *)
44     ln -s ../$i $i_minus_1/s || framework_failure
45     file=$file/s;;
46   esac
47   i_minus_1=$i
48 done
49 echo foo > $i
50
51 # If a system can handle this many symlinks in a file name,
52 # just skip this test.
53
54 # The following also serves to record in `err' the string
55 # corresponding to strerror (ELOOP).  This is necessary because while
56 # Linux/libc gives `Too many levels of symbolic links', Solaris
57 # renders it as `Number of symbolic links encountered during path
58 # name traversal exceeds MAXSYMLINKS'.
59
60 cat $file > /dev/null 2> err &&
61     skip_test_ 'Your system appears to be able to handle more than $n symlinks
62 in file name resolution'
63 too_many=`sed 's/.*: //' err`
64
65
66 # With coreutils-5.93 there was no failure.
67 # With coreutils-5.94 we get the desired diagnostic:
68 # du: cannot access `1/s/s/s/.../s': Too many levels of symbolic links
69 du -L 1 > /dev/null 2> out1 && fail=1
70 sed "s, .1/s/s/s/[/s]*',," out1 > out || fail=1
71
72 echo "du: cannot access: $too_many" > exp || fail=1
73
74 compare out exp || fail=1
75
76 Exit $fail