3 # Copyright (C) 2018-2019 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
37 requires qemu-io
--version
39 out
="test-sh-errors.out"
40 expected
="test-sh-errors.expected"
41 files
="$out $expected"
43 cleanup_fn
rm -f $files
45 # do_test 'egrep pattern' ['write_zero']
46 # (Use of an egrep pattern makes it easy to whitelist other localized error
47 # outputs that may be system-dependent)
51 if [ "$2" = write_zero
]; then
52 cmd
='qemu-io -f raw -c "w -z 0 512" $nbd'
54 cmd
='qemu-io -r -f raw -c "r 0 1" $nbd'
56 nbdkit
-v -U - sh
- --run "$cmd"' &&
57 echo qemu-io unexpectedly passed >> '$out'; :' >> $out
58 if grep "qemu-io unexpectedly passed" $out ||
59 ! egrep "$1" $out; then
60 echo "$0: output did not match expected data"
68 # All caps, no trailing whitespace, ENOMEM
69 do_test
'Cannot allocate memory' <<'EOF'
72 pread) printf ENOMEM >&2; exit 1 ;;
77 # Lower case, trailing newline, EPERM
78 do_test
'Operation not permitted' <<'EOF'
81 pread) echo eperm >&2; exit 1 ;;
86 # Trailing single-line message, ENOSPC
87 do_test
'No space left on device' <<'EOF'
90 pread) echo ENOSPC custom message does not reach client >&2; exit 1 ;;
95 # Multi-line message, ESHUTDOWN
96 do_test
'Cannot send after transport endpoint shutdown' <<'EOF'
99 pread) printf 'ESHUTDOWN\nline one\nline two\n' >&2; exit 1 ;;
104 # Any errno that can't be sent over NBD is flattened to EIO
105 do_test
'Input/output error' <<'EOF'
108 pread) echo EPIPE >&2; exit 1 ;;
113 # EINVALID is not a real errno name, and should not be confused with EINVAL
114 do_test
'Input/output error' <<'EOF'
117 pread) echo EINVALID >&2; exit 1 ;;
122 # ENOTSUP is special to write zero; it triggers a fallback to pwrite
123 # Also test that anything on stderr is ignored when the script succeeds
124 do_test
'No space left on device' write_zero
<<'EOF'
126 get_size) echo 'EINVAL ignored' >&2; echo 1M ;;
127 can_write | can_zero) echo ENOMEM >&2; exit 0 ;;
128 pwrite) echo ENOSPC >&2; exit 1 ;;
129 zero) echo ENOTSUP >&2; exit 1 ;;