xref: /openbmc/qemu/tests/qemu-iotests/099 (revision 911864c6e5f58a86ac987aa4d2e5743851374c05)
1*911864c6SMax Reitz#!/bin/bash
2*911864c6SMax Reitz#
3*911864c6SMax Reitz# Test valid filenames for blkdebug and blkverify representatively for
4*911864c6SMax Reitz# other protocols (such as NBD) when queried
5*911864c6SMax Reitz#
6*911864c6SMax Reitz# Copyright (C) 2014 Red Hat, Inc.
7*911864c6SMax Reitz#
8*911864c6SMax Reitz# This program is free software; you can redistribute it and/or modify
9*911864c6SMax Reitz# it under the terms of the GNU General Public License as published by
10*911864c6SMax Reitz# the Free Software Foundation; either version 2 of the License, or
11*911864c6SMax Reitz# (at your option) any later version.
12*911864c6SMax Reitz#
13*911864c6SMax Reitz# This program is distributed in the hope that it will be useful,
14*911864c6SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
15*911864c6SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*911864c6SMax Reitz# GNU General Public License for more details.
17*911864c6SMax Reitz#
18*911864c6SMax Reitz# You should have received a copy of the GNU General Public License
19*911864c6SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20*911864c6SMax Reitz#
21*911864c6SMax Reitz
22*911864c6SMax Reitz# creator
23*911864c6SMax Reitzowner=mreitz@redhat.com
24*911864c6SMax Reitz
25*911864c6SMax Reitzseq="$(basename $0)"
26*911864c6SMax Reitzecho "QA output created by $seq"
27*911864c6SMax Reitz
28*911864c6SMax Reitzhere="$PWD"
29*911864c6SMax Reitztmp=/tmp/$$
30*911864c6SMax Reitzstatus=1	# failure is the default!
31*911864c6SMax Reitz
32*911864c6SMax Reitz_cleanup()
33*911864c6SMax Reitz{
34*911864c6SMax Reitz	_cleanup_test_img
35*911864c6SMax Reitz}
36*911864c6SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
37*911864c6SMax Reitz
38*911864c6SMax Reitz# get standard environment, filters and checks
39*911864c6SMax Reitz. ./common.rc
40*911864c6SMax Reitz. ./common.filter
41*911864c6SMax Reitz
42*911864c6SMax Reitz# Basically all formats, but "raw" has issues with _filter_imgfmt regarding the
43*911864c6SMax Reitz# raw comparison image for blkverify; also, all images have to support creation
44*911864c6SMax Reitz_supported_fmt cow qcow qcow2 qed vdi vhdx vmdk vpc
45*911864c6SMax Reitz_supported_proto file
46*911864c6SMax Reitz_supported_os Linux
47*911864c6SMax Reitz
48*911864c6SMax Reitz
49*911864c6SMax Reitzfunction do_run_qemu()
50*911864c6SMax Reitz{
51*911864c6SMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
52*911864c6SMax Reitz}
53*911864c6SMax Reitz
54*911864c6SMax Reitzfunction run_qemu()
55*911864c6SMax Reitz{
56*911864c6SMax Reitz    # Get the "file": "foo" entry ($foo may only contain escaped double quotes,
57*911864c6SMax Reitz    # which is how we can extract it)
58*911864c6SMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \
59*911864c6SMax Reitz        | grep "drv0" \
60*911864c6SMax Reitz        | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g'
61*911864c6SMax Reitz}
62*911864c6SMax Reitz
63*911864c6SMax Reitzfunction test_qemu()
64*911864c6SMax Reitz{
65*911864c6SMax Reitz    run_qemu -drive "if=none,id=drv0,$1" <<EOF
66*911864c6SMax Reitz        { 'execute': 'qmp_capabilities' }
67*911864c6SMax Reitz        { 'execute': 'query-block' }
68*911864c6SMax Reitz        { 'execute': 'quit' }
69*911864c6SMax ReitzEOF
70*911864c6SMax Reitz}
71*911864c6SMax Reitz
72*911864c6SMax Reitz
73*911864c6SMax Reitz
74*911864c6SMax ReitzIMG_SIZE=128K
75*911864c6SMax Reitz
76*911864c6SMax Reitz_make_test_img $IMG_SIZE
77*911864c6SMax Reitz$QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \
78*911864c6SMax Reitz    | _filter_testdir | _filter_imgfmt
79*911864c6SMax Reitz
80*911864c6SMax Reitzecho
81*911864c6SMax Reitzecho '=== Testing simple filename for blkverify ==='
82*911864c6SMax Reitzecho
83*911864c6SMax Reitz
84*911864c6SMax Reitz# This should return simply the filename itself
85*911864c6SMax Reitztest_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG"
86*911864c6SMax Reitz
87*911864c6SMax Reitzecho
88*911864c6SMax Reitzecho '=== Testing filename reconstruction for blkverify ==='
89*911864c6SMax Reitzecho
90*911864c6SMax Reitz
91*911864c6SMax Reitz# This should return the same filename as above
92*911864c6SMax Reitztest_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG"
93*911864c6SMax Reitz
94*911864c6SMax Reitzecho
95*911864c6SMax Reitzecho '=== Testing JSON filename for blkdebug ==='
96*911864c6SMax Reitzecho
97*911864c6SMax Reitz
98*911864c6SMax Reitz# blkdebug cannot create a configuration file, therefore it is unable to
99*911864c6SMax Reitz# generate a plain filename here; thus this should return a JSON filename
100*911864c6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update"
101*911864c6SMax Reitz
102*911864c6SMax Reitzecho
103*911864c6SMax Reitzecho '=== Testing indirectly enforced JSON filename ==='
104*911864c6SMax Reitzecho
105*911864c6SMax Reitz
106*911864c6SMax Reitz# Because blkdebug cannot return a plain filename, blkverify is forced to
107*911864c6SMax Reitz# generate a JSON object here as well
108*911864c6SMax 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"
109*911864c6SMax Reitz
110*911864c6SMax Reitz
111*911864c6SMax Reitzrm -f "$TEST_IMG.compare"
112*911864c6SMax Reitz
113*911864c6SMax Reitz# success, all done
114*911864c6SMax Reitzecho "*** done"
115*911864c6SMax Reitzrm -f $seq.full
116*911864c6SMax Reitzstatus=0
117