xref: /openbmc/qemu/tests/qemu-iotests/099 (revision 11a82d14293cd66f428f535741717ff338c0722b)
1*11a82d14SPhilippe 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
33911864c6SMax Reitz}
34911864c6SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
35911864c6SMax Reitz
36911864c6SMax Reitz# get standard environment, filters and checks
37911864c6SMax Reitz. ./common.rc
38911864c6SMax Reitz. ./common.filter
39911864c6SMax Reitz
40911864c6SMax Reitz# Basically all formats, but "raw" has issues with _filter_imgfmt regarding the
41911864c6SMax Reitz# raw comparison image for blkverify; also, all images have to support creation
42550830f9SStefan Hajnoczi_supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc
43911864c6SMax Reitz_supported_proto file
44911864c6SMax Reitz_supported_os Linux
450fc9b0d1SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
460fc9b0d1SFam Zheng    "subformat=twoGbMaxExtentSparse"
47911864c6SMax Reitz
488cedcffdSEric Blakedo_run_qemu()
49911864c6SMax Reitz{
50911864c6SMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
51911864c6SMax Reitz}
52911864c6SMax Reitz
538cedcffdSEric Blakerun_qemu()
54911864c6SMax Reitz{
55911864c6SMax Reitz    # Get the "file": "foo" entry ($foo may only contain escaped double quotes,
56911864c6SMax Reitz    # which is how we can extract it)
57911864c6SMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \
584dd7b8d3SMax Reitz        | _filter_qemu | grep "drv0" \
59911864c6SMax Reitz        | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g'
60911864c6SMax Reitz}
61911864c6SMax Reitz
628cedcffdSEric Blaketest_qemu()
63911864c6SMax Reitz{
64911864c6SMax Reitz    run_qemu -drive "if=none,id=drv0,$1" <<EOF
65911864c6SMax Reitz        { 'execute': 'qmp_capabilities' }
66911864c6SMax Reitz        { 'execute': 'query-block' }
67911864c6SMax Reitz        { 'execute': 'quit' }
68911864c6SMax ReitzEOF
69911864c6SMax Reitz}
70911864c6SMax Reitz
71911864c6SMax Reitz
72911864c6SMax Reitz
73911864c6SMax ReitzIMG_SIZE=128K
74911864c6SMax Reitz
75911864c6SMax Reitz_make_test_img $IMG_SIZE
76911864c6SMax Reitz$QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \
77911864c6SMax Reitz    | _filter_testdir | _filter_imgfmt
78911864c6SMax Reitz
79911864c6SMax Reitzecho
80911864c6SMax Reitzecho '=== Testing simple filename for blkverify ==='
81911864c6SMax Reitzecho
82911864c6SMax Reitz
83911864c6SMax Reitz# This should return simply the filename itself
84911864c6SMax Reitztest_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG"
85911864c6SMax Reitz
86911864c6SMax Reitzecho
87911864c6SMax Reitzecho '=== Testing filename reconstruction for blkverify ==='
88911864c6SMax Reitzecho
89911864c6SMax Reitz
90911864c6SMax Reitz# This should return the same filename as above
91911864c6SMax Reitztest_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG"
92911864c6SMax Reitz
93911864c6SMax Reitzecho
94911864c6SMax Reitzecho '=== Testing JSON filename for blkdebug ==='
95911864c6SMax Reitzecho
96911864c6SMax Reitz
97911864c6SMax Reitz# blkdebug cannot create a configuration file, therefore it is unable to
98911864c6SMax Reitz# generate a plain filename here; thus this should return a JSON filename
99911864c6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update"
100911864c6SMax Reitz
101911864c6SMax Reitzecho
102911864c6SMax Reitzecho '=== Testing indirectly enforced JSON filename ==='
103911864c6SMax Reitzecho
104911864c6SMax Reitz
105911864c6SMax Reitz# Because blkdebug cannot return a plain filename, blkverify is forced to
106911864c6SMax Reitz# generate a JSON object here as well
107911864c6SMax 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"
108911864c6SMax Reitz
109f48a33b6SMax Reitzecho
110f48a33b6SMax Reitzecho '=== Testing plain filename for blkdebug ==='
111f48a33b6SMax Reitzecho
112911864c6SMax Reitz
113f48a33b6SMax Reitztouch "$TEST_DIR/blkdebug.conf"
114f48a33b6SMax Reitztest_qemu "file.driver=blkdebug,file.config=$TEST_DIR/blkdebug.conf,file.image.filename=$TEST_IMG"
115f48a33b6SMax Reitz
116f48a33b6SMax Reitzecho
117f48a33b6SMax Reitzecho '=== Testing plain filename for blkdebug without configuration file ==='
118f48a33b6SMax Reitzecho
119f48a33b6SMax Reitz
120f48a33b6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG"
121f48a33b6SMax Reitz
122f48a33b6SMax Reitz
123f48a33b6SMax Reitzrm -f "$TEST_IMG.compare" "$TEST_DIR/blkdebug.conf"
124911864c6SMax Reitz
125911864c6SMax Reitz# success, all done
126911864c6SMax Reitzecho "*** done"
127911864c6SMax Reitzrm -f $seq.full
128911864c6SMax Reitzstatus=0
129