xref: /openbmc/qemu/tests/qemu-iotests/099 (revision 68894b5fed671d49587209697f2224b4e857fd1a)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick
3911864c6SMax Reitz#
4911864c6SMax Reitz# Test valid filenames for blkdebug and blkverify representatively for
5911864c6SMax Reitz# other protocols (such as NBD) when queried
6911864c6SMax Reitz#
7911864c6SMax Reitz# Copyright (C) 2014 Red Hat, Inc.
8911864c6SMax Reitz#
9911864c6SMax Reitz# This program is free software; you can redistribute it and/or modify
10911864c6SMax Reitz# it under the terms of the GNU General Public License as published by
11911864c6SMax Reitz# the Free Software Foundation; either version 2 of the License, or
12911864c6SMax Reitz# (at your option) any later version.
13911864c6SMax Reitz#
14911864c6SMax Reitz# This program is distributed in the hope that it will be useful,
15911864c6SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
16911864c6SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17911864c6SMax Reitz# GNU General Public License for more details.
18911864c6SMax Reitz#
19911864c6SMax Reitz# You should have received a copy of the GNU General Public License
20911864c6SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21911864c6SMax Reitz#
22911864c6SMax Reitz
23911864c6SMax Reitz# creator
24*42a5009dSJohn Snowowner=hreitz@redhat.com
25911864c6SMax Reitz
26911864c6SMax Reitzseq="$(basename $0)"
27911864c6SMax Reitzecho "QA output created by $seq"
28911864c6SMax Reitz
29911864c6SMax Reitzstatus=1	# failure is the default!
30911864c6SMax Reitz
31911864c6SMax Reitz_cleanup()
32911864c6SMax Reitz{
33911864c6SMax Reitz    _cleanup_test_img
34f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.compare"
35f91ecbd7SMax Reitz    rm -f "$TEST_DIR/blkdebug.conf"
36f91ecbd7SMax Reitz
37911864c6SMax Reitz}
38911864c6SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
39911864c6SMax Reitz
40911864c6SMax Reitz# get standard environment, filters and checks
41911864c6SMax Reitz. ./common.rc
42911864c6SMax Reitz. ./common.filter
43911864c6SMax Reitz
44911864c6SMax Reitz# Basically all formats, but "raw" has issues with _filter_imgfmt regarding the
45911864c6SMax Reitz# raw comparison image for blkverify; also, all images have to support creation
46550830f9SStefan Hajnoczi_supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc
47911864c6SMax Reitz_supported_proto file
48911864c6SMax Reitz_supported_os Linux
4921b43d00SThomas Huth_require_drivers blkdebug blkverify
503be2024aSMax Reitz# data_file would change the json:{} filenames
510fc9b0d1SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
523be2024aSMax Reitz    "subformat=twoGbMaxExtentSparse" data_file
53911864c6SMax Reitz
548cedcffdSEric Blakedo_run_qemu()
55911864c6SMax Reitz{
56911864c6SMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
57911864c6SMax Reitz}
58911864c6SMax Reitz
598cedcffdSEric Blakerun_qemu()
60911864c6SMax Reitz{
61911864c6SMax Reitz    # Get the "file": "foo" entry ($foo may only contain escaped double quotes,
62911864c6SMax Reitz    # which is how we can extract it)
63911864c6SMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \
644dd7b8d3SMax Reitz        | _filter_qemu | grep "drv0" \
65911864c6SMax Reitz        | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g'
66911864c6SMax Reitz}
67911864c6SMax Reitz
688cedcffdSEric Blaketest_qemu()
69911864c6SMax Reitz{
70911864c6SMax Reitz    run_qemu -drive "if=none,id=drv0,$1" <<EOF
71911864c6SMax Reitz        { 'execute': 'qmp_capabilities' }
72911864c6SMax Reitz        { 'execute': 'query-block' }
73911864c6SMax Reitz        { 'execute': 'quit' }
74911864c6SMax ReitzEOF
75911864c6SMax Reitz}
76911864c6SMax Reitz
77911864c6SMax Reitz
78911864c6SMax Reitz
79911864c6SMax ReitzIMG_SIZE=128K
80911864c6SMax Reitz
81911864c6SMax Reitz_make_test_img $IMG_SIZE
82911864c6SMax Reitz$QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \
83911864c6SMax Reitz    | _filter_testdir | _filter_imgfmt
84911864c6SMax Reitz
85911864c6SMax Reitzecho
86911864c6SMax Reitzecho '=== Testing simple filename for blkverify ==='
87911864c6SMax Reitzecho
88911864c6SMax Reitz
89911864c6SMax Reitz# This should return simply the filename itself
90911864c6SMax Reitztest_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG"
91911864c6SMax Reitz
92911864c6SMax Reitzecho
93911864c6SMax Reitzecho '=== Testing filename reconstruction for blkverify ==='
94911864c6SMax Reitzecho
95911864c6SMax Reitz
96911864c6SMax Reitz# This should return the same filename as above
97911864c6SMax Reitztest_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG"
98911864c6SMax Reitz
99911864c6SMax Reitzecho
100911864c6SMax Reitzecho '=== Testing JSON filename for blkdebug ==='
101911864c6SMax Reitzecho
102911864c6SMax Reitz
103911864c6SMax Reitz# blkdebug cannot create a configuration file, therefore it is unable to
104911864c6SMax Reitz# generate a plain filename here; thus this should return a JSON filename
105911864c6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update"
106911864c6SMax Reitz
107911864c6SMax Reitzecho
108911864c6SMax Reitzecho '=== Testing indirectly enforced JSON filename ==='
109911864c6SMax Reitzecho
110911864c6SMax Reitz
111911864c6SMax Reitz# Because blkdebug cannot return a plain filename, blkverify is forced to
112911864c6SMax Reitz# generate a JSON object here as well
113911864c6SMax 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"
114911864c6SMax Reitz
115f48a33b6SMax Reitzecho
116f48a33b6SMax Reitzecho '=== Testing plain filename for blkdebug ==='
117f48a33b6SMax Reitzecho
118911864c6SMax Reitz
119f48a33b6SMax Reitztouch "$TEST_DIR/blkdebug.conf"
120f48a33b6SMax Reitztest_qemu "file.driver=blkdebug,file.config=$TEST_DIR/blkdebug.conf,file.image.filename=$TEST_IMG"
121f48a33b6SMax Reitz
122f48a33b6SMax Reitzecho
123f48a33b6SMax Reitzecho '=== Testing plain filename for blkdebug without configuration file ==='
124f48a33b6SMax Reitzecho
125f48a33b6SMax Reitz
126f48a33b6SMax Reitztest_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG"
127f48a33b6SMax Reitz
128f48a33b6SMax Reitz
129911864c6SMax Reitz# success, all done
130911864c6SMax Reitzecho "*** done"
131911864c6SMax Reitzrm -f $seq.full
132911864c6SMax Reitzstatus=0
133