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 33f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.compare" 34f91ecbd7SMax Reitz rm -f "$TEST_DIR/blkdebug.conf" 35f91ecbd7SMax 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 49*3be2024aSMax Reitz# data_file would change the json:{} filenames 500fc9b0d1SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ 51*3be2024aSMax Reitz "subformat=twoGbMaxExtentSparse" data_file 52911864c6SMax Reitz 538cedcffdSEric Blakedo_run_qemu() 54911864c6SMax Reitz{ 55911864c6SMax Reitz $QEMU -nographic -qmp stdio -serial none "$@" 56911864c6SMax Reitz} 57911864c6SMax Reitz 588cedcffdSEric Blakerun_qemu() 59911864c6SMax Reitz{ 60911864c6SMax Reitz # Get the "file": "foo" entry ($foo may only contain escaped double quotes, 61911864c6SMax Reitz # which is how we can extract it) 62911864c6SMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \ 634dd7b8d3SMax Reitz | _filter_qemu | grep "drv0" \ 64911864c6SMax Reitz | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g' 65911864c6SMax Reitz} 66911864c6SMax Reitz 678cedcffdSEric Blaketest_qemu() 68911864c6SMax Reitz{ 69911864c6SMax Reitz run_qemu -drive "if=none,id=drv0,$1" <<EOF 70911864c6SMax Reitz { 'execute': 'qmp_capabilities' } 71911864c6SMax Reitz { 'execute': 'query-block' } 72911864c6SMax Reitz { 'execute': 'quit' } 73911864c6SMax ReitzEOF 74911864c6SMax Reitz} 75911864c6SMax Reitz 76911864c6SMax Reitz 77911864c6SMax Reitz 78911864c6SMax ReitzIMG_SIZE=128K 79911864c6SMax Reitz 80911864c6SMax Reitz_make_test_img $IMG_SIZE 81911864c6SMax Reitz$QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \ 82911864c6SMax Reitz | _filter_testdir | _filter_imgfmt 83911864c6SMax Reitz 84911864c6SMax Reitzecho 85911864c6SMax Reitzecho '=== Testing simple filename for blkverify ===' 86911864c6SMax Reitzecho 87911864c6SMax Reitz 88911864c6SMax Reitz# This should return simply the filename itself 89911864c6SMax Reitztest_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG" 90911864c6SMax Reitz 91911864c6SMax Reitzecho 92911864c6SMax Reitzecho '=== Testing filename reconstruction for blkverify ===' 93911864c6SMax Reitzecho 94911864c6SMax Reitz 95911864c6SMax Reitz# This should return the same filename as above 96911864c6SMax Reitztest_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG" 97911864c6SMax Reitz 98911864c6SMax Reitzecho 99911864c6SMax Reitzecho '=== Testing JSON filename for blkdebug ===' 100911864c6SMax Reitzecho 101911864c6SMax Reitz 102911864c6SMax Reitz# blkdebug cannot create a configuration file, therefore it is unable to 103911864c6SMax Reitz# generate a plain filename here; thus this should return a JSON filename 104911864c6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update" 105911864c6SMax Reitz 106911864c6SMax Reitzecho 107911864c6SMax Reitzecho '=== Testing indirectly enforced JSON filename ===' 108911864c6SMax Reitzecho 109911864c6SMax Reitz 110911864c6SMax Reitz# Because blkdebug cannot return a plain filename, blkverify is forced to 111911864c6SMax Reitz# generate a JSON object here as well 112911864c6SMax 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" 113911864c6SMax Reitz 114f48a33b6SMax Reitzecho 115f48a33b6SMax Reitzecho '=== Testing plain filename for blkdebug ===' 116f48a33b6SMax Reitzecho 117911864c6SMax Reitz 118f48a33b6SMax Reitztouch "$TEST_DIR/blkdebug.conf" 119f48a33b6SMax Reitztest_qemu "file.driver=blkdebug,file.config=$TEST_DIR/blkdebug.conf,file.image.filename=$TEST_IMG" 120f48a33b6SMax Reitz 121f48a33b6SMax Reitzecho 122f48a33b6SMax Reitzecho '=== Testing plain filename for blkdebug without configuration file ===' 123f48a33b6SMax Reitzecho 124f48a33b6SMax Reitz 125f48a33b6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG" 126f48a33b6SMax Reitz 127f48a33b6SMax Reitz 128911864c6SMax Reitz# success, all done 129911864c6SMax Reitzecho "*** done" 130911864c6SMax Reitzrm -f $seq.full 131911864c6SMax Reitzstatus=0 132