build: Link user-only with crypto random number objects
[qemu/ar7.git] / tests / qemu-iotests / 162
blob4e5ed74fd5874f31d9d4af2f9da6331cd355aac3
1 #!/usr/bin/env bash
3 # Test case for specifying runtime options of the wrong type to some
4 # block drivers
6 # Copyright (C) 2016 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=mreitz@redhat.com
25 seq="$(basename $0)"
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 rm -f "${TEST_DIR}/qemu-nbd.pid"
33 rm -f 42
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 _supported_fmt generic
43 test_ssh=$($QEMU_IMG --help | grep '^Supported formats:.* ssh\( \|$\)')
44 [ "$test_ssh" = "" ] && _notrun "ssh support required"
46 echo
47 echo '=== NBD ==='
48 # NBD expects all of its arguments to be strings
50 # So this should not crash
51 $QEMU_IMG info 'json:{"driver": "nbd", "host": 42}'
53 # And this should not treat @port as if it had not been specified
54 # (We need to set up a server here, because the error message for "Connection
55 # refused" does not contain the destination port)
57 # Launching qemu-nbd is done in a loop: We try to set up an NBD server on some
58 # random port and continue until success, i.e. until we have found a port that
59 # is not in use yet.
60 while true; do
61 port=$((RANDOM + 32768))
62 if $QEMU_NBD -p $port -f raw --fork null-co:// 2> /dev/null; then
63 break
65 done
67 $QEMU_IMG info "json:{'driver': 'nbd', 'host': 'localhost', 'port': $port}" \
68 | grep '^image' | sed -e "s/$port/PORT/"
70 # This is a test for NBD's bdrv_refresh_filename() implementation: It expects
71 # either host or path to be set, but it must not assume that they are set to
72 # strings in the options QDict
73 $QEMU_NBD -k "$PWD/42" -f raw --fork null-co://
74 $QEMU_IMG info 'json:{"driver": "nbd", "path": 42}' | grep '^image'
75 rm -f 42
78 echo
79 echo '=== SSH ==='
80 # SSH expects all of its arguments to be strings, except for @port, which is
81 # expected to be an integer
83 # So "0" should be converted to an integer here (instead of crashing)
84 $QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": "0", "path": "/foo"}'
85 # The same, basically (all values for --image-opts are seen as strings in qemu)
86 $QEMU_IMG info --image-opts \
87 driver=ssh,host=localhost,port=0,path=/foo
89 # This, however, should fail because of the wrong type
90 $QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": 0.42, "path": "/foo"}'
91 # Not really the same: Here, "0.42" will be passed instead of 0.42, but still,
92 # qemu should not try to convert "0.42" to an integer
93 $QEMU_IMG info --image-opts \
94 driver=ssh,host=localhost,port=0.42,path=/foo
97 echo
98 echo '=== blkdebug ==='
99 # blkdebug expects all of its arguments to be strings, but its
100 # bdrv_refresh_filename() implementation should not assume that they have been
101 # passed as strings in the original options QDict.
102 # So this should emit blkdebug:42:null-co:// as the filename:
103 touch 42
104 $QEMU_IMG info 'json:{"driver": "blkdebug", "config": 42,
105 "image.driver": "null-co"}' \
106 | grep '^image'
107 rm -f 42
110 # success, all done
111 echo
112 echo '*** done'
113 rm -f $seq.full
114 status=0