1911864c6SMax Reitz#!/bin/bash 2911864c6SMax Reitz# 3911864c6SMax Reitz# Test valid filenames for blkdebug and blkverify representatively for 4911864c6SMax Reitz# other protocols (such as NBD) when queried 5911864c6SMax Reitz# 6911864c6SMax Reitz# Copyright (C) 2014 Red Hat, Inc. 7911864c6SMax Reitz# 8911864c6SMax Reitz# This program is free software; you can redistribute it and/or modify 9911864c6SMax Reitz# it under the terms of the GNU General Public License as published by 10911864c6SMax Reitz# the Free Software Foundation; either version 2 of the License, or 11911864c6SMax Reitz# (at your option) any later version. 12911864c6SMax Reitz# 13911864c6SMax Reitz# This program is distributed in the hope that it will be useful, 14911864c6SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 15911864c6SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16911864c6SMax Reitz# GNU General Public License for more details. 17911864c6SMax Reitz# 18911864c6SMax Reitz# You should have received a copy of the GNU General Public License 19911864c6SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 20911864c6SMax Reitz# 21911864c6SMax Reitz 22911864c6SMax Reitz# creator 23911864c6SMax Reitzowner=mreitz@redhat.com 24911864c6SMax Reitz 25911864c6SMax Reitzseq="$(basename $0)" 26911864c6SMax Reitzecho "QA output created by $seq" 27911864c6SMax Reitz 28911864c6SMax Reitzhere="$PWD" 29911864c6SMax Reitztmp=/tmp/$$ 30911864c6SMax Reitzstatus=1 # failure is the default! 31911864c6SMax Reitz 32911864c6SMax Reitz_cleanup() 33911864c6SMax Reitz{ 34911864c6SMax Reitz _cleanup_test_img 35911864c6SMax Reitz} 36911864c6SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 37911864c6SMax Reitz 38911864c6SMax Reitz# get standard environment, filters and checks 39911864c6SMax Reitz. ./common.rc 40911864c6SMax Reitz. ./common.filter 41911864c6SMax Reitz 42911864c6SMax Reitz# Basically all formats, but "raw" has issues with _filter_imgfmt regarding the 43911864c6SMax Reitz# raw comparison image for blkverify; also, all images have to support creation 44*550830f9SStefan Hajnoczi_supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc 45911864c6SMax Reitz_supported_proto file 46911864c6SMax Reitz_supported_os Linux 47911864c6SMax Reitz 48911864c6SMax Reitz 49911864c6SMax Reitzfunction do_run_qemu() 50911864c6SMax Reitz{ 51911864c6SMax Reitz $QEMU -nographic -qmp stdio -serial none "$@" 52911864c6SMax Reitz} 53911864c6SMax Reitz 54911864c6SMax Reitzfunction run_qemu() 55911864c6SMax Reitz{ 56911864c6SMax Reitz # Get the "file": "foo" entry ($foo may only contain escaped double quotes, 57911864c6SMax Reitz # which is how we can extract it) 58911864c6SMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \ 59911864c6SMax Reitz | grep "drv0" \ 60911864c6SMax Reitz | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g' 61911864c6SMax Reitz} 62911864c6SMax Reitz 63911864c6SMax Reitzfunction test_qemu() 64911864c6SMax Reitz{ 65911864c6SMax Reitz run_qemu -drive "if=none,id=drv0,$1" <<EOF 66911864c6SMax Reitz { 'execute': 'qmp_capabilities' } 67911864c6SMax Reitz { 'execute': 'query-block' } 68911864c6SMax Reitz { 'execute': 'quit' } 69911864c6SMax ReitzEOF 70911864c6SMax Reitz} 71911864c6SMax Reitz 72911864c6SMax Reitz 73911864c6SMax Reitz 74911864c6SMax ReitzIMG_SIZE=128K 75911864c6SMax Reitz 76911864c6SMax Reitz_make_test_img $IMG_SIZE 77911864c6SMax Reitz$QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \ 78911864c6SMax Reitz | _filter_testdir | _filter_imgfmt 79911864c6SMax Reitz 80911864c6SMax Reitzecho 81911864c6SMax Reitzecho '=== Testing simple filename for blkverify ===' 82911864c6SMax Reitzecho 83911864c6SMax Reitz 84911864c6SMax Reitz# This should return simply the filename itself 85911864c6SMax Reitztest_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG" 86911864c6SMax Reitz 87911864c6SMax Reitzecho 88911864c6SMax Reitzecho '=== Testing filename reconstruction for blkverify ===' 89911864c6SMax Reitzecho 90911864c6SMax Reitz 91911864c6SMax Reitz# This should return the same filename as above 92911864c6SMax Reitztest_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG" 93911864c6SMax Reitz 94911864c6SMax Reitzecho 95911864c6SMax Reitzecho '=== Testing JSON filename for blkdebug ===' 96911864c6SMax Reitzecho 97911864c6SMax Reitz 98911864c6SMax Reitz# blkdebug cannot create a configuration file, therefore it is unable to 99911864c6SMax Reitz# generate a plain filename here; thus this should return a JSON filename 100911864c6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update" 101911864c6SMax Reitz 102911864c6SMax Reitzecho 103911864c6SMax Reitzecho '=== Testing indirectly enforced JSON filename ===' 104911864c6SMax Reitzecho 105911864c6SMax Reitz 106911864c6SMax Reitz# Because blkdebug cannot return a plain filename, blkverify is forced to 107911864c6SMax Reitz# generate a JSON object here as well 108911864c6SMax Reitztest_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.driver=blkdebug,file.test.file.image.filename=$TEST_IMG,file.test.file.inject-error.0.event=l1_update" 109911864c6SMax Reitz 110911864c6SMax Reitz 111911864c6SMax Reitzrm -f "$TEST_IMG.compare" 112911864c6SMax Reitz 113911864c6SMax Reitz# success, all done 114911864c6SMax Reitzecho "*** done" 115911864c6SMax Reitzrm -f $seq.full 116911864c6SMax Reitzstatus=0 117