These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / tests / qemu-iotests / 099
1 #!/bin/bash
2 #
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
23 owner=mreitz@redhat.com
24
25 seq="$(basename $0)"
26 echo "QA output created by $seq"
27
28 here="$PWD"
29 status=1        # failure is the default!
30
31 _cleanup()
32 {
33         _cleanup_test_img
34 }
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
40
41 # Basically all formats, but "raw" has issues with _filter_imgfmt regarding the
42 # raw comparison image for blkverify; also, all images have to support creation
43 _supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc
44 _supported_proto file
45 _supported_os Linux
46 _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
47     "subformat=twoGbMaxExtentSparse"
48
49 function do_run_qemu()
50 {
51     $QEMU -nographic -qmp stdio -serial none "$@"
52 }
53
54 function run_qemu()
55 {
56     # Get the "file": "foo" entry ($foo may only contain escaped double quotes,
57     # which is how we can extract it)
58     do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \
59         | _filter_qemu | grep "drv0" \
60         | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g'
61 }
62
63 function test_qemu()
64 {
65     run_qemu -drive "if=none,id=drv0,$1" <<EOF
66         { 'execute': 'qmp_capabilities' }
67         { 'execute': 'query-block' }
68         { 'execute': 'quit' }
69 EOF
70 }
71
72
73
74 IMG_SIZE=128K
75
76 _make_test_img $IMG_SIZE
77 $QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \
78     | _filter_testdir | _filter_imgfmt
79
80 echo
81 echo '=== Testing simple filename for blkverify ==='
82 echo
83
84 # This should return simply the filename itself
85 test_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG"
86
87 echo
88 echo '=== Testing filename reconstruction for blkverify ==='
89 echo
90
91 # This should return the same filename as above
92 test_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG"
93
94 echo
95 echo '=== Testing JSON filename for blkdebug ==='
96 echo
97
98 # blkdebug cannot create a configuration file, therefore it is unable to
99 # generate a plain filename here; thus this should return a JSON filename
100 test_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update"
101
102 echo
103 echo '=== Testing indirectly enforced JSON filename ==='
104 echo
105
106 # Because blkdebug cannot return a plain filename, blkverify is forced to
107 # generate a JSON object here as well
108 test_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"
109
110 echo
111 echo '=== Testing plain filename for blkdebug ==='
112 echo
113
114 touch "$TEST_DIR/blkdebug.conf"
115 test_qemu "file.driver=blkdebug,file.config=$TEST_DIR/blkdebug.conf,file.image.filename=$TEST_IMG"
116
117 echo
118 echo '=== Testing plain filename for blkdebug without configuration file ==='
119 echo
120
121 test_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG"
122
123
124 rm -f "$TEST_IMG.compare" "$TEST_DIR/blkdebug.conf"
125
126 # success, all done
127 echo "*** done"
128 rm -f $seq.full
129 status=0