2 # Ensure "df --total" computes accurate totals
4 # Copyright (C) 2008-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
23 # Protect against inaccessible remote mounts etc.
24 timeout
10 df || skip_
"df fails"
26 cat <<\EOF
> check-df || framework_failure_
27 my
($total, $used, $avail) = (0, 0, 0);
31 and next
; # skip first (header) line
32 # Recognize df output lines like these:
33 # /dev/sdc1 0 0 0 - /c
34 # tmpfs 1536000 12965 1523035 1% /tmp
35 # total 5285932 787409 4498523 15% -
36 /^
(.
*?
) +(-?\d
+|
-) +(-?\d
+|
-) +(-?\d
+|
-) +(?
:-|
[0-9]+%) (.
*)$
/
37 or die
"$0: invalid input line\n: $_";
38 if ($1 eq
'total' && $5 eq
'-')
40 $total == $2 or die
"$total != $2";
41 $used == $3 or die
"$used != $3";
42 $avail == $4 or die
"$avail != $4";
45 and die
"$0: extra line(s) after totals\n";
48 $total += $2 unless
$2 eq
'-';
49 $used += $3 unless
$3 eq
'-';
50 $avail += $4 unless
$4 eq
'-';
52 die
"$0: missing line of totals\n";
55 # Use --block-size=512 to keep df from printing rounded-to-kilobyte
56 # numbers which wouldn't necessarily add up to the displayed total.
57 df
--total -P --block-size=512 > space || framework_failure_
58 cat space
# this helps when debugging any test failure
59 df
--total -i -P > inode || framework_failure_
62 $PERL check-df space || fail
=1
63 $PERL check-df inode || fail
=1
65 test "$fail" = 1 && dump_mount_list_