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