tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / dd / skip-seek-past-dev
1 #!/bin/sh
2 # test diagnostics are printed immediately when seeking beyond device.
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
26 # need write access to device
27 # (even though we don't actually write anything)
28 require_root_
29
30 get_device_size() {
31   BLOCKDEV=blockdev
32   $BLOCKDEV -V >/dev/null 2>&1 || BLOCKDEV=/sbin/blockdev
33   $BLOCKDEV --getsize64 "$1"
34 }
35
36
37 # Get path to device the current dir is on.
38 # Note df can only get fs size, not device size.
39 device=$(df -P --local . | tail -n1 | cut -d' ' -f1) ||
40   skip_test_ 'this test runs only on local file systems'
41
42 dev_size=$(get_device_size "$device") ||
43   skip_test_ "failed to determine size of $device"
44
45 # Don't use shell arithimetic as older version of dash use longs
46 DEV_OFLOW=$(expr $dev_size + 1)
47
48 timeout 1 dd bs=1 skip=$DEV_OFLOW count=0 status=noxfer < "$device" 2> err
49 test "$?" = "1" || fail=1
50 echo "dd: \`standard input': cannot skip: Invalid argument
51 0+0 records in
52 0+0 records out" > err_ok || framework_failure
53 compare err_ok err || fail=1
54
55 timeout 1 dd bs=1 seek=$DEV_OFLOW count=0 status=noxfer > "$device" 2> err
56 test "$?" = "1" || fail=1
57 echo "dd: \`standard output': cannot seek: Invalid argument
58 0+0 records in
59 0+0 records out" > err_ok || framework_failure
60 compare err_ok err || fail=1
61
62 Exit $fail