xref: /openbmc/qemu/tests/qemu-iotests/162 (revision 68894b5fed671d49587209697f2224b4e857fd1a)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: quick
37d3e6936SMax Reitz#
47d3e6936SMax Reitz# Test case for specifying runtime options of the wrong type to some
57d3e6936SMax Reitz# block drivers
67d3e6936SMax Reitz#
77d3e6936SMax Reitz# Copyright (C) 2016 Red Hat, Inc.
87d3e6936SMax Reitz#
97d3e6936SMax Reitz# This program is free software; you can redistribute it and/or modify
107d3e6936SMax Reitz# it under the terms of the GNU General Public License as published by
117d3e6936SMax Reitz# the Free Software Foundation; either version 2 of the License, or
127d3e6936SMax Reitz# (at your option) any later version.
137d3e6936SMax Reitz#
147d3e6936SMax Reitz# This program is distributed in the hope that it will be useful,
157d3e6936SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
167d3e6936SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
177d3e6936SMax Reitz# GNU General Public License for more details.
187d3e6936SMax Reitz#
197d3e6936SMax Reitz# You should have received a copy of the GNU General Public License
207d3e6936SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
217d3e6936SMax Reitz#
227d3e6936SMax Reitz
237d3e6936SMax Reitz# creator
24*42a5009dSJohn Snowowner=hreitz@redhat.com
257d3e6936SMax Reitz
267d3e6936SMax Reitzseq="$(basename $0)"
277d3e6936SMax Reitzecho "QA output created by $seq"
287d3e6936SMax Reitz
297d3e6936SMax Reitzstatus=1	# failure is the default!
307d3e6936SMax Reitz
31a8e9c848SKevin Wolf_cleanup()
32a8e9c848SKevin Wolf{
33a8e9c848SKevin Wolf    rm -f "${TEST_DIR}/qemu-nbd.pid"
34a8e9c848SKevin Wolf    rm -f 42
35a8e9c848SKevin Wolf}
36a8e9c848SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
37a8e9c848SKevin Wolf
387d3e6936SMax Reitz# get standard environment, filters and checks
397d3e6936SMax Reitz. ./common.rc
407d3e6936SMax Reitz. ./common.filter
417d3e6936SMax Reitz
427d3e6936SMax Reitz_supported_fmt generic
4321b43d00SThomas Huth_require_drivers ssh
44eaed0907SMax Reitz
457d3e6936SMax Reitzecho
467d3e6936SMax Reitzecho '=== NBD ==='
477d3e6936SMax Reitz# NBD expects all of its arguments to be strings
487d3e6936SMax Reitz
497d3e6936SMax Reitz# So this should not crash
5035f05b2eSMax Reitz$QEMU_IMG info 'json:{"driver": "nbd", "host": -1}'
517d3e6936SMax Reitz
527d3e6936SMax Reitz# And this should not treat @port as if it had not been specified
5312ac9d9eSMax Reitz# (We need to set up a server here, because the error message for "Connection
5412ac9d9eSMax Reitz#  refused" does not contain the destination port)
5512ac9d9eSMax Reitz
5612ac9d9eSMax Reitz# Launching qemu-nbd is done in a loop: We try to set up an NBD server on some
5712ac9d9eSMax Reitz# random port and continue until success, i.e. until we have found a port that
5812ac9d9eSMax Reitz# is not in use yet.
5912ac9d9eSMax Reitzwhile true; do
6012ac9d9eSMax Reitz    port=$((RANDOM + 32768))
6112ac9d9eSMax Reitz    if $QEMU_NBD -p $port -f raw --fork null-co:// 2> /dev/null; then
6212ac9d9eSMax Reitz        break
6312ac9d9eSMax Reitz    fi
6412ac9d9eSMax Reitzdone
6512ac9d9eSMax Reitz
6612ac9d9eSMax Reitz$QEMU_IMG info "json:{'driver': 'nbd', 'host': 'localhost', 'port': $port}" \
6712ac9d9eSMax Reitz    | grep '^image' | sed -e "s/$port/PORT/"
687d3e6936SMax Reitz
697d3e6936SMax Reitz# This is a test for NBD's bdrv_refresh_filename() implementation: It expects
707d3e6936SMax Reitz# either host or path to be set, but it must not assume that they are set to
717d3e6936SMax Reitz# strings in the options QDict
72668b4406SMax Reitz$QEMU_NBD -k "$PWD/42" -f raw --fork null-co://
737d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "nbd", "path": 42}' | grep '^image'
747d3e6936SMax Reitzrm -f 42
757d3e6936SMax Reitz
767d3e6936SMax Reitz
777d3e6936SMax Reitzecho
787d3e6936SMax Reitzecho '=== SSH ==='
797d3e6936SMax Reitz# SSH expects all of its arguments to be strings, except for @port, which is
807d3e6936SMax Reitz# expected to be an integer
817d3e6936SMax Reitz
827d3e6936SMax Reitz# So "0" should be converted to an integer here (instead of crashing)
837d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": "0", "path": "/foo"}'
847d3e6936SMax Reitz# The same, basically (all values for --image-opts are seen as strings in qemu)
857d3e6936SMax Reitz$QEMU_IMG info --image-opts \
867d3e6936SMax Reitz    driver=ssh,host=localhost,port=0,path=/foo
877d3e6936SMax Reitz
887d3e6936SMax Reitz# This, however, should fail because of the wrong type
897d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": 0.42, "path": "/foo"}'
907d3e6936SMax Reitz# Not really the same: Here, "0.42" will be passed instead of 0.42, but still,
917d3e6936SMax Reitz# qemu should not try to convert "0.42" to an integer
927d3e6936SMax Reitz$QEMU_IMG info --image-opts \
937d3e6936SMax Reitz    driver=ssh,host=localhost,port=0.42,path=/foo
947d3e6936SMax Reitz
957d3e6936SMax Reitz
967d3e6936SMax Reitzecho
977d3e6936SMax Reitzecho '=== blkdebug ==='
987d3e6936SMax Reitz# blkdebug expects all of its arguments to be strings, but its
997d3e6936SMax Reitz# bdrv_refresh_filename() implementation should not assume that they have been
1007d3e6936SMax Reitz# passed as strings in the original options QDict.
1017d3e6936SMax Reitz# So this should emit blkdebug:42:null-co:// as the filename:
1027d3e6936SMax Reitztouch 42
1037d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "blkdebug", "config": 42,
1047d3e6936SMax Reitz                      "image.driver": "null-co"}' \
1057d3e6936SMax Reitz    | grep '^image'
1067d3e6936SMax Reitzrm -f 42
1077d3e6936SMax Reitz
1087d3e6936SMax Reitz
1097d3e6936SMax Reitz# success, all done
1107d3e6936SMax Reitzecho
1117d3e6936SMax Reitzecho '*** done'
1127d3e6936SMax Reitzrm -f $seq.full
1137d3e6936SMax Reitzstatus=0
114