block-size.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #!/bin/sh
  2. # Exercise ls --block-size and related options.
  3. # Copyright (C) 2011-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ ls
  16. TZ=UTC0
  17. export TZ
  18. mkdir sub
  19. cd sub
  20. for size in 1024 4096 262144; do
  21. echo foo | dd conv=sync bs=$size >file$size || fail=1
  22. done
  23. touch -d '2001-01-01 00:00' file* || fail=1
  24. size_etc='s/[^ ]* *[^ ]* *//'
  25. ls -og * | sed "$size_etc" >../out || fail=1
  26. POSIXLY_CORRECT=1 ls -og * | sed "$size_etc" >>../out || fail=1
  27. POSIXLY_CORRECT=1 ls -k -og * | sed "$size_etc" >>../out || fail=1
  28. for var in BLOCKSIZE BLOCK_SIZE LS_BLOCK_SIZE; do
  29. for blocksize in 1 512 1K 1KiB; do
  30. (eval $var=$blocksize && export $var &&
  31. echo "x x # $var=$blocksize" &&
  32. ls -og * &&
  33. ls -og -k * &&
  34. ls -og -k --block-size=$blocksize *
  35. ) | sed "$size_etc" >>../out || fail=1
  36. done
  37. done
  38. cd ..
  39. cat >exp <<'EOF'
  40. 1024 Jan 1 2001 file1024
  41. 262144 Jan 1 2001 file262144
  42. 4096 Jan 1 2001 file4096
  43. 1024 Jan 1 2001 file1024
  44. 262144 Jan 1 2001 file262144
  45. 4096 Jan 1 2001 file4096
  46. 1024 Jan 1 2001 file1024
  47. 262144 Jan 1 2001 file262144
  48. 4096 Jan 1 2001 file4096
  49. # BLOCKSIZE=1
  50. 1024 Jan 1 2001 file1024
  51. 262144 Jan 1 2001 file262144
  52. 4096 Jan 1 2001 file4096
  53. 1024 Jan 1 2001 file1024
  54. 262144 Jan 1 2001 file262144
  55. 4096 Jan 1 2001 file4096
  56. 1024 Jan 1 2001 file1024
  57. 262144 Jan 1 2001 file262144
  58. 4096 Jan 1 2001 file4096
  59. # BLOCKSIZE=512
  60. 1024 Jan 1 2001 file1024
  61. 262144 Jan 1 2001 file262144
  62. 4096 Jan 1 2001 file4096
  63. 1024 Jan 1 2001 file1024
  64. 262144 Jan 1 2001 file262144
  65. 4096 Jan 1 2001 file4096
  66. 2 Jan 1 2001 file1024
  67. 512 Jan 1 2001 file262144
  68. 8 Jan 1 2001 file4096
  69. # BLOCKSIZE=1K
  70. 1024 Jan 1 2001 file1024
  71. 262144 Jan 1 2001 file262144
  72. 4096 Jan 1 2001 file4096
  73. 1024 Jan 1 2001 file1024
  74. 262144 Jan 1 2001 file262144
  75. 4096 Jan 1 2001 file4096
  76. 1 Jan 1 2001 file1024
  77. 256 Jan 1 2001 file262144
  78. 4 Jan 1 2001 file4096
  79. # BLOCKSIZE=1KiB
  80. 1024 Jan 1 2001 file1024
  81. 262144 Jan 1 2001 file262144
  82. 4096 Jan 1 2001 file4096
  83. 1024 Jan 1 2001 file1024
  84. 262144 Jan 1 2001 file262144
  85. 4096 Jan 1 2001 file4096
  86. 1 Jan 1 2001 file1024
  87. 256 Jan 1 2001 file262144
  88. 4 Jan 1 2001 file4096
  89. # BLOCK_SIZE=1
  90. 1024 Jan 1 2001 file1024
  91. 262144 Jan 1 2001 file262144
  92. 4096 Jan 1 2001 file4096
  93. 1024 Jan 1 2001 file1024
  94. 262144 Jan 1 2001 file262144
  95. 4096 Jan 1 2001 file4096
  96. 1024 Jan 1 2001 file1024
  97. 262144 Jan 1 2001 file262144
  98. 4096 Jan 1 2001 file4096
  99. # BLOCK_SIZE=512
  100. 2 Jan 1 2001 file1024
  101. 512 Jan 1 2001 file262144
  102. 8 Jan 1 2001 file4096
  103. 2 Jan 1 2001 file1024
  104. 512 Jan 1 2001 file262144
  105. 8 Jan 1 2001 file4096
  106. 2 Jan 1 2001 file1024
  107. 512 Jan 1 2001 file262144
  108. 8 Jan 1 2001 file4096
  109. # BLOCK_SIZE=1K
  110. 1 Jan 1 2001 file1024
  111. 256 Jan 1 2001 file262144
  112. 4 Jan 1 2001 file4096
  113. 1 Jan 1 2001 file1024
  114. 256 Jan 1 2001 file262144
  115. 4 Jan 1 2001 file4096
  116. 1 Jan 1 2001 file1024
  117. 256 Jan 1 2001 file262144
  118. 4 Jan 1 2001 file4096
  119. # BLOCK_SIZE=1KiB
  120. 1 Jan 1 2001 file1024
  121. 256 Jan 1 2001 file262144
  122. 4 Jan 1 2001 file4096
  123. 1 Jan 1 2001 file1024
  124. 256 Jan 1 2001 file262144
  125. 4 Jan 1 2001 file4096
  126. 1 Jan 1 2001 file1024
  127. 256 Jan 1 2001 file262144
  128. 4 Jan 1 2001 file4096
  129. # LS_BLOCK_SIZE=1
  130. 1024 Jan 1 2001 file1024
  131. 262144 Jan 1 2001 file262144
  132. 4096 Jan 1 2001 file4096
  133. 1024 Jan 1 2001 file1024
  134. 262144 Jan 1 2001 file262144
  135. 4096 Jan 1 2001 file4096
  136. 1024 Jan 1 2001 file1024
  137. 262144 Jan 1 2001 file262144
  138. 4096 Jan 1 2001 file4096
  139. # LS_BLOCK_SIZE=512
  140. 2 Jan 1 2001 file1024
  141. 512 Jan 1 2001 file262144
  142. 8 Jan 1 2001 file4096
  143. 2 Jan 1 2001 file1024
  144. 512 Jan 1 2001 file262144
  145. 8 Jan 1 2001 file4096
  146. 2 Jan 1 2001 file1024
  147. 512 Jan 1 2001 file262144
  148. 8 Jan 1 2001 file4096
  149. # LS_BLOCK_SIZE=1K
  150. 1 Jan 1 2001 file1024
  151. 256 Jan 1 2001 file262144
  152. 4 Jan 1 2001 file4096
  153. 1 Jan 1 2001 file1024
  154. 256 Jan 1 2001 file262144
  155. 4 Jan 1 2001 file4096
  156. 1 Jan 1 2001 file1024
  157. 256 Jan 1 2001 file262144
  158. 4 Jan 1 2001 file4096
  159. # LS_BLOCK_SIZE=1KiB
  160. 1 Jan 1 2001 file1024
  161. 256 Jan 1 2001 file262144
  162. 4 Jan 1 2001 file4096
  163. 1 Jan 1 2001 file1024
  164. 256 Jan 1 2001 file262144
  165. 4 Jan 1 2001 file4096
  166. 1 Jan 1 2001 file1024
  167. 256 Jan 1 2001 file262144
  168. 4 Jan 1 2001 file4096
  169. EOF
  170. compare exp out || fail=1
  171. Exit $fail