*** empty log message ***
[platform/upstream/coreutils.git] / lib / t-chdir-long
1 #!/bin/sh
2 # Exercise chdir-long's sample main program.
3 # FIXME: add traps and choose top level names so that
4 # temporary directories are easier to remove.
5 # FIXME: don't clobber a.out
6
7 gcc -DTEST_CHDIR=1 -DHAVE_CONFIG_H -I.. -g -O -W -Wall \
8   chdir-long.c libcoreutils.a
9
10 vg='valgrind --track-fds=yes --leak-check=yes --quiet --num-callers=9'
11 vg="$vg --leak-resolution=high"
12
13 # Create a directory with name of the specified length.
14 # Caveat: assumes the requested length is longer than that of $TMPDIR or /tmp.
15 function mkdir_len
16 {
17   local n
18   case $# in 1) n=$1;; *) echo "Usage: $FUNCNAME N" 1>&2; return 1;; esac
19   local root=${TMPDIR=/tmp}
20   test -n "$ROOT" && root=$ROOT
21   ( cd $root &&
22     perl -e 'my $len='$n'-length "'$root'";$i=100;$d="z"x$i;
23                   while ($i+2 < $len) {
24                     $len -= $i + 1;
25                     mkdir $d,0700 or die "$!\n";
26                     chdir $d} $d="z"x($len-1);
27                     mkdir $d or die "mkdir_len: $d: $!\n"' )
28 }
29
30 size_list=
31 pow_2=128
32 for i in 7 8 9 10 11 12 13 14 15 16 17; do
33   n=$pow_2
34   nm1=`expr $pow_2 - 1`
35   np1=`expr $pow_2 + 1`
36   size_list="$size_list $nm1 $n $np1"
37   pow_2=`expr $pow_2 \* 2`
38 done
39
40 for t in . /t /tmp /var/tmp; do
41   test -d $t || continue
42   printf "$t\n"
43   export TMPDIR=$t
44   for i in `echo $size_list 99999 11`; do
45     printf "$t\t$i\n"
46     mkdir_len $i
47     find $TMPDIR/zz*|tail -n1 > in
48     tt=`echo $t|tr / -`
49     # strace -o /t/k-$tt-$i ./a.out < in > out
50     ./a.out < in > out
51     # eval "$vg ./a.out no-pwd < in"
52     rm -rf $TMPDIR/zz*
53     if test "$TMPDIR" = . ; then
54       (pwd|tr -d '\n'; sed 's/^\.//' in) > k; rm -f in; mv k in
55     fi
56     diff -u in out > diff \
57       || { echo FAIL $t:$i; cut -b 1-35 diff; } \
58       && rm -f diff in out
59   done
60 done
61
62 rm -f a.out