111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Reitzstatus=1 # failure is the default! 29911864c6SMax Reitz 30911864c6SMax Reitz_cleanup() 31911864c6SMax Reitz{ 32911864c6SMax Reitz _cleanup_test_img 33*f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.compare" 34*f91ecbd7SMax Reitz rm -f "$TEST_DIR/blkdebug.conf" 35*f91ecbd7SMax Reitz 36911864c6SMax Reitz} 37911864c6SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 38911864c6SMax Reitz 39911864c6SMax Reitz# get standard environment, filters and checks 40911864c6SMax Reitz. ./common.rc 41911864c6SMax Reitz. ./common.filter 42911864c6SMax Reitz 43911864c6SMax Reitz# Basically all formats, but "raw" has issues with _filter_imgfmt regarding the 44911864c6SMax Reitz# raw comparison image for blkverify; also, all images have to support creation 45550830f9SStefan Hajnoczi_supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc 46911864c6SMax Reitz_supported_proto file 47911864c6SMax Reitz_supported_os Linux 4821b43d00SThomas Huth_require_drivers blkdebug blkverify 490fc9b0d1SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ 500fc9b0d1SFam Zheng "subformat=twoGbMaxExtentSparse" 51911864c6SMax Reitz 528cedcffdSEric Blakedo_run_qemu() 53911864c6SMax Reitz{ 54911864c6SMax Reitz $QEMU -nographic -qmp stdio -serial none "$@" 55911864c6SMax Reitz} 56911864c6SMax Reitz 578cedcffdSEric Blakerun_qemu() 58911864c6SMax Reitz{ 59911864c6SMax Reitz # Get the "file": "foo" entry ($foo may only contain escaped double quotes, 60911864c6SMax Reitz # which is how we can extract it) 61911864c6SMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \ 624dd7b8d3SMax Reitz | _filter_qemu | grep "drv0" \ 63911864c6SMax Reitz | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g' 64911864c6SMax Reitz} 65911864c6SMax Reitz 668cedcffdSEric Blaketest_qemu() 67911864c6SMax Reitz{ 68911864c6SMax Reitz run_qemu -drive "if=none,id=drv0,$1" <<EOF 69911864c6SMax Reitz { 'execute': 'qmp_capabilities' } 70911864c6SMax Reitz { 'execute': 'query-block' } 71911864c6SMax Reitz { 'execute': 'quit' } 72911864c6SMax ReitzEOF 73911864c6SMax Reitz} 74911864c6SMax Reitz 75911864c6SMax Reitz 76911864c6SMax Reitz 77911864c6SMax ReitzIMG_SIZE=128K 78911864c6SMax Reitz 79911864c6SMax Reitz_make_test_img $IMG_SIZE 80911864c6SMax Reitz$QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \ 81911864c6SMax Reitz | _filter_testdir | _filter_imgfmt 82911864c6SMax Reitz 83911864c6SMax Reitzecho 84911864c6SMax Reitzecho '=== Testing simple filename for blkverify ===' 85911864c6SMax Reitzecho 86911864c6SMax Reitz 87911864c6SMax Reitz# This should return simply the filename itself 88911864c6SMax Reitztest_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG" 89911864c6SMax Reitz 90911864c6SMax Reitzecho 91911864c6SMax Reitzecho '=== Testing filename reconstruction for blkverify ===' 92911864c6SMax Reitzecho 93911864c6SMax Reitz 94911864c6SMax Reitz# This should return the same filename as above 95911864c6SMax Reitztest_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG" 96911864c6SMax Reitz 97911864c6SMax Reitzecho 98911864c6SMax Reitzecho '=== Testing JSON filename for blkdebug ===' 99911864c6SMax Reitzecho 100911864c6SMax Reitz 101911864c6SMax Reitz# blkdebug cannot create a configuration file, therefore it is unable to 102911864c6SMax Reitz# generate a plain filename here; thus this should return a JSON filename 103911864c6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update" 104911864c6SMax Reitz 105911864c6SMax Reitzecho 106911864c6SMax Reitzecho '=== Testing indirectly enforced JSON filename ===' 107911864c6SMax Reitzecho 108911864c6SMax Reitz 109911864c6SMax Reitz# Because blkdebug cannot return a plain filename, blkverify is forced to 110911864c6SMax Reitz# generate a JSON object here as well 111911864c6SMax 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" 112911864c6SMax Reitz 113f48a33b6SMax Reitzecho 114f48a33b6SMax Reitzecho '=== Testing plain filename for blkdebug ===' 115f48a33b6SMax Reitzecho 116911864c6SMax Reitz 117f48a33b6SMax Reitztouch "$TEST_DIR/blkdebug.conf" 118f48a33b6SMax Reitztest_qemu "file.driver=blkdebug,file.config=$TEST_DIR/blkdebug.conf,file.image.filename=$TEST_IMG" 119f48a33b6SMax Reitz 120f48a33b6SMax Reitzecho 121f48a33b6SMax Reitzecho '=== Testing plain filename for blkdebug without configuration file ===' 122f48a33b6SMax Reitzecho 123f48a33b6SMax Reitz 124f48a33b6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG" 125f48a33b6SMax Reitz 126f48a33b6SMax Reitz 127911864c6SMax Reitz# success, all done 128911864c6SMax Reitzecho "*** done" 129911864c6SMax Reitzrm -f $seq.full 130911864c6SMax Reitzstatus=0 131