1#!/bin/sh
2# Exercise ls --block-size and related options.
3
4# Copyright (C) 2011-2023 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 3 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, see <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ ls
21
22TZ=UTC0
23export TZ
24
25mkdir sub
26cd sub
27
28for size in 1024 4096 262144; do
29  echo foo | dd conv=sync bs=$size >file$size || fail=1
30done
31touch -d '2001-01-01 00:00' file* || fail=1
32
33size_etc='s/[^ ]* *[^ ]* *//'
34
35ls -og * | sed "$size_etc" >../out || fail=1
36POSIXLY_CORRECT=1 ls -og * | sed "$size_etc" >>../out || fail=1
37POSIXLY_CORRECT=1 ls -k -og * | sed "$size_etc" >>../out || fail=1
38
39for var in BLOCKSIZE BLOCK_SIZE LS_BLOCK_SIZE; do
40  for blocksize in 1 512 1K 1KiB; do
41    (eval $var=$blocksize && export $var &&
42     echo "x x # $var=$blocksize" &&
43     ls -og * &&
44     ls -og -k * &&
45     ls -og -k --block-size=$blocksize *
46    ) | sed "$size_etc" >>../out || fail=1
47  done
48done
49
50cd ..
51
52cat >exp <<'EOF'
531024 Jan  1  2001 file1024
54262144 Jan  1  2001 file262144
554096 Jan  1  2001 file4096
561024 Jan  1  2001 file1024
57262144 Jan  1  2001 file262144
584096 Jan  1  2001 file4096
591024 Jan  1  2001 file1024
60262144 Jan  1  2001 file262144
614096 Jan  1  2001 file4096
62# BLOCKSIZE=1
631024 Jan  1  2001 file1024
64262144 Jan  1  2001 file262144
654096 Jan  1  2001 file4096
661024 Jan  1  2001 file1024
67262144 Jan  1  2001 file262144
684096 Jan  1  2001 file4096
691024 Jan  1  2001 file1024
70262144 Jan  1  2001 file262144
714096 Jan  1  2001 file4096
72# BLOCKSIZE=512
731024 Jan  1  2001 file1024
74262144 Jan  1  2001 file262144
754096 Jan  1  2001 file4096
761024 Jan  1  2001 file1024
77262144 Jan  1  2001 file262144
784096 Jan  1  2001 file4096
792 Jan  1  2001 file1024
80512 Jan  1  2001 file262144
818 Jan  1  2001 file4096
82# BLOCKSIZE=1K
831024 Jan  1  2001 file1024
84262144 Jan  1  2001 file262144
854096 Jan  1  2001 file4096
861024 Jan  1  2001 file1024
87262144 Jan  1  2001 file262144
884096 Jan  1  2001 file4096
891 Jan  1  2001 file1024
90256 Jan  1  2001 file262144
914 Jan  1  2001 file4096
92# BLOCKSIZE=1KiB
931024 Jan  1  2001 file1024
94262144 Jan  1  2001 file262144
954096 Jan  1  2001 file4096
961024 Jan  1  2001 file1024
97262144 Jan  1  2001 file262144
984096 Jan  1  2001 file4096
991 Jan  1  2001 file1024
100256 Jan  1  2001 file262144
1014 Jan  1  2001 file4096
102# BLOCK_SIZE=1
1031024 Jan  1  2001 file1024
104262144 Jan  1  2001 file262144
1054096 Jan  1  2001 file4096
1061024 Jan  1  2001 file1024
107262144 Jan  1  2001 file262144
1084096 Jan  1  2001 file4096
1091024 Jan  1  2001 file1024
110262144 Jan  1  2001 file262144
1114096 Jan  1  2001 file4096
112# BLOCK_SIZE=512
1132 Jan  1  2001 file1024
114512 Jan  1  2001 file262144
1158 Jan  1  2001 file4096
1162 Jan  1  2001 file1024
117512 Jan  1  2001 file262144
1188 Jan  1  2001 file4096
1192 Jan  1  2001 file1024
120512 Jan  1  2001 file262144
1218 Jan  1  2001 file4096
122# BLOCK_SIZE=1K
1231 Jan  1  2001 file1024
124256 Jan  1  2001 file262144
1254 Jan  1  2001 file4096
1261 Jan  1  2001 file1024
127256 Jan  1  2001 file262144
1284 Jan  1  2001 file4096
1291 Jan  1  2001 file1024
130256 Jan  1  2001 file262144
1314 Jan  1  2001 file4096
132# BLOCK_SIZE=1KiB
1331 Jan  1  2001 file1024
134256 Jan  1  2001 file262144
1354 Jan  1  2001 file4096
1361 Jan  1  2001 file1024
137256 Jan  1  2001 file262144
1384 Jan  1  2001 file4096
1391 Jan  1  2001 file1024
140256 Jan  1  2001 file262144
1414 Jan  1  2001 file4096
142# LS_BLOCK_SIZE=1
1431024 Jan  1  2001 file1024
144262144 Jan  1  2001 file262144
1454096 Jan  1  2001 file4096
1461024 Jan  1  2001 file1024
147262144 Jan  1  2001 file262144
1484096 Jan  1  2001 file4096
1491024 Jan  1  2001 file1024
150262144 Jan  1  2001 file262144
1514096 Jan  1  2001 file4096
152# LS_BLOCK_SIZE=512
1532 Jan  1  2001 file1024
154512 Jan  1  2001 file262144
1558 Jan  1  2001 file4096
1562 Jan  1  2001 file1024
157512 Jan  1  2001 file262144
1588 Jan  1  2001 file4096
1592 Jan  1  2001 file1024
160512 Jan  1  2001 file262144
1618 Jan  1  2001 file4096
162# LS_BLOCK_SIZE=1K
1631 Jan  1  2001 file1024
164256 Jan  1  2001 file262144
1654 Jan  1  2001 file4096
1661 Jan  1  2001 file1024
167256 Jan  1  2001 file262144
1684 Jan  1  2001 file4096
1691 Jan  1  2001 file1024
170256 Jan  1  2001 file262144
1714 Jan  1  2001 file4096
172# LS_BLOCK_SIZE=1KiB
1731 Jan  1  2001 file1024
174256 Jan  1  2001 file262144
1754 Jan  1  2001 file4096
1761 Jan  1  2001 file1024
177256 Jan  1  2001 file262144
1784 Jan  1  2001 file4096
1791 Jan  1  2001 file1024
180256 Jan  1  2001 file262144
1814 Jan  1  2001 file4096
182EOF
183
184compare exp out || fail=1
185
186Exit $fail
187