trace: count number of enabled events
[qemu/ar7.git] / tests / qemu-iotests / 083
blobaa99278fd8540ecd20584645bd04d5301707e0b9
1 #!/bin/bash
3 # Test NBD client unexpected disconnect
5 # Copyright Red Hat, Inc. 2014
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.
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.
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/>.
21 # creator
22 owner=stefanha@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1 # failure is the default!
31 # get standard environment, filters and checks
32 . ./common.rc
33 . ./common.filter
35 _supported_fmt generic
36 _supported_proto nbd
37 _supported_os Linux
39 # Pick a TCP port based on our pid. This way multiple instances of this test
40 # can run in parallel without conflicting.
41 choose_tcp_port() {
42 echo $((($$ % 31744) + 1024)) # 1024 <= port < 32768
45 wait_for_tcp_port() {
46 while ! (netstat --tcp --listening --numeric | \
47 grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") 2>&1 >/dev/null; do
48 sleep 0.1
49 done
52 check_disconnect() {
53 event=$1
54 when=$2
55 negotiation=$3
56 echo "=== Check disconnect $when $event ==="
57 echo
59 port=$(choose_tcp_port)
61 cat > "$TEST_DIR/nbd-fault-injector.conf" <<EOF
62 [inject-error]
63 event=$event
64 when=$when
65 EOF
67 if [ "$negotiation" = "--classic-negotiation" ]; then
68 extra_args=--classic-negotiation
69 nbd_url="nbd:127.0.0.1:$port"
70 else
71 nbd_url="nbd:127.0.0.1:$port:exportname=foo"
74 $PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" "$TEST_DIR/nbd-fault-injector.conf" 2>&1 >/dev/null &
75 wait_for_tcp_port "127\\.0\\.0\\.1:$port"
76 $QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd
78 echo
81 for event in neg1 "export" neg2 request reply data; do
82 for when in before after; do
83 check_disconnect "$event" "$when"
84 done
86 # Also inject short replies from the NBD server
87 case "$event" in
88 neg1)
89 for when in 8 16; do
90 check_disconnect "$event" "$when"
91 done
93 "export")
94 for when in 4 12 16; do
95 check_disconnect "$event" "$when"
96 done
98 neg2)
99 for when in 8 10; do
100 check_disconnect "$event" "$when"
101 done
103 reply)
104 for when in 4 8; do
105 check_disconnect "$event" "$when"
106 done
108 esac
109 done
111 # Also check classic negotiation without export information
112 for when in before 8 16 24 28 after; do
113 check_disconnect "neg-classic" "$when" --classic-negotiation
114 done
116 # success, all done
117 echo "*** done"
118 rm -f $seq.full
119 status=0