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