xref: /qemu/tests/qemu-iotests/162 (revision 7d3e693646ad07459e04898663b37000858b4c20)
1*7d3e6936SMax Reitz#!/bin/bash
2*7d3e6936SMax Reitz#
3*7d3e6936SMax Reitz# Test case for specifying runtime options of the wrong type to some
4*7d3e6936SMax Reitz# block drivers
5*7d3e6936SMax Reitz#
6*7d3e6936SMax Reitz# Copyright (C) 2016 Red Hat, Inc.
7*7d3e6936SMax Reitz#
8*7d3e6936SMax Reitz# This program is free software; you can redistribute it and/or modify
9*7d3e6936SMax Reitz# it under the terms of the GNU General Public License as published by
10*7d3e6936SMax Reitz# the Free Software Foundation; either version 2 of the License, or
11*7d3e6936SMax Reitz# (at your option) any later version.
12*7d3e6936SMax Reitz#
13*7d3e6936SMax Reitz# This program is distributed in the hope that it will be useful,
14*7d3e6936SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
15*7d3e6936SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*7d3e6936SMax Reitz# GNU General Public License for more details.
17*7d3e6936SMax Reitz#
18*7d3e6936SMax Reitz# You should have received a copy of the GNU General Public License
19*7d3e6936SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20*7d3e6936SMax Reitz#
21*7d3e6936SMax Reitz
22*7d3e6936SMax Reitz# creator
23*7d3e6936SMax Reitzowner=mreitz@redhat.com
24*7d3e6936SMax Reitz
25*7d3e6936SMax Reitzseq="$(basename $0)"
26*7d3e6936SMax Reitzecho "QA output created by $seq"
27*7d3e6936SMax Reitz
28*7d3e6936SMax Reitzhere="$PWD"
29*7d3e6936SMax Reitzstatus=1	# failure is the default!
30*7d3e6936SMax Reitz
31*7d3e6936SMax Reitz# get standard environment, filters and checks
32*7d3e6936SMax Reitz. ./common.rc
33*7d3e6936SMax Reitz. ./common.filter
34*7d3e6936SMax Reitz
35*7d3e6936SMax Reitz_supported_fmt generic
36*7d3e6936SMax Reitz_supported_os Linux
37*7d3e6936SMax Reitz
38*7d3e6936SMax Reitzecho
39*7d3e6936SMax Reitzecho '=== NBD ==='
40*7d3e6936SMax Reitz# NBD expects all of its arguments to be strings
41*7d3e6936SMax Reitz
42*7d3e6936SMax Reitz# So this should not crash
43*7d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "nbd", "host": 42}'
44*7d3e6936SMax Reitz
45*7d3e6936SMax Reitz# And this should not treat @port as if it had not been specified
46*7d3e6936SMax Reitz# (We cannot use localhost with an invalid port here, but we need to use a
47*7d3e6936SMax Reitz#  non-existing domain, because otherwise the error message will not contain
48*7d3e6936SMax Reitz#  the port)
49*7d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "nbd", "host": "does.not.exist.example.com", "port": 42}'
50*7d3e6936SMax Reitz
51*7d3e6936SMax Reitz# This is a test for NBD's bdrv_refresh_filename() implementation: It expects
52*7d3e6936SMax Reitz# either host or path to be set, but it must not assume that they are set to
53*7d3e6936SMax Reitz# strings in the options QDict
54*7d3e6936SMax Reitz$QEMU_NBD -k "$PWD/42" -f raw null-co:// &
55*7d3e6936SMax Reitzsleep 0.5
56*7d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "nbd", "path": 42}' | grep '^image'
57*7d3e6936SMax Reitzrm -f 42
58*7d3e6936SMax Reitz
59*7d3e6936SMax Reitz
60*7d3e6936SMax Reitzecho
61*7d3e6936SMax Reitzecho '=== SSH ==='
62*7d3e6936SMax Reitz# SSH expects all of its arguments to be strings, except for @port, which is
63*7d3e6936SMax Reitz# expected to be an integer
64*7d3e6936SMax Reitz
65*7d3e6936SMax Reitz# So "0" should be converted to an integer here (instead of crashing)
66*7d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": "0", "path": "/foo"}'
67*7d3e6936SMax Reitz# The same, basically (all values for --image-opts are seen as strings in qemu)
68*7d3e6936SMax Reitz$QEMU_IMG info --image-opts \
69*7d3e6936SMax Reitz    driver=ssh,host=localhost,port=0,path=/foo
70*7d3e6936SMax Reitz
71*7d3e6936SMax Reitz# This, however, should fail because of the wrong type
72*7d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": 0.42, "path": "/foo"}'
73*7d3e6936SMax Reitz# Not really the same: Here, "0.42" will be passed instead of 0.42, but still,
74*7d3e6936SMax Reitz# qemu should not try to convert "0.42" to an integer
75*7d3e6936SMax Reitz$QEMU_IMG info --image-opts \
76*7d3e6936SMax Reitz    driver=ssh,host=localhost,port=0.42,path=/foo
77*7d3e6936SMax Reitz
78*7d3e6936SMax Reitz
79*7d3e6936SMax Reitzecho
80*7d3e6936SMax Reitzecho '=== blkdebug ==='
81*7d3e6936SMax Reitz# blkdebug expects all of its arguments to be strings, but its
82*7d3e6936SMax Reitz# bdrv_refresh_filename() implementation should not assume that they have been
83*7d3e6936SMax Reitz# passed as strings in the original options QDict.
84*7d3e6936SMax Reitz# So this should emit blkdebug:42:null-co:// as the filename:
85*7d3e6936SMax Reitztouch 42
86*7d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "blkdebug", "config": 42,
87*7d3e6936SMax Reitz                      "image.driver": "null-co"}' \
88*7d3e6936SMax Reitz    | grep '^image'
89*7d3e6936SMax Reitzrm -f 42
90*7d3e6936SMax Reitz
91*7d3e6936SMax Reitz
92*7d3e6936SMax Reitz# success, all done
93*7d3e6936SMax Reitzecho
94*7d3e6936SMax Reitzecho '*** done'
95*7d3e6936SMax Reitzrm -f $seq.full
96*7d3e6936SMax Reitzstatus=0
97