Try to fix today's NFS-related failure: Treat ESTALE like EACCES.
[coreutils.git] / lib / t-chdir-long
blob2da09b31efdb98c1bcf2e400b75f0a8229642029
1 #!/bin/sh
2 # Exercise chdir-long's sample main program.
4 # Copyright (C) 2005, 2006 Free Software Foundation, Inc.
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.
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.
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.
22 # FIXME: add traps and choose top level names so that
23 # temporary directories are easier to remove.
24 # FIXME: don't clobber a.out
26 gcc -DTEST_CHDIR -g -O -W -Wall \
27 chdir-long.c libcoreutils.a
29 vg='valgrind --track-fds=yes --leak-check=yes --quiet --num-callers=9'
30 vg="$vg --leak-resolution=high"
32 # Create a directory with name of the specified length.
33 # Caveat: assumes the requested length is longer than that of $TMPDIR or /tmp.
34 function mkdir_len
36 local n
37 case $# in 1) n=$1;; *) echo "Usage: $FUNCNAME N" 1>&2; return 1;; esac
38 local root=${TMPDIR=/tmp}
39 test -n "$ROOT" && root=$ROOT
40 ( cd $root &&
41 perl -e 'my $len='$n'-length "'$root'";$i=100;$d="z"x$i;
42 while ($i+2 < $len) {
43 $len -= $i + 1;
44 mkdir $d,0700 or die "$!\n";
45 chdir $d} $d="z"x($len-1);
46 mkdir $d or die "mkdir_len: $d: $!\n"' )
49 size_list=
50 pow_2=128
51 for i in 7 8 9 10 11 12 13 14 15 16 17; do
52 n=$pow_2
53 nm1=`expr $pow_2 - 1`
54 np1=`expr $pow_2 + 1`
55 size_list="$size_list $nm1 $n $np1"
56 pow_2=`expr $pow_2 \* 2`
57 done
59 for t in . /t /tmp /var/tmp; do
60 test -d $t || continue
61 printf "$t\n"
62 export TMPDIR=$t
63 for i in `echo $size_list 99999 11`; do
64 printf "$t\t$i\n"
65 mkdir_len $i
66 find $TMPDIR/zz*|tail -n1 > in
67 tt=`echo $t|tr / -`
68 # strace -o /t/k-$tt-$i ./a.out < in > out
69 ./a.out < in > out
70 # eval "$vg ./a.out no-pwd < in"
71 rm -rf $TMPDIR/zz*
72 if test "$TMPDIR" = . ; then
73 (pwd|tr -d '\n'; sed 's/^\.//' in) > k; rm -f in; mv k in
75 diff -u in out > diff \
76 || { echo FAIL $t:$i; cut -b 1-35 diff; } \
77 && rm -f diff in out
78 done
79 done
81 rm -f a.out