2336ed891e935534c3aceee244b1e17381e69ffc
[platform/upstream/coreutils.git] / tests / du / fd-leak
1 #!/bin/sh
2 # check for file descriptor leak
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   du --version
7 fi
8
9 # Call this an expensive test.  It's not that expensive, but command line
10 # limitations might induce failure on some losing systems.
11 . $srcdir/../expensive
12
13 pwd=`pwd`
14 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
15 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
16 trap '(exit $?); exit $?' 1 2 13 15
17
18 framework_failure=0
19 mkdir -p $tmp || framework_failure=1
20 cd $tmp || framework_failure=1
21 # Create 1296 (36^2) files.
22 # Their names and separating spaces take up 3887 bytes.
23 x='a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9'
24 f=
25 for i in $x; do
26   for j in $x; do
27     f="$f $i$j"
28   done
29 done
30
31 # This may fail due to command line limitations.
32 touch $f || framework_failure=1
33
34 if test $framework_failure = 1; then
35   echo "$0: failure in testing framework" 1>&2
36   (exit 1); exit 1
37 fi
38
39 fail=0
40
41 # With coreutils-5.0, this would fail due to a file descriptor leak.
42 du $f > out || fail=1
43
44 (exit $fail); exit $fail