Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / du / 2g
1 #!/bin/sh
2 # Ensure that du can handle a 2GB file (i.e., a file of size 2^31 bytes)
3 # Before coreutils-5.93, on systems with a signed, 32-bit stat.st_blocks
4 # one of du's computations would overflow.
5
6 # Copyright (C) 2005, 2006 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 2 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, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 if test "$VERBOSE" = yes; then
24   set -x
25   du --version
26 fi
27
28 . $srcdir/../envvar-check
29
30 # Creating a 2GB file counts as `very expensive'.
31 . $srcdir/../very-expensive
32
33 pwd=`pwd`
34 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
35 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
36 trap '(exit $?); exit $?' 1 2 13 15
37
38 framework_failure=0
39 mkdir -p $tmp || framework_failure=1
40 cd $tmp || framework_failure=1
41
42 if test $framework_failure = 1; then
43   echo "$0: failure in testing framework" 1>&2
44   (exit 1); exit 1
45 fi
46
47 fail=0
48
49 # Get number of free kilobytes on current partition, so we can
50 # skip this test if there is insufficient free space.
51
52 # This technique relies on the fact that the `Available' kilobyte
53 # count is the number just before the one with a trailing `%'.
54 free_kb=`df -kP .|tail -1|sed 's/ [0-9][0-9]*%.*//;s/ *$//;s/.* //'`
55 case "$free_kb" in
56   [0-9]*) ;;
57   *) echo "invalid size from df: $free_kb" 1>&2; (exit 77); exit 77;;
58 esac
59
60 # Require about 3GB free.
61 min_kb=3000000
62 test $min_kb -lt $free_kb ||
63 {
64   echo "$0: skipping this test:"
65   echo "too little free space on current partition: $free_kb (need $min_kb KB)" \
66     1>&2;
67   (exit 77); exit 77
68 }
69
70 big=big
71 rm -f $big
72 test -t 1 || printf 'creating a 2GB file...\n'
73 for i in `seq 100`; do
74   # Note: 2147483648 == 2^31. Print floor(2^31/100) per iteration.
75   printf %21474836s x >> $big || fail=1
76   # On the final iteration, append the remaining 48 bytes.
77   test $i = 100 && { printf %48s x >> $big || fail=1; }
78   test -t 1 && printf 'creating a 2GB file: %d%% complete\r' $i
79 done
80 echo
81
82 du -k $big > out1 || fail=1
83 rm -f $big
84 sed 's/^2[0-9][0-9][0-9][0-9][0-9][0-9] '$big'$/~2M/' out1 > out
85
86 cat <<\EOF > exp || fail=1
87 ~2M
88 EOF
89
90 cmp out exp || fail=1
91 test $fail = 1 && diff out exp 2> /dev/null
92
93 (exit $fail); exit $fail