2 # Exercise du's --threshold option.
4 # Copyright (C) 2013-2024 Free Software Foundation, Inc.
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 3 of the License, or
9 # (at your option) any later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
22 mkdir
-p a
/b a
/c || framework_failure_
24 touch a
/b
/0 || framework_failure_
25 printf '%1s' x
> a
/b
/1 || framework_failure_
26 printf '%2s' x
> a
/b
/2 || framework_failure_
27 printf '%3s' x
> a
/b
/3 || framework_failure_
29 Ba
=$
(stat
--format="%B * %b" a |
xargs expr)
30 Bb
=$
(stat
--format="%B * %b" a
/b |
xargs expr)
31 Bc
=$
(stat
--format="%B * %b" a
/c |
xargs expr)
32 B0
=$
(stat
--format="%B * %b" a
/b
/0 |
xargs expr)
33 B1
=$
(stat
--format="%B * %b" a
/b
/1 |
xargs expr)
34 B2
=$
(stat
--format="%B * %b" a
/b
/2 |
xargs expr)
35 B3
=$
(stat
--format="%B * %b" a
/b
/3 |
xargs expr)
37 Sa
=0 # du always assumes st_size=0 for dirs
40 S0
=$
(stat
--format=%s a
/b
/0)
41 S1
=$
(stat
--format=%s a
/b
/1)
42 S2
=$
(stat
--format=%s a
/b
/2)
43 S3
=$
(stat
--format=%s a
/b
/3)
45 Bb0123
=$
(expr $Bb + $B0 + $B1 + $B2 + $B3)
46 Sb0123
=$
(expr $Sb + $S0 + $S1 + $S2 + $S3)
48 Bab0123
=$
(expr $Ba + $Bc + $Bb0123)
51 test $Ba -gt 4 || skip_
"block size of a directory is smaller than 4 bytes"
52 test $Bc -gt 4 || skip_
"block size of an empty directory is smaller than 4 \
54 test $B1 -gt 4 || skip_
"block size of small file smaller than 4 bytes"
55 test $S3 -eq 3 || framework_failure_
56 test $S2 -eq 2 || framework_failure_
57 test $S1 -eq 1 || framework_failure_
58 test $S0 -eq 0 || framework_failure_
59 test $B0 -eq 0 || skip_
"block size of an empty file unequal Zero"
60 # block size of a/b/1 == a/b/2
61 test $B1 -eq $B2 || framework_failure_
62 # a is bigger than a/b.
63 test $Bab0123 -gt $Bb0123 || framework_failure_
64 # a/b is bigger than empty a/c.
65 test $Sb0123 -gt $Sc || framework_failure_
66 test $Bb0123 -gt $Bc || framework_failure_
68 # Exercise a bad argument: unparsable number.
70 du: invalid --threshold argument 'SIZE'
72 du
--threshold=SIZE a
> out
2>&1 && fail
=1
73 compare exp out || fail
=1
76 du: invalid -t argument 'SIZE'
78 du
-t SIZE a
> out
2>&1 && fail
=1
79 compare exp out || fail
=1
81 # Exercise a bad argument: -0 is not valid.
83 du: invalid --threshold argument '-0'
85 du
--threshold=-0 a
> out
2>&1 && fail
=1
86 compare exp out || fail
=1
88 du
-t -0 a
> out
2>&1 && fail
=1
89 compare exp out || fail
=1
91 du
-t-0 a
> out
2>&1 && fail
=1
92 compare exp out || fail
=1
94 # Exercise a bad argument: empty argument.
96 du: invalid --threshold argument ''
98 du
--threshold= a
> out
2>&1 && fail
=1
99 compare exp out || fail
=1
101 # Exercise a bad argument: no argument.
102 du
--threshold > out.tmp
2>&1 && fail
=1
103 sed 's/argument.*/argument/; s/option.*requires/option requires/' \
104 < out.tmp
> out || framework_failure_
106 du: option requires an argument
107 Try 'du --help' for more information.
109 compare exp out || fail
=1
120 if [ "$exp" = "" ] ; then
123 printf "%s\n" $exp > exp
127 du
-B1 $args a
> out1
2>&1 ||
{ cat out1
; rc
=1 ; }
129 # Remove the size column and sort the output.
130 cut
-f2- out1 |
sort > out || framework_failure_
132 compare exp out ||
{ cat out1
; rc
=1 ; }
136 # Check numbers around the total size of the main directory 'a'.
137 # One byte greater than 'a'.
138 s
=$
(expr $Bab0123 + 1) # block size
139 dutest
" -t $s" '' || fail
=1
140 dutest
" -a -t $s" '' || fail
=1
141 dutest
" -S -t $s" '' || fail
=1
142 dutest
" -a -S -t $s" '' || fail
=1
143 dutest
" -t -$s" 'a a/b a/c' || fail
=1
144 dutest
" -a -t -$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
145 dutest
" -S -t -$s" 'a a/b a/c' || fail
=1
146 dutest
" -a -S -t -$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
148 # Exactly the size of 'a'.
149 s
=$Bab0123 # block size
150 dutest
" --th=$s" 'a' || fail
=1
151 dutest
" -a --th=$s" 'a' || fail
=1
152 dutest
" -S --th=$s" '' || fail
=1
153 dutest
" -a -S --th=$s" '' || fail
=1
154 dutest
" --th=-$s" 'a a/b a/c' || fail
=1
155 dutest
" -a --th=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
156 dutest
" -S --th=-$s" 'a a/b a/c' || fail
=1
157 dutest
" -a -S --th=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
159 # One byte smaller than 'a'.
160 s
=$
(expr $Bab0123 - 1) # block size
161 dutest
" --th=$s" 'a' || fail
=1
162 dutest
" -a --th=$s" 'a' || fail
=1
163 dutest
" -S --th=$s" '' || fail
=1
164 dutest
" -a -S --th=$s" '' || fail
=1
165 dutest
" --th=-$s" 'a/b a/c' || fail
=1
166 dutest
" -a --th=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
167 dutest
" -S --th=-$s" 'a a/b a/c' || fail
=1
168 dutest
" -a -S --th=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
171 # Check numbers around the total size of the sub directory 'a/b'.
172 # One byte greater than 'a/b'.
173 s
=$
(expr $Bb0123 + 1) # block size
174 dutest
" --th=$s" 'a' || fail
=1
175 dutest
" -a --th=$s" 'a' || fail
=1
176 dutest
" -S --th=$s" '' || fail
=1
177 dutest
" -a -S --th=$s" '' || fail
=1
178 dutest
" --th=-$s" 'a/b a/c' || fail
=1
179 dutest
" -a --th=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
180 dutest
" -S --th=-$s" 'a a/b a/c' || fail
=1
181 dutest
" -a -S --th=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
183 # Exactly the size of 'a/b'.
184 s
=$Bb0123 # block size
185 dutest
" --th=$s" 'a a/b' || fail
=1
186 dutest
" -a --th=$s" 'a a/b' || fail
=1
187 dutest
" -S --th=$s" 'a/b' || fail
=1
188 dutest
" -a -S --th=$s" 'a/b' || fail
=1
189 dutest
" --th=-$s" 'a/b a/c' || fail
=1
190 dutest
" -a --th=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
191 dutest
" -S --th=-$s" 'a a/b a/c' || fail
=1
192 dutest
" -a -S --th=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
194 # One byte smaller than 'a/b'.
195 s
=$
(expr $Bb0123 - 1) # block size
196 dutest
" --th=$s" 'a a/b' || fail
=1
197 dutest
" -a --th=$s" 'a a/b' || fail
=1
198 dutest
" -S --th=$s" 'a/b' || fail
=1
199 dutest
" -a -S --th=$s" 'a/b' || fail
=1
200 dutest
" --th=-$s" 'a/c' || fail
=1
201 dutest
" -a --th=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
202 dutest
" -S --th=-$s" 'a a/c' || fail
=1
203 dutest
" -a -S --th=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
206 # Check numbers around the total size of the files a/b/[0123]'.
207 echo One byte greater than
'a/b/3'.
208 s
=$
(expr $B3 + 1) # block size
209 dutest
" --th=$s" 'a a/b' || fail
=1
210 dutest
" -a --th=$s" 'a a/b' || fail
=1
211 dutest
" -S --th=$s" 'a/b' || fail
=1
212 dutest
" -a -S --th=$s" 'a/b' || fail
=1
213 dutest
" --th=-$s" 'a/c' || fail
=1
214 dutest
" -a --th=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
215 dutest
" -S --th=-$s" 'a a/c' || fail
=1
216 dutest
" -a -S --th=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
218 # Exactly the size of 'a/b/3'.
219 echo Exactly the size of
'a/b/3'.
221 dutest
" --th=$s" 'a a/b a/c' || fail
=1
222 dutest
" -a --th=$s" 'a a/b a/b/1 a/b/2 a/b/3 a/c' || fail
=1
223 dutest
" -S --th=$s" 'a a/b a/c' || fail
=1
224 dutest
" -a -S --th=$s" 'a a/b a/b/1 a/b/2 a/b/3 a/c' || fail
=1
225 dutest
" --th=-$s" 'a/c' || fail
=1
226 dutest
" -a --th=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
227 dutest
" -S --th=-$s" 'a a/c' || fail
=1
228 dutest
" -a -S --th=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
230 # Exactly the size of 'a/b/2'.
231 echo Exactly the size of
'a/b/2'.
233 dutest
" --th=$s" 'a a/b a/c' || fail
=1
234 dutest
" -a --th=$s" 'a a/b a/b/1 a/b/2 a/b/3 a/c' || fail
=1
235 dutest
" -S --th=$s" 'a a/b a/c' || fail
=1
236 dutest
" -a -S --th=$s" 'a a/b a/b/1 a/b/2 a/b/3 a/c' || fail
=1
237 dutest
" --th=-$s" 'a/c' || fail
=1
238 dutest
" -a --th=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
239 dutest
" -S --th=-$s" 'a a/c' || fail
=1
240 dutest
" -a -S --th=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
242 # Exactly the size of 'a/b/1'.
243 echo Exactly the size of
'a/b/1'.
245 dutest
" --th=$s" 'a a/b a/c' || fail
=1
246 dutest
" -a --th=$s" 'a a/b a/b/1 a/b/2 a/b/3 a/c' || fail
=1
247 dutest
" -S --th=$s" 'a a/b a/c' || fail
=1
248 dutest
" -a -S --th=$s" 'a a/b a/b/1 a/b/2 a/b/3 a/c' || fail
=1
249 dutest
" --th=-$s" 'a/c' || fail
=1
250 dutest
" -a --th=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
251 dutest
" -S --th=-$s" 'a a/c' || fail
=1
252 dutest
" -a -S --th=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
254 # Exactly the size of 'a/b/0'.
255 echo Exactly the size of
'a/b/0'.
257 dutest
" --th=$s" 'a a/b a/c' || fail
=1
258 dutest
" -a --th=$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
259 dutest
" -S --th=$s" 'a a/b a/c' || fail
=1
260 dutest
" -a -S --th=$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail
=1
261 # (maximum tests (-0) not possible).