17d3e6936SMax Reitz#!/bin/bash 27d3e6936SMax Reitz# 37d3e6936SMax Reitz# Test case for specifying runtime options of the wrong type to some 47d3e6936SMax Reitz# block drivers 57d3e6936SMax Reitz# 67d3e6936SMax Reitz# Copyright (C) 2016 Red Hat, Inc. 77d3e6936SMax Reitz# 87d3e6936SMax Reitz# This program is free software; you can redistribute it and/or modify 97d3e6936SMax Reitz# it under the terms of the GNU General Public License as published by 107d3e6936SMax Reitz# the Free Software Foundation; either version 2 of the License, or 117d3e6936SMax Reitz# (at your option) any later version. 127d3e6936SMax Reitz# 137d3e6936SMax Reitz# This program is distributed in the hope that it will be useful, 147d3e6936SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 157d3e6936SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 167d3e6936SMax Reitz# GNU General Public License for more details. 177d3e6936SMax Reitz# 187d3e6936SMax Reitz# You should have received a copy of the GNU General Public License 197d3e6936SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 207d3e6936SMax Reitz# 217d3e6936SMax Reitz 227d3e6936SMax Reitz# creator 237d3e6936SMax Reitzowner=mreitz@redhat.com 247d3e6936SMax Reitz 257d3e6936SMax Reitzseq="$(basename $0)" 267d3e6936SMax Reitzecho "QA output created by $seq" 277d3e6936SMax Reitz 287d3e6936SMax Reitzhere="$PWD" 297d3e6936SMax Reitzstatus=1 # failure is the default! 307d3e6936SMax Reitz 317d3e6936SMax Reitz# get standard environment, filters and checks 327d3e6936SMax Reitz. ./common.rc 337d3e6936SMax Reitz. ./common.filter 347d3e6936SMax Reitz 357d3e6936SMax Reitz_supported_fmt generic 367d3e6936SMax Reitz_supported_os Linux 377d3e6936SMax Reitz 387d3e6936SMax Reitzecho 397d3e6936SMax Reitzecho '=== NBD ===' 407d3e6936SMax Reitz# NBD expects all of its arguments to be strings 417d3e6936SMax Reitz 427d3e6936SMax Reitz# So this should not crash 437d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "nbd", "host": 42}' 447d3e6936SMax Reitz 457d3e6936SMax Reitz# And this should not treat @port as if it had not been specified 467d3e6936SMax Reitz# (We cannot use localhost with an invalid port here, but we need to use a 477d3e6936SMax Reitz# non-existing domain, because otherwise the error message will not contain 487d3e6936SMax Reitz# the port) 497d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "nbd", "host": "does.not.exist.example.com", "port": 42}' 507d3e6936SMax Reitz 517d3e6936SMax Reitz# This is a test for NBD's bdrv_refresh_filename() implementation: It expects 527d3e6936SMax Reitz# either host or path to be set, but it must not assume that they are set to 537d3e6936SMax Reitz# strings in the options QDict 54*668b4406SMax Reitz$QEMU_NBD -k "$PWD/42" -f raw --fork null-co:// 557d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "nbd", "path": 42}' | grep '^image' 567d3e6936SMax Reitzrm -f 42 577d3e6936SMax Reitz 587d3e6936SMax Reitz 597d3e6936SMax Reitzecho 607d3e6936SMax Reitzecho '=== SSH ===' 617d3e6936SMax Reitz# SSH expects all of its arguments to be strings, except for @port, which is 627d3e6936SMax Reitz# expected to be an integer 637d3e6936SMax Reitz 647d3e6936SMax Reitz# So "0" should be converted to an integer here (instead of crashing) 657d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": "0", "path": "/foo"}' 667d3e6936SMax Reitz# The same, basically (all values for --image-opts are seen as strings in qemu) 677d3e6936SMax Reitz$QEMU_IMG info --image-opts \ 687d3e6936SMax Reitz driver=ssh,host=localhost,port=0,path=/foo 697d3e6936SMax Reitz 707d3e6936SMax Reitz# This, however, should fail because of the wrong type 717d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": 0.42, "path": "/foo"}' 727d3e6936SMax Reitz# Not really the same: Here, "0.42" will be passed instead of 0.42, but still, 737d3e6936SMax Reitz# qemu should not try to convert "0.42" to an integer 747d3e6936SMax Reitz$QEMU_IMG info --image-opts \ 757d3e6936SMax Reitz driver=ssh,host=localhost,port=0.42,path=/foo 767d3e6936SMax Reitz 777d3e6936SMax Reitz 787d3e6936SMax Reitzecho 797d3e6936SMax Reitzecho '=== blkdebug ===' 807d3e6936SMax Reitz# blkdebug expects all of its arguments to be strings, but its 817d3e6936SMax Reitz# bdrv_refresh_filename() implementation should not assume that they have been 827d3e6936SMax Reitz# passed as strings in the original options QDict. 837d3e6936SMax Reitz# So this should emit blkdebug:42:null-co:// as the filename: 847d3e6936SMax Reitztouch 42 857d3e6936SMax Reitz$QEMU_IMG info 'json:{"driver": "blkdebug", "config": 42, 867d3e6936SMax Reitz "image.driver": "null-co"}' \ 877d3e6936SMax Reitz | grep '^image' 887d3e6936SMax Reitzrm -f 42 897d3e6936SMax Reitz 907d3e6936SMax Reitz 917d3e6936SMax Reitz# success, all done 927d3e6936SMax Reitzecho 937d3e6936SMax Reitzecho '*** done' 947d3e6936SMax Reitzrm -f $seq.full 957d3e6936SMax Reitzstatus=0 96