Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / du / basic
1 #!/bin/sh
2 # Compare actual numbers from du, assuming block size matches mine.
3
4 # Copyright (C) 2003, 2006 Free Software Foundation, Inc.
5
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.
10
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.
15
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.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   du --version
24 fi
25
26 # DU_BLOCK_SIZE could cause problems
27 . $srcdir/../envvar-check
28 . $srcdir/../lang-default
29
30 pwd=`pwd`
31 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
32 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
33 trap '(exit $?); exit $?' 1 2 13 15
34
35 framework_failure=0
36 mkdir -p $tmp || framework_failure=1
37 cd $tmp || framework_failure=1
38 mkdir -p a/b d d/sub || framework_failure=1
39
40 # Ensure that these files contain more than 64 bytes, so that we don't
41 # immediately disqualify file systems (e.g., NetApp) on which smaller
42 # files take up zero disk blocks.
43 printf '%*s' 257 make-sure-the-file-is-non-empty > a/b/F || framework_failure=1
44 seq --format=%100g 1 90 | head --bytes=4k > d/1
45 cp d/1 d/sub/2
46
47 if test $framework_failure = 1; then
48   echo "$0: failure in testing framework" 1>&2
49   (exit 1); exit 1
50 fi
51
52 fail=0
53
54 B=`stat --format=%B a/b/F`
55
56 du --block-size=$B -a a > out || fail=1
57 echo === >> out
58 du --block-size=$B -a -S a >> out || fail=1
59 echo === >> out
60 du --block-size=$B -s a >> out || fail=1
61
62 f=`stat --format=%b a/b/F`
63 b=`stat --format=%b a/b`
64 a=`stat --format=%b a`
65 bf=`expr $b + $f`
66 tot=`expr $bf + $a`
67
68 cat <<EOF | sed 's/ *#.*//' > exp
69 $f      a/b/F
70 $bf     a/b
71 $tot    a
72 ===
73 $f      a/b/F   # size of file, a/b/F
74 $bf     a/b     # size of dir entry, a/b, + size of file, a/b/F
75 $a      a       # size of dir entry, a
76 ===
77 $tot    a
78 EOF
79
80 cmp out exp || fail=1
81 test $fail = 1 && diff -u out exp 2> /dev/null
82
83 rm -f out exp
84 du --block-size=$B -a d | sort -r -k2,2 > out || fail=1
85 echo === >> out
86 du --block-size=$B -S d | sort -r -k2,2 >> out || fail=1
87
88 t2=`stat --format=%b d/sub/2`
89 ts=`stat --format=%b d/sub`
90 t1=`stat --format=%b d/1`
91 td=`stat --format=%b d`
92 tot=`expr $t1 + $t2 + $ts + $td`
93 d1=`expr $td + $t1`
94 s2=`expr $ts + $t2`
95
96 cat <<EOF | sed 's/ *#.*//' > exp
97 $t2     d/sub/2
98 $s2     d/sub
99 $t1     d/1
100 $tot    d
101 ===
102 $s2     d/sub
103 $d1     d           # d + d/1; don't count the dir. entry for d/sub
104 EOF
105
106 cmp out exp || fail=1
107 test $fail = 1 && diff out exp 2> /dev/null
108
109 (exit $fail); exit $fail