Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / du / slink
1 #!/bin/sh
2 # Ensure that the size of a long-named-symlink is > 0.
3
4 # Copyright (C) 2002-2007 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   du --version
24 fi
25
26 pwd=`pwd`
27 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
28 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
29 trap '(exit $?); exit $?' 1 2 13 15
30
31 framework_failure=0
32 mkdir -p $tmp || framework_failure=1
33 cd $tmp || framework_failure=1
34
35 # Determine if `.' is on a local (would non-NFS be sufficient?) file system.
36 # On at least some NFS implementations, symlinks never take up space,
37
38 # So if this is a non-local file system, skip the test.
39 if df --local . >/dev/null 2>&1; then
40   : # Ok.
41 else
42   echo "$0: skipping this test, since \`.' is on a non-local file system" 1>&2
43   (exit 77); exit 77
44 fi
45
46 if df --type=xfs . >/dev/null 2>&1; then
47   # At least on Irix-6.5.19, when using an xfs file system,
48   # each created symlink (name lengths up to 255) would have a size of `0'.
49   echo "$0: skipping this test, since \`.' is on an XFS file system" 1>&2
50   (exit 77); exit 77
51 fi
52
53 if df --type=nfsv3 . >/dev/null 2>&1; then
54   # At least on OSF/1 4.0d, when using an nfsv3 file system,
55   # each created symlink can end up having a size of 0.
56   echo "$0: skipping this test, since \`.' is on an NFS file system" 1>&2
57   (exit 77); exit 77
58 fi
59
60 if test $framework_failure = 1; then
61   echo "$0: failure in testing framework" 1>&2
62   (exit 1); exit 1
63 fi
64
65 fail=0
66 symlink_name_lengths='1 15 16 31 32 59 60 63 64 127 128 255 256 511 512 1024'
67 for len in $symlink_name_lengths; do
68   name=`seq 1 $len|tr -c x y |head -c$len`
69   # Record the names of symlinks that are successfully created.
70   ln -fs $name $len > /dev/null 2>&1 \
71     && symlinks="$symlinks $len"
72 done
73
74 du -a $symlinks > out || fail=1
75
76 # Require that at least one of these symlinks has a non-zero size.
77 grep '^[1-9]' out > /dev/null || fail=1
78
79 (exit $fail); exit $fail