~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/dd/skip-seek-past-file.sh

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

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