xref: /openbmc/qemu/tests/qemu-iotests/162 (revision c00506aa)
1#!/usr/bin/env bash
2#
3# Test case for specifying runtime options of the wrong type to some
4# block drivers
5#
6# Copyright (C) 2016 Red Hat, Inc.
7#
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.
12#
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.
17#
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/>.
20#
21
22# creator
23owner=mreitz@redhat.com
24
25seq="$(basename $0)"
26echo "QA output created by $seq"
27
28status=1	# failure is the default!
29
30_cleanup()
31{
32    rm -f "${TEST_DIR}/qemu-nbd.pid"
33    rm -f 42
34}
35trap "_cleanup; exit \$status" 0 1 2 3 15
36
37# get standard environment, filters and checks
38. ./common.rc
39. ./common.filter
40
41_supported_fmt generic
42_require_drivers ssh
43
44echo
45echo '=== NBD ==='
46# NBD expects all of its arguments to be strings
47
48# So this should not crash
49$QEMU_IMG info 'json:{"driver": "nbd", "host": -1}'
50
51# And this should not treat @port as if it had not been specified
52# (We need to set up a server here, because the error message for "Connection
53#  refused" does not contain the destination port)
54
55# Launching qemu-nbd is done in a loop: We try to set up an NBD server on some
56# random port and continue until success, i.e. until we have found a port that
57# is not in use yet.
58while true; do
59    port=$((RANDOM + 32768))
60    if $QEMU_NBD -p $port -f raw --fork null-co:// 2> /dev/null; then
61        break
62    fi
63done
64
65$QEMU_IMG info "json:{'driver': 'nbd', 'host': 'localhost', 'port': $port}" \
66    | grep '^image' | sed -e "s/$port/PORT/"
67
68# This is a test for NBD's bdrv_refresh_filename() implementation: It expects
69# either host or path to be set, but it must not assume that they are set to
70# strings in the options QDict
71$QEMU_NBD -k "$PWD/42" -f raw --fork null-co://
72$QEMU_IMG info 'json:{"driver": "nbd", "path": 42}' | grep '^image'
73rm -f 42
74
75
76echo
77echo '=== SSH ==='
78# SSH expects all of its arguments to be strings, except for @port, which is
79# expected to be an integer
80
81# So "0" should be converted to an integer here (instead of crashing)
82$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": "0", "path": "/foo"}'
83# The same, basically (all values for --image-opts are seen as strings in qemu)
84$QEMU_IMG info --image-opts \
85    driver=ssh,host=localhost,port=0,path=/foo
86
87# This, however, should fail because of the wrong type
88$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": 0.42, "path": "/foo"}'
89# Not really the same: Here, "0.42" will be passed instead of 0.42, but still,
90# qemu should not try to convert "0.42" to an integer
91$QEMU_IMG info --image-opts \
92    driver=ssh,host=localhost,port=0.42,path=/foo
93
94
95echo
96echo '=== blkdebug ==='
97# blkdebug expects all of its arguments to be strings, but its
98# bdrv_refresh_filename() implementation should not assume that they have been
99# passed as strings in the original options QDict.
100# So this should emit blkdebug:42:null-co:// as the filename:
101touch 42
102$QEMU_IMG info 'json:{"driver": "blkdebug", "config": 42,
103                      "image.driver": "null-co"}' \
104    | grep '^image'
105rm -f 42
106
107
108# success, all done
109echo
110echo '*** done'
111rm -f $seq.full
112status=0
113