Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / dd / skip-seek
1 #!/bin/sh
2 # -*- perl -*-
3 # Test dd's skip and seek options.
4
5 # Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation,
6 # Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 : ${PERL=perl}
24 : ${srcdir=.}
25
26 $PERL -e 1 > /dev/null 2>&1 || {
27   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
28     "so can't run this test"
29   exit 77
30 }
31
32 SCRIPT_NAME=$0
33 export SCRIPT_NAME
34
35 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
36 require 5.003;
37 use strict;
38
39 (my $program_name = $0) =~ s|.*/||;
40
41 # Turn off localisation of executable's ouput.
42 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
43 my $out = 'out';
44 my $script_name = $ENV{SCRIPT_NAME};
45
46 my @Tests =
47     (
48      [
49       'sk-seek1',
50       qw (bs=1 skip=1 seek=2 conv=notrunc count=3 status=noxfer of=@AUX@ < ),
51       {IN=> '0123456789abcdef'},
52       {AUX=> 'zyxwvutsrqponmlkji'},
53       {OUT=> ''},
54       {ERR=> "3+0 records in\n3+0 records out\n"},
55       {CMP=> ['zy123utsrqponmlkji', {'@AUX@'=> undef}]},
56      ],
57      [
58       'sk-seek2',
59       qw (bs=5 skip=1 seek=1 conv=notrunc count=1 status=noxfer of=@AUX@ < ),
60       {IN=> '0123456789abcdef'},
61       {AUX=> 'zyxwvutsrqponmlkji'},
62       {OUT=> ''},
63       {ERR=> "1+0 records in\n1+0 records out\n"},
64       {CMP=> ['zyxwv56789ponmlkji', {'@AUX@'=> undef}]},
65      ],
66      [
67       'sk-seek3',
68       qw (bs=5 skip=1 seek=1 count=1 status=noxfer of=@AUX@ < ),
69       {IN=> '0123456789abcdef'},
70       {AUX=> 'zyxwvutsrqponmlkji'},
71       {OUT=> ''},
72       {ERR=> "1+0 records in\n1+0 records out\n"},
73       {CMP=> ['zyxwv56789', {'@AUX@'=> undef}]},
74      ],
75      [
76       # Before fileutils-4.0.45, the last 10 bytes of output
77       # were these "\0\0\0\0\0\0\0\0  ".
78       'block-sync-1', qw(ibs=10 cbs=10 status=noxfer), 'conv=block,sync', '<',
79       {IN=> "01234567\nabcdefghijkl\n"},
80       {OUT=> "01234567  abcdefghij          "},
81       {ERR=> "2+1 records in\n0+1 records out\n1 truncated record\n"},
82      ],
83      [
84       # Before coreutils-5.93, this would output just "c\n".
85       'sk-seek4', qw(bs=1 skip=1 status=noxfer),
86       {IN_PIPE=> "abc\n"},
87       {OUT=> "bc\n"},
88       {ERR=> "3+0 records in\n3+0 records out\n"},
89      ],
90     );
91
92 my $save_temps = $ENV{DEBUG};
93 my $verbose = $ENV{VERBOSE};
94
95 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
96 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
97 exit $fail;
98 EOF