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.
6 if test "$VERBOSE" = yes; then
11 . $srcdir/../envvar-check
13 # Creating a 2GB file counts as `very expensive'.
14 . $srcdir/../very-expensive
17 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
18 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
19 trap '(exit $?); exit $?' 1 2 13 15
22 mkdir -p $tmp || framework_failure=1
23 cd $tmp || framework_failure=1
25 if test $framework_failure = 1; then
26 echo "$0: failure in testing framework" 1>&2
32 # Get number of free kilobytes on current partition, so we can
33 # skip this test if there is insufficient free space.
35 # This technique relies on the fact that the `Available' kilobyte
36 # count is the number just before the one with a trailing `%'.
37 free_kb=`df -kP .|tail -1|sed 's/ [0-9][0-9]*%.*//;s/ *$//;s/.* //'`
40 *) echo "invalid size from df: $free_kb" 1>&2; (exit 77); exit 77;;
43 # Require about 3GB free.
45 test $min_kb -lt $free_kb ||
47 echo "$0: skipping this test:"
48 echo "too little free space on current partition: $free_kb (need $min_kb KB)" \
55 test -t 1 || printf 'creating a 2GB file...\n'
56 for i in `seq 100`; do
57 # Note: 2147483648 == 2^31. Print floor(2^31/100) per iteration.
58 printf %21474836s x >> $big || fail=1
59 # On the final iteration, append the remaining 48 bytes.
60 test $i = 100 && { printf %48s x >> $big || fail=1; }
61 test -t 1 && printf 'creating a 2GB file: %d%% complete\r' $i
65 du -k $big > out1 || fail=1
67 sed 's/^2[0-9][0-9][0-9][0-9][0-9][0-9] '$big'$/~2M/' out1 > out
69 cat <<\EOF > exp || fail=1
74 test $fail = 1 && diff out exp 2> /dev/null
76 (exit $fail); exit $fail