cirrus: fix off-by-one in cirrus_bitblt_rop_bkwd_transp_*_16
[qemu.git] / tests / qemu-iotests / 083
1 #!/bin/bash
2 #
3 # Test NBD client unexpected disconnect
4 #
5 # Copyright Red Hat, Inc. 2014
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 # creator
22 owner=stefanha@redhat.com
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 status=1        # failure is the default!
29
30 # get standard environment, filters and checks
31 . ./common.rc
32 . ./common.filter
33
34 _supported_fmt generic
35 _supported_proto nbd
36 _supported_os Linux
37
38 # Pick a TCP port based on our pid.  This way multiple instances of this test
39 # can run in parallel without conflicting.
40 choose_tcp_port() {
41         echo $((($$ % 31744) + 1024)) # 1024 <= port < 32768
42 }
43
44 wait_for_tcp_port() {
45         while ! (netstat --tcp --listening --numeric | \
46                  grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") >/dev/null 2>&1; do
47                 sleep 0.1
48         done
49 }
50
51 check_disconnect() {
52         event=$1
53         when=$2
54         negotiation=$3
55         echo "=== Check disconnect $when $event ==="
56         echo
57
58         port=$(choose_tcp_port)
59
60         cat > "$TEST_DIR/nbd-fault-injector.conf" <<EOF
61 [inject-error]
62 event=$event
63 when=$when
64 EOF
65
66         if [ "$negotiation" = "--classic-negotiation" ]; then
67                 extra_args=--classic-negotiation
68                 nbd_url="nbd:127.0.0.1:$port"
69         else
70                 nbd_url="nbd:127.0.0.1:$port:exportname=foo"
71         fi
72
73         $PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" "$TEST_DIR/nbd-fault-injector.conf" >/dev/null 2>&1 &
74         wait_for_tcp_port "127\\.0\\.0\\.1:$port"
75         $QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd
76
77         echo
78 }
79
80 for event in neg1 "export" neg2 request reply data; do
81         for when in before after; do
82                 check_disconnect "$event" "$when"
83         done
84
85         # Also inject short replies from the NBD server
86         case "$event" in
87         neg1)
88                 for when in 8 16; do
89                         check_disconnect "$event" "$when"
90                 done
91                 ;;
92         "export")
93                 for when in 4 12 16; do
94                         check_disconnect "$event" "$when"
95                 done
96                 ;;
97         neg2)
98                 for when in 8 10; do
99                         check_disconnect "$event" "$when"
100                 done
101                 ;;
102         reply)
103                 for when in 4 8; do
104                         check_disconnect "$event" "$when"
105                 done
106                 ;;
107         esac
108 done
109
110 # Also check classic negotiation without export information
111 for when in before 8 16 24 28 after; do
112         check_disconnect "neg-classic" "$when" --classic-negotiation
113 done
114
115 # success, all done
116 echo "*** done"
117 rm -f $seq.full
118 status=0