fw_cfg: Refactor extra pci roots addition
[qemu/ar7.git] / tests / qemu-iotests / 140
blob309b177e77f5b0ecae727620d66d699016a5adec
1 #!/usr/bin/env bash
3 # Test case for ejecting a BlockBackend with an NBD server attached to it
5 # Verify that the NBD server stops offering the drive when ejecting a
6 # BlockDriverState tree from a BlockBackend (that is, a medium from a
7 # drive) exposed via an NBD server.
9 # Copyright (C) 2016 Red Hat, Inc.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # creator
26 owner=mreitz@redhat.com
28 seq="$(basename $0)"
29 echo "QA output created by $seq"
31 status=1 # failure is the default!
33 _cleanup()
35 _cleanup_qemu
36 _cleanup_test_img
37 rm -f "$SOCK_DIR/nbd"
39 trap "_cleanup; exit \$status" 0 1 2 3 15
41 # get standard environment, filters and checks
42 . ./common.rc
43 . ./common.filter
44 . ./common.qemu
46 _supported_fmt generic
47 _supported_proto file
48 _supported_os Linux
50 _make_test_img 64k
52 $QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
54 if test "$IMGOPTSSYNTAX" = "true"
55 then
56 SYSEMU_DRIVE_ARG=if=none,media=cdrom,id=drv,"$TEST_IMG"
57 else
58 SYSEMU_DRIVE_ARG=if=none,media=cdrom,id=drv,file="$TEST_IMG",driver=$IMGFMT
61 keep_stderr=y \
62 _launch_qemu -drive $SYSEMU_DRIVE_ARG \
63 2> >(_filter_nbd)
65 _send_qemu_cmd $QEMU_HANDLE \
66 "{ 'execute': 'qmp_capabilities' }" \
67 'return'
69 _send_qemu_cmd $QEMU_HANDLE \
70 "{ 'execute': 'nbd-server-start',
71 'arguments': { 'addr': { 'type': 'unix',
72 'data': { 'path': '$SOCK_DIR/nbd' }}}}" \
73 'return'
75 _send_qemu_cmd $QEMU_HANDLE \
76 "{ 'execute': 'nbd-server-add',
77 'arguments': { 'device': 'drv' }}" \
78 'return'
80 $QEMU_IO_PROG -f raw -r -c 'read -P 42 0 64k' \
81 "nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \
82 | _filter_qemu_io | _filter_nbd
84 # The order of 'return' and the BLOCK_EXPORT_DELETED event is undefined. Just
85 # wait until we've twice seen one of them. Filter the 'return' line out so that
86 # the output is defined.
87 _send_qemu_cmd $QEMU_HANDLE \
88 "{ 'execute': 'eject',
89 'arguments': { 'device': 'drv' }}" \
90 'return\|BLOCK_EXPORT_DELETED' |
91 grep -v 'return'
93 _send_qemu_cmd $QEMU_HANDLE '' 'return\|BLOCK_EXPORT_DELETED' |
94 grep -v 'return'
96 $QEMU_IO_PROG -f raw -r -c close \
97 "nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \
98 | _filter_qemu_io | _filter_nbd
100 _send_qemu_cmd $QEMU_HANDLE \
101 "{ 'execute': 'quit' }" \
102 'return'
104 wait=1 _cleanup_qemu
106 # success, all done
107 echo '*** done'
108 rm -f $seq.full
109 status=0