reblock.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. # test dd reblocking vs. bs=
  3. # Copyright (C) 2008-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_ dd
  16. # 2 short reads -> 1 full write + 1 partial write
  17. cat <<\EOF > exp-reblock || framework_failure_
  18. 0+2 records in
  19. 1+1 records out
  20. 4 bytes copied
  21. EOF
  22. # 2 short reads -> 2 partial writes
  23. cat <<\EOF > exp-no-reblock || framework_failure_
  24. 0+2 records in
  25. 0+2 records out
  26. 4 bytes copied
  27. EOF
  28. # Use a fifo rather than a pipe in the tests below
  29. # so that the producer (printf subshell) will wait
  30. # until the consumer (dd) opens the fifo therefore
  31. # increasing the chance that dd will read the data
  32. # from each printf separately.
  33. mkfifo_or_skip_ dd.fifo
  34. dd_reblock_1()
  35. {
  36. local delay="$1"
  37. # ensure that dd reblocks when bs= is not specified
  38. dd ibs=3 obs=3 if=dd.fifo > out 2> err&
  39. (printf 'ab'; sleep $delay; printf 'cd') > dd.fifo
  40. wait #for dd to complete
  41. sed 's/,.*//' err > k && mv k err
  42. compare exp-reblock err
  43. }
  44. retry_delay_ dd_reblock_1 .1 6 || fail=1
  45. dd_reblock_2()
  46. {
  47. local delay="$1"
  48. # Demonstrate that bs=N supersedes even following ibs= and obs= settings.
  49. dd bs=3 ibs=1 obs=1 if=dd.fifo > out 2> err&
  50. (printf 'ab'; sleep $delay; printf 'cd') > dd.fifo
  51. wait #for dd to complete
  52. sed 's/,.*//' err > k && mv k err
  53. compare exp-no-reblock err
  54. }
  55. retry_delay_ dd_reblock_2 .1 6 || fail=1
  56. Exit $fail