tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / dd / skip-seek-past-file
1 #!/bin/sh
2 # test diagnostics are printed when seeking too far in seekable files.
3
4 # Copyright (C) 2008, 2009 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 <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   dd --version
22 fi
23
24 . $srcdir/test-lib.sh
25 require_sparse_support_ # for `truncate --size=$OFF_T_MAX`
26 eval $(getlimits) # for OFF_T limits
27
28
29 printf "1234" > file || framework_failure
30
31 echo "\
32 dd: \`standard input': cannot skip to specified offset
33 0+0 records in
34 0+0 records out" > skip_err || framework_failure
35
36 # skipping beyond number of blocks in file should issue a warning
37 dd bs=1 skip=5 count=0 status=noxfer < file 2> err || fail=1
38 compare skip_err err || fail=1
39
40 # skipping beyond number of bytes in file should issue a warning
41 dd bs=3 skip=2 count=0 status=noxfer < file 2> err || fail=1
42 compare skip_err err || fail=1
43
44 # skipping beyond number of blocks in pipe should issue a warning
45 cat file | dd bs=1 skip=5 count=0 status=noxfer 2> err || fail=1
46 compare skip_err err || fail=1
47
48 # skipping beyond number of bytes in pipe should issue a warning
49 cat file | dd bs=3 skip=2 count=0 status=noxfer 2> err || fail=1
50 compare skip_err err || fail=1
51
52 # Check seeking beyond file already offset into
53 # skipping beyond number of blocks in file should issue a warning
54 (dd bs=1 skip=1 count=0 2>/dev/null &&
55  dd bs=1 skip=4 status=noxfer 2> err) < file || fail=1
56 compare skip_err err || fail=1
57
58 # Check seeking beyond file already offset into
59 # skipping beyond number of bytes in file should issue a warning
60 (dd bs=1 skip=1 count=0 2>/dev/null &&
61  dd bs=2 skip=2 status=noxfer 2> err) < file || fail=1
62 compare skip_err err || fail=1
63
64 # seeking beyond end of file is OK
65 dd bs=1 seek=5 count=0 status=noxfer > file 2> err || fail=1
66 echo "0+0 records in
67 0+0 records out" > err_ok || framework_failure
68 compare err_ok err || fail=1
69
70 # skipping > OFF_T_MAX should fail immediately
71 dd bs=1 skip=$OFF_T_OFLOW count=0 status=noxfer < file 2> err && fail=1
72 # error message should be "... cannot skip: strerror(EOVERFLOW)"
73 grep "cannot skip:" err >/dev/null || fail=1
74
75 # skipping > max file size should fail immediately
76 if ! truncate --size=$OFF_T_MAX in 2>/dev/null; then
77   # truncate is to ensure file system doesn't actually support OFF_T_MAX files
78   dd bs=1 skip=$OFF_T_MAX count=0 status=noxfer < file 2> err \
79     && lseek_ok=yes \
80     || lseek_ok=no
81
82   if test $lseek_ok = yes; then
83     # On Solaris 10 at least, lseek(>max file size) succeeds,
84     # so just check for the skip warning.
85     compare skip_err err || fail=1
86   else
87     # On Linux kernels at least, lseek(>max file size) fails.
88     # error message should be "... cannot skip: strerror(EINVAL)"
89     grep "cannot skip:" err >/dev/null || fail=1
90   fi
91 fi
92
93 Exit $fail