skip-seek.pl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/perl
  2. # Test dd's skip and seek options.
  3. # Copyright (C) 2000-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. use strict;
  15. (my $program_name = $0) =~ s|.*/||;
  16. # Turn off localization of executable's output.
  17. @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
  18. my $out = 'out';
  19. my @Tests =
  20. (
  21. [
  22. 'sk-seek1',
  23. qw (bs=1 skip=1 seek=2 conv=notrunc count=3 status=noxfer of=@AUX@ < ),
  24. {IN=> '0123456789abcdef'},
  25. {AUX=> 'zyxwvutsrqponmlkji'},
  26. {OUT=> ''},
  27. {ERR=> "3+0 records in\n3+0 records out\n"},
  28. {CMP=> ['zy123utsrqponmlkji', {'@AUX@'=> undef}]},
  29. ],
  30. [
  31. 'sk-seek2',
  32. qw (bs=5 skip=1 seek=1 conv=notrunc count=1 status=noxfer of=@AUX@ < ),
  33. {IN=> '0123456789abcdef'},
  34. {AUX=> 'zyxwvutsrqponmlkji'},
  35. {OUT=> ''},
  36. {ERR=> "1+0 records in\n1+0 records out\n"},
  37. {CMP=> ['zyxwv56789ponmlkji', {'@AUX@'=> undef}]},
  38. ],
  39. [
  40. 'sk-seek3',
  41. qw (bs=5 skip=1 seek=1 count=1 status=noxfer of=@AUX@ < ),
  42. {IN=> '0123456789abcdef'},
  43. {AUX=> 'zyxwvutsrqponmlkji'},
  44. {OUT=> ''},
  45. {ERR=> "1+0 records in\n1+0 records out\n"},
  46. {CMP=> ['zyxwv56789', {'@AUX@'=> undef}]},
  47. ],
  48. [
  49. # Before fileutils-4.0.45, the last 10 bytes of output
  50. # were these "\0\0\0\0\0\0\0\0 ".
  51. 'block-sync-1', qw(ibs=10 cbs=10 status=noxfer), 'conv=block,sync', '<',
  52. {IN=> "01234567\nabcdefghijkl\n"},
  53. {OUT=> "01234567 abcdefghij "},
  54. {ERR=> "2+1 records in\n0+1 records out\n1 truncated record\n"},
  55. ],
  56. [
  57. # Before coreutils-5.93, this would output just "c\n".
  58. 'sk-seek4', qw(bs=1 skip=1 status=noxfer),
  59. {IN_PIPE=> "abc\n"},
  60. {OUT=> "bc\n"},
  61. {ERR=> "3+0 records in\n3+0 records out\n"},
  62. ],
  63. );
  64. my $save_temps = $ENV{DEBUG};
  65. my $verbose = $ENV{VERBOSE};
  66. my $prog = 'dd';
  67. my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
  68. exit $fail;