xref: /openbmc/qemu/tests/qemu-iotests/089 (revision 9dd003a9)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick
34ad30336SMax Reitz#
44ad30336SMax Reitz# Test case for support of JSON filenames
54ad30336SMax Reitz#
64ad30336SMax Reitz# Copyright (C) 2014 Red Hat, Inc.
74ad30336SMax Reitz#
84ad30336SMax Reitz# This program is free software; you can redistribute it and/or modify
94ad30336SMax Reitz# it under the terms of the GNU General Public License as published by
104ad30336SMax Reitz# the Free Software Foundation; either version 2 of the License, or
114ad30336SMax Reitz# (at your option) any later version.
124ad30336SMax Reitz#
134ad30336SMax Reitz# This program is distributed in the hope that it will be useful,
144ad30336SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
154ad30336SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
164ad30336SMax Reitz# GNU General Public License for more details.
174ad30336SMax Reitz#
184ad30336SMax Reitz# You should have received a copy of the GNU General Public License
194ad30336SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
204ad30336SMax Reitz#
214ad30336SMax Reitz
224ad30336SMax Reitz# creator
234ad30336SMax Reitzowner=mreitz@redhat.com
244ad30336SMax Reitz
254ad30336SMax Reitzseq="$(basename $0)"
264ad30336SMax Reitzecho "QA output created by $seq"
274ad30336SMax Reitz
284ad30336SMax Reitzstatus=1	# failure is the default!
294ad30336SMax Reitz
304ad30336SMax Reitz_cleanup()
314ad30336SMax Reitz{
324ad30336SMax Reitz	_cleanup_test_img
334ad30336SMax Reitz}
344ad30336SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
354ad30336SMax Reitz
364ad30336SMax Reitz# get standard environment, filters and checks
374ad30336SMax Reitz. ./common.rc
384ad30336SMax Reitz. ./common.filter
394ad30336SMax Reitz
404ad30336SMax Reitz_supported_fmt qcow2
4157284d2aSMax Reitz_supported_proto file fuse
425262caa7SMax Reitz# Because anything other than 16 would change the output of qemu_io -c info
435262caa7SMax Reitz_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
444ad30336SMax Reitz
454ad30336SMax Reitz# Using an image filename containing quotation marks will render the JSON data
464ad30336SMax Reitz# below invalid. In that case, we have little choice but simply not to run this
474ad30336SMax Reitz# test.
484ad30336SMax Reitzcase $TEST_IMG in
494ad30336SMax Reitz    *'"'*)
504ad30336SMax Reitz        _notrun "image filename may not contain quotation marks"
514ad30336SMax Reitz        ;;
524ad30336SMax Reitzesac
534ad30336SMax Reitz
544ad30336SMax ReitzIMG_SIZE=64M
554ad30336SMax Reitz
564ad30336SMax Reitz# Taken from test 072
574ad30336SMax Reitzecho
584ad30336SMax Reitzecho "=== Testing nested image formats ==="
594ad30336SMax Reitzecho
604ad30336SMax Reitz
614ad30336SMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE
624ad30336SMax Reitz
634ad30336SMax Reitz$QEMU_IO -c 'write -P 42 0 512' -c 'write -P 23 512 512' \
644ad30336SMax Reitz         -c 'write -P 66 1024 512' "$TEST_IMG.base" | _filter_qemu_io
654ad30336SMax Reitz
66620a628dSMax Reitz_make_test_img $IMG_SIZE
67620a628dSMax Reitz$QEMU_IMG convert -f raw -O $IMGFMT -n "$TEST_IMG.base" "$TEST_IMG"
684ad30336SMax Reitz
698dff69b9SAarushi Mehta$QEMU_IO_PROG --cache $CACHEMODE --aio $AIOMODE \
708f9e835fSKevin Wolf         -c 'read -P 42 0 512' -c 'read -P 23 512 512' \
714ad30336SMax Reitz         -c 'read -P 66 1024 512' "json:{
724ad30336SMax Reitz    \"driver\": \"$IMGFMT\",
734ad30336SMax Reitz    \"file\": {
744ad30336SMax Reitz        \"driver\": \"$IMGFMT\",
754ad30336SMax Reitz        \"file\": {
764ad30336SMax Reitz            \"filename\": \"$TEST_IMG\"
774ad30336SMax Reitz        }
784ad30336SMax Reitz    }
794ad30336SMax Reitz}" | _filter_qemu_io
804ad30336SMax Reitz
814ad30336SMax Reitz# This should fail (see test 072)
824ad30336SMax Reitz$QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
834ad30336SMax Reitz
844ad30336SMax Reitz
85e59a0cf1SMax Reitzecho
86e59a0cf1SMax Reitzecho "=== Testing correct handling of 'backing':null ==="
87e59a0cf1SMax Reitzecho
88e59a0cf1SMax Reitz
89b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $IMG_SIZE
90e59a0cf1SMax Reitz
91e59a0cf1SMax Reitz# This should read 42
92e59a0cf1SMax Reitz$QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
93e59a0cf1SMax Reitz
94e59a0cf1SMax Reitz# This should read 0
95e59a0cf1SMax Reitz$QEMU_IO -c 'read -P 0 0 512' "json:{\
96e59a0cf1SMax Reitz    'driver': '$IMGFMT',
97e59a0cf1SMax Reitz    'file': {
98e59a0cf1SMax Reitz        'driver': 'file',
99e59a0cf1SMax Reitz        'filename': '$TEST_IMG'
100e59a0cf1SMax Reitz    },
101e59a0cf1SMax Reitz    'backing': null
102e59a0cf1SMax Reitz}" | _filter_qemu_io
103e59a0cf1SMax Reitz
104e59a0cf1SMax Reitz
1054ad30336SMax Reitz# Taken from test 071
1064ad30336SMax Reitzecho
1074ad30336SMax Reitzecho "=== Testing blkdebug ==="
1084ad30336SMax Reitzecho
1094ad30336SMax Reitz
1104ad30336SMax Reitz_make_test_img $IMG_SIZE
1114ad30336SMax Reitz
1124ad30336SMax Reitz$QEMU_IO -c 'write -P 42 0x38000 512' "$TEST_IMG" | _filter_qemu_io
1134ad30336SMax Reitz
1144ad30336SMax Reitz# The "image.filename" part tests whether "a": { "b": "c" } and "a.b": "c" do
1154ad30336SMax Reitz# the same (which they should).
1168dff69b9SAarushi Mehta$QEMU_IO_PROG --cache $CACHEMODE --aio $AIOMODE  \
1178f9e835fSKevin Wolf     -c 'read -P 42 0x38000 512' "json:{
1184ad30336SMax Reitz    \"driver\": \"$IMGFMT\",
1194ad30336SMax Reitz    \"file\": {
1204ad30336SMax Reitz        \"driver\": \"blkdebug\",
1214ad30336SMax Reitz        \"inject-error\": [{
1224ad30336SMax Reitz            \"event\": \"l2_load\"
1234ad30336SMax Reitz        }],
1244ad30336SMax Reitz        \"image.filename\": \"$TEST_IMG\"
1254ad30336SMax Reitz    }
1264ad30336SMax Reitz}" | _filter_qemu_io
1274ad30336SMax Reitz
1284ad30336SMax Reitz
1294ad30336SMax Reitzecho
1304ad30336SMax Reitzecho "=== Testing qemu-img info output ==="
1314ad30336SMax Reitzecho
1324ad30336SMax Reitz
1330bf7488aSMax ReitzTEST_IMG="json:{\"driver\":\"qcow2\",\"file.filename\":\"$TEST_IMG\"}" _img_info
1344ad30336SMax Reitz
1354ad30336SMax Reitz
1364ad30336SMax Reitzecho
1374ad30336SMax Reitzecho "=== Testing option merging ==="
1384ad30336SMax Reitzecho
1394ad30336SMax Reitz
1404ad30336SMax Reitz# Both options given directly and those given in the filename should be used
1414ad30336SMax Reitz$QEMU_IO -c "open -o driver=qcow2 json:{\"file.filename\":\"$TEST_IMG\"}" \
1429853f5c4SMax Reitz         -c "info" 2>&1 | _filter_img_info
1434ad30336SMax Reitz
1444ad30336SMax Reitz# Options given directly should be prioritized over those given in the filename
1454ad30336SMax Reitz$QEMU_IO -c "open -o driver=qcow2 json:{\"driver\":\"raw\",\"file.filename\":\"$TEST_IMG\"}" \
1469853f5c4SMax Reitz         -c "info" 2>&1 | _filter_img_info
1474ad30336SMax Reitz
1484ad30336SMax Reitz
1494ad30336SMax Reitz# success, all done
1504ad30336SMax Reitzecho "*** done"
1514ad30336SMax Reitzrm -f $seq.full
1524ad30336SMax Reitzstatus=0
153