1*4ad30336SMax Reitz#!/bin/bash 2*4ad30336SMax Reitz# 3*4ad30336SMax Reitz# Test case for support of JSON filenames 4*4ad30336SMax Reitz# 5*4ad30336SMax Reitz# Copyright (C) 2014 Red Hat, Inc. 6*4ad30336SMax Reitz# 7*4ad30336SMax Reitz# This program is free software; you can redistribute it and/or modify 8*4ad30336SMax Reitz# it under the terms of the GNU General Public License as published by 9*4ad30336SMax Reitz# the Free Software Foundation; either version 2 of the License, or 10*4ad30336SMax Reitz# (at your option) any later version. 11*4ad30336SMax Reitz# 12*4ad30336SMax Reitz# This program is distributed in the hope that it will be useful, 13*4ad30336SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*4ad30336SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*4ad30336SMax Reitz# GNU General Public License for more details. 16*4ad30336SMax Reitz# 17*4ad30336SMax Reitz# You should have received a copy of the GNU General Public License 18*4ad30336SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*4ad30336SMax Reitz# 20*4ad30336SMax Reitz 21*4ad30336SMax Reitz# creator 22*4ad30336SMax Reitzowner=mreitz@redhat.com 23*4ad30336SMax Reitz 24*4ad30336SMax Reitzseq="$(basename $0)" 25*4ad30336SMax Reitzecho "QA output created by $seq" 26*4ad30336SMax Reitz 27*4ad30336SMax Reitzhere="$PWD" 28*4ad30336SMax Reitztmp=/tmp/$$ 29*4ad30336SMax Reitzstatus=1 # failure is the default! 30*4ad30336SMax Reitz 31*4ad30336SMax Reitz_cleanup() 32*4ad30336SMax Reitz{ 33*4ad30336SMax Reitz _cleanup_test_img 34*4ad30336SMax Reitz} 35*4ad30336SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 36*4ad30336SMax Reitz 37*4ad30336SMax Reitz# get standard environment, filters and checks 38*4ad30336SMax Reitz. ./common.rc 39*4ad30336SMax Reitz. ./common.filter 40*4ad30336SMax Reitz 41*4ad30336SMax Reitz_supported_fmt qcow2 42*4ad30336SMax Reitz_supported_proto file 43*4ad30336SMax Reitz_supported_os Linux 44*4ad30336SMax Reitz 45*4ad30336SMax Reitz# Using an image filename containing quotation marks will render the JSON data 46*4ad30336SMax Reitz# below invalid. In that case, we have little choice but simply not to run this 47*4ad30336SMax Reitz# test. 48*4ad30336SMax Reitzcase $TEST_IMG in 49*4ad30336SMax Reitz *'"'*) 50*4ad30336SMax Reitz _notrun "image filename may not contain quotation marks" 51*4ad30336SMax Reitz ;; 52*4ad30336SMax Reitzesac 53*4ad30336SMax Reitz 54*4ad30336SMax ReitzIMG_SIZE=64M 55*4ad30336SMax Reitz 56*4ad30336SMax Reitz# Taken from test 072 57*4ad30336SMax Reitzecho 58*4ad30336SMax Reitzecho "=== Testing nested image formats ===" 59*4ad30336SMax Reitzecho 60*4ad30336SMax Reitz 61*4ad30336SMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE 62*4ad30336SMax Reitz 63*4ad30336SMax Reitz$QEMU_IO -c 'write -P 42 0 512' -c 'write -P 23 512 512' \ 64*4ad30336SMax Reitz -c 'write -P 66 1024 512' "$TEST_IMG.base" | _filter_qemu_io 65*4ad30336SMax Reitz 66*4ad30336SMax Reitz$QEMU_IMG convert -f raw -O $IMGFMT "$TEST_IMG.base" "$TEST_IMG" 67*4ad30336SMax Reitz 68*4ad30336SMax Reitz$QEMU_IO -c 'read -P 42 0 512' -c 'read -P 23 512 512' \ 69*4ad30336SMax Reitz -c 'read -P 66 1024 512' "json:{ 70*4ad30336SMax Reitz \"driver\": \"$IMGFMT\", 71*4ad30336SMax Reitz \"file\": { 72*4ad30336SMax Reitz \"driver\": \"$IMGFMT\", 73*4ad30336SMax Reitz \"file\": { 74*4ad30336SMax Reitz \"filename\": \"$TEST_IMG\" 75*4ad30336SMax Reitz } 76*4ad30336SMax Reitz } 77*4ad30336SMax Reitz}" | _filter_qemu_io 78*4ad30336SMax Reitz 79*4ad30336SMax Reitz# This should fail (see test 072) 80*4ad30336SMax Reitz$QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io 81*4ad30336SMax Reitz 82*4ad30336SMax Reitz 83*4ad30336SMax Reitz# Taken from test 071 84*4ad30336SMax Reitzecho 85*4ad30336SMax Reitzecho "=== Testing blkdebug ===" 86*4ad30336SMax Reitzecho 87*4ad30336SMax Reitz 88*4ad30336SMax Reitz_make_test_img $IMG_SIZE 89*4ad30336SMax Reitz 90*4ad30336SMax Reitz$QEMU_IO -c 'write -P 42 0x38000 512' "$TEST_IMG" | _filter_qemu_io 91*4ad30336SMax Reitz 92*4ad30336SMax Reitz# The "image.filename" part tests whether "a": { "b": "c" } and "a.b": "c" do 93*4ad30336SMax Reitz# the same (which they should). 94*4ad30336SMax Reitz$QEMU_IO -c 'read -P 42 0x38000 512' "json:{ 95*4ad30336SMax Reitz \"driver\": \"$IMGFMT\", 96*4ad30336SMax Reitz \"file\": { 97*4ad30336SMax Reitz \"driver\": \"blkdebug\", 98*4ad30336SMax Reitz \"inject-error\": [{ 99*4ad30336SMax Reitz \"event\": \"l2_load\" 100*4ad30336SMax Reitz }], 101*4ad30336SMax Reitz \"image.filename\": \"$TEST_IMG\" 102*4ad30336SMax Reitz } 103*4ad30336SMax Reitz}" | _filter_qemu_io 104*4ad30336SMax Reitz 105*4ad30336SMax Reitz 106*4ad30336SMax Reitzecho 107*4ad30336SMax Reitzecho "=== Testing qemu-img info output ===" 108*4ad30336SMax Reitzecho 109*4ad30336SMax Reitz 110*4ad30336SMax Reitz$QEMU_IMG info "json:{\"driver\":\"qcow2\",\"file.filename\":\"$TEST_IMG\"}" \ 111*4ad30336SMax Reitz | _filter_testdir | _filter_imgfmt 112*4ad30336SMax Reitz 113*4ad30336SMax Reitz 114*4ad30336SMax Reitzecho 115*4ad30336SMax Reitzecho "=== Testing option merging ===" 116*4ad30336SMax Reitzecho 117*4ad30336SMax Reitz 118*4ad30336SMax Reitz# Both options given directly and those given in the filename should be used 119*4ad30336SMax Reitz$QEMU_IO -c "open -o driver=qcow2 json:{\"file.filename\":\"$TEST_IMG\"}" \ 120*4ad30336SMax Reitz -c "info" 2>&1 | _filter_testdir | _filter_imgfmt 121*4ad30336SMax Reitz 122*4ad30336SMax Reitz# Options given directly should be prioritized over those given in the filename 123*4ad30336SMax Reitz$QEMU_IO -c "open -o driver=qcow2 json:{\"driver\":\"raw\",\"file.filename\":\"$TEST_IMG\"}" \ 124*4ad30336SMax Reitz -c "info" 2>&1 | _filter_testdir | _filter_imgfmt 125*4ad30336SMax Reitz 126*4ad30336SMax Reitz 127*4ad30336SMax Reitz# success, all done 128*4ad30336SMax Reitzecho "*** done" 129*4ad30336SMax Reitzrm -f $seq.full 130*4ad30336SMax Reitzstatus=0 131