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