3 # Copyright (C) 2018-2020 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 requires qemu-io
--version
40 out
="test-sh-errors.out"
41 expected
="test-sh-errors.expected"
42 files
="$out $expected"
44 cleanup_fn
rm -f $files
46 # do_test 'egrep pattern' ['write_zero']
47 # (Use of an egrep pattern makes it easy to whitelist other localized error
48 # outputs that may be system-dependent)
52 if [ "$2" = write_zero
]; then
53 cmd
='qemu-io -f raw -c "w -z 0 512" $nbd'
55 cmd
='qemu-io -r -f raw -c "r 0 1" $nbd'
57 nbdkit
-v -U - sh
- --run "$cmd"' &&
58 echo qemu-io unexpectedly passed >> '$out'; :' >> $out
59 if grep "qemu-io unexpectedly passed" $out ||
60 ! egrep "$1" $out; then
61 echo "$0: output did not match expected data"
69 # All caps, no trailing whitespace, ENOMEM
70 do_test
'(Cannot allocate|Out of) memory' <<'EOF'
73 pread) printf ENOMEM >&2; exit 1 ;;
78 # Lower case, trailing newline, EPERM
79 do_test
'Operation not permitted' <<'EOF'
82 pread) echo eperm >&2; exit 1 ;;
87 # Trailing single-line message, ENOSPC
88 do_test
'No space left on device' <<'EOF'
91 pread) echo ENOSPC custom message does not reach client >&2; exit 1 ;;
96 # Multi-line message, ESHUTDOWN
97 do_test
"(Cannot|Can't) send after (transport endpoint|socket) shutdown" <<'EOF'
100 pread) printf 'ESHUTDOWN\nline one\nline two\n' >&2; exit 1 ;;
105 # Any errno that can't be sent over NBD is flattened to EIO
106 do_test
'(Input/output|I/O) error' <<'EOF'
109 pread) echo EPIPE >&2; exit 1 ;;
114 # EINVALID is not a real errno name, and should not be confused with EINVAL
115 do_test
'(Input/output| I/O) error' <<'EOF'
118 pread) echo EINVALID >&2; exit 1 ;;
123 # ENOTSUP is special to write zero; it triggers a fallback to pwrite
124 # Also test that anything on stderr is ignored when the script succeeds
125 do_test
'No space left on device' write_zero
<<'EOF'
127 get_size) echo 'EINVAL ignored' >&2; echo 1M ;;
128 can_write | can_zero) echo ENOMEM >&2; exit 0 ;;
129 pwrite) echo ENOSPC >&2; exit 1 ;;
130 zero) echo ENOTSUP >&2; exit 1 ;;