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