blob: 65e8e9257200c2951a088def307b55d2e1c0e3d5 [file] [log] [blame]
Philippe Mathieu-Daudé11a82d12019-03-07 15:58:38 +01001#!/usr/bin/env bash
Max Reitz911864c2014-07-18 20:25:01 +02002#
3# Test valid filenames for blkdebug and blkverify representatively for
4# other protocols (such as NBD) when queried
5#
6# Copyright (C) 2014 Red Hat, Inc.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21
22# creator
23owner=mreitz@redhat.com
24
25seq="$(basename $0)"
26echo "QA output created by $seq"
27
Max Reitz911864c2014-07-18 20:25:01 +020028status=1 # failure is the default!
29
30_cleanup()
31{
Max Reitzf91ecbd2019-11-07 17:37:01 +010032 _cleanup_test_img
33 _rm_test_img "$TEST_IMG.compare"
34 rm -f "$TEST_DIR/blkdebug.conf"
35
Max Reitz911864c2014-07-18 20:25:01 +020036}
37trap "_cleanup; exit \$status" 0 1 2 3 15
38
39# get standard environment, filters and checks
40. ./common.rc
41. ./common.filter
42
43# Basically all formats, but "raw" has issues with _filter_imgfmt regarding the
44# raw comparison image for blkverify; also, all images have to support creation
Stefan Hajnoczi550830f2014-09-16 15:24:24 +010045_supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc
Max Reitz911864c2014-07-18 20:25:01 +020046_supported_proto file
47_supported_os Linux
Thomas Huth21b43d02019-08-23 15:35:52 +020048_require_drivers blkdebug blkverify
Max Reitz3be20242019-11-07 17:37:07 +010049# data_file would change the json:{} filenames
Fam Zheng0fc9b0d2014-12-03 09:49:30 +080050_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
Max Reitz3be20242019-11-07 17:37:07 +010051 "subformat=twoGbMaxExtentSparse" data_file
Max Reitz911864c2014-07-18 20:25:01 +020052
Eric Blake8cedcff2018-11-16 15:50:02 -060053do_run_qemu()
Max Reitz911864c2014-07-18 20:25:01 +020054{
55 $QEMU -nographic -qmp stdio -serial none "$@"
56}
57
Eric Blake8cedcff2018-11-16 15:50:02 -060058run_qemu()
Max Reitz911864c2014-07-18 20:25:01 +020059{
60 # Get the "file": "foo" entry ($foo may only contain escaped double quotes,
61 # which is how we can extract it)
62 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \
Max Reitz4dd7b8d2014-12-19 17:17:06 +010063 | _filter_qemu | grep "drv0" \
Max Reitz911864c2014-07-18 20:25:01 +020064 | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g'
65}
66
Eric Blake8cedcff2018-11-16 15:50:02 -060067test_qemu()
Max Reitz911864c2014-07-18 20:25:01 +020068{
69 run_qemu -drive "if=none,id=drv0,$1" <<EOF
70 { 'execute': 'qmp_capabilities' }
71 { 'execute': 'query-block' }
72 { 'execute': 'quit' }
73EOF
74}
75
76
77
78IMG_SIZE=128K
79
80_make_test_img $IMG_SIZE
81$QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \
82 | _filter_testdir | _filter_imgfmt
83
84echo
85echo '=== Testing simple filename for blkverify ==='
86echo
87
88# This should return simply the filename itself
89test_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG"
90
91echo
92echo '=== Testing filename reconstruction for blkverify ==='
93echo
94
95# This should return the same filename as above
96test_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG"
97
98echo
99echo '=== Testing JSON filename for blkdebug ==='
100echo
101
102# blkdebug cannot create a configuration file, therefore it is unable to
103# generate a plain filename here; thus this should return a JSON filename
104test_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update"
105
106echo
107echo '=== Testing indirectly enforced JSON filename ==='
108echo
109
110# Because blkdebug cannot return a plain filename, blkverify is forced to
111# generate a JSON object here as well
112test_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"
113
Max Reitzf48a33b2014-11-11 10:23:45 +0100114echo
115echo '=== Testing plain filename for blkdebug ==='
116echo
Max Reitz911864c2014-07-18 20:25:01 +0200117
Max Reitzf48a33b2014-11-11 10:23:45 +0100118touch "$TEST_DIR/blkdebug.conf"
119test_qemu "file.driver=blkdebug,file.config=$TEST_DIR/blkdebug.conf,file.image.filename=$TEST_IMG"
120
121echo
122echo '=== Testing plain filename for blkdebug without configuration file ==='
123echo
124
125test_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG"
126
127
Max Reitz911864c2014-07-18 20:25:01 +0200128# success, all done
129echo "*** done"
130rm -f $seq.full
131status=0