1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2ca6cbb65SFam Zheng# 3ca6cbb65SFam Zheng# Test case for vmdk 4ca6cbb65SFam Zheng# 5ca6cbb65SFam Zheng# Copyright (C) 2013 Red Hat, Inc. 6ca6cbb65SFam Zheng# 7ca6cbb65SFam Zheng# This program is free software; you can redistribute it and/or modify 8ca6cbb65SFam Zheng# it under the terms of the GNU General Public License as published by 9ca6cbb65SFam Zheng# the Free Software Foundation; either version 2 of the License, or 10ca6cbb65SFam Zheng# (at your option) any later version. 11ca6cbb65SFam Zheng# 12ca6cbb65SFam Zheng# This program is distributed in the hope that it will be useful, 13ca6cbb65SFam Zheng# but WITHOUT ANY WARRANTY; without even the implied warranty of 14ca6cbb65SFam Zheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15ca6cbb65SFam Zheng# GNU General Public License for more details. 16ca6cbb65SFam Zheng# 17ca6cbb65SFam Zheng# You should have received a copy of the GNU General Public License 18ca6cbb65SFam Zheng# along with this program. If not, see <http://www.gnu.org/licenses/>. 19ca6cbb65SFam Zheng# 20ca6cbb65SFam Zheng 21ca6cbb65SFam Zheng# creator 22ca6cbb65SFam Zhengowner=famz@redhat.com 23ca6cbb65SFam Zheng 24ca6cbb65SFam Zhengseq=`basename $0` 25ca6cbb65SFam Zhengecho "QA output created by $seq" 26ca6cbb65SFam Zheng 27ca6cbb65SFam Zhengstatus=1 # failure is the default! 28ca6cbb65SFam Zheng 29ca6cbb65SFam Zheng_cleanup() 30ca6cbb65SFam Zheng{ 31ca6cbb65SFam Zheng _cleanup_test_img 3259fa68f3SKevin Wolf rm -f "$TEST_IMG.qcow2" 33ca6cbb65SFam Zheng} 34ca6cbb65SFam Zhengtrap "_cleanup; exit \$status" 0 1 2 3 15 35ca6cbb65SFam Zheng 36ca6cbb65SFam Zheng# get standard environment, filters and checks 37ca6cbb65SFam Zheng. ./common.rc 38ca6cbb65SFam Zheng. ./common.filter 39ca6cbb65SFam Zheng 40ca6cbb65SFam Zheng# This tests vmdk-specific low-level functionality 41ca6cbb65SFam Zheng_supported_fmt vmdk 421f7bf7d0SPeter Lieven_supported_proto file 43ca6cbb65SFam Zheng_supported_os Linux 44d2329f27SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" \ 45d2329f27SFam Zheng "subformat=twoGbMaxExtentFlat" \ 46d2329f27SFam Zheng "subformat=twoGbMaxExtentSparse" 47ca6cbb65SFam Zheng 482c43e43cSFam Zhengcapacity_offset=16 498aa1331cSFam Zhenggranularity_offset=20 50f8ce0403SFam Zhenggrain_table_size_offset=44 518aa1331cSFam Zheng 528aa1331cSFam Zhengecho 535dd75f9aSFam Zhengecho "=== Testing invalid granularity ===" 548aa1331cSFam Zheng_make_test_img 64M 558aa1331cSFam Zhengpoke_file "$TEST_IMG" "$granularity_offset" "\xff\xff\xff\xff\xff\xff\xff\xff" 56fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir 57ca6cbb65SFam Zheng 58f8ce0403SFam Zhengecho 595dd75f9aSFam Zhengecho "=== Testing too big L2 table size ===" 60f8ce0403SFam Zheng_make_test_img 64M 61f8ce0403SFam Zhengpoke_file "$TEST_IMG" "$grain_table_size_offset" "\xff\xff\xff\xff" 62fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir 63f8ce0403SFam Zheng 642c43e43cSFam Zhengecho 655dd75f9aSFam Zhengecho "=== Testing too big L1 table size ===" 662c43e43cSFam Zheng_make_test_img 64M 672c43e43cSFam Zhengpoke_file "$TEST_IMG" "$capacity_offset" "\xff\xff\xff\xff" 682c43e43cSFam Zhengpoke_file "$TEST_IMG" "$grain_table_size_offset" "\x01\x00\x00\x00" 69fef9c191SJeff Cody{ $QEMU_IO -c "read 0 512" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir 702c43e43cSFam Zheng 712fe2e290SFam Zhengecho 725dd75f9aSFam Zhengecho "=== Testing monolithicFlat creation and opening ===" 732fe2e290SFam ZhengIMGOPTS="subformat=monolithicFlat" _make_test_img 2G 74f4c129a3SFam Zheng_img_info 7559fa68f3SKevin Wolf_cleanup_test_img 762fe2e290SFam Zheng 7752c8d629SFam Zhengecho 7852c8d629SFam Zhengecho "=== Testing monolithicFlat with zeroed_grain ===" 7952c8d629SFam ZhengIMGOPTS="subformat=monolithicFlat,zeroed_grain=on" _make_test_img 2G 8059fa68f3SKevin Wolf_cleanup_test_img 8152c8d629SFam Zheng 82981cbf59SFam Zhengecho 83af057fe7SFam Zhengecho "=== Testing big twoGbMaxExtentFlat ===" 84af057fe7SFam ZhengIMGOPTS="subformat=twoGbMaxExtentFlat" _make_test_img 1000G 85af057fe7SFam Zheng$QEMU_IMG info $TEST_IMG | _filter_testdir | sed -e 's/cid: [0-9]*/cid: XXXXXXXX/' 8659fa68f3SKevin Wolf_cleanup_test_img 87af057fe7SFam Zheng 88af057fe7SFam Zhengecho 89b47053bdSFam Zhengecho "=== Testing malformed VMFS extent description line ===" 90b47053bdSFam Zhengcat >"$TEST_IMG" <<EOF 91b47053bdSFam Zheng# Disk DescriptorFile 92b47053bdSFam Zhengversion=1 93b47053bdSFam ZhengCID=58ab4847 94b47053bdSFam ZhengparentCID=ffffffff 95b47053bdSFam ZhengcreateType="vmfs" 96b47053bdSFam Zheng 97b47053bdSFam Zheng# Extent description 98b47053bdSFam ZhengRW 12582912 VMFS "dummy.vmdk" 1 99b47053bdSFam ZhengEOF 100b47053bdSFam Zheng_img_info 101b47053bdSFam Zheng 102b47053bdSFam Zhengecho 10334ceed81SFam Zhengecho "=== Testing truncated sparse ===" 10434ceed81SFam ZhengIMGOPTS="subformat=monolithicSparse" _make_test_img 100G 10534ceed81SFam Zhengtruncate -s 10M $TEST_IMG 10634ceed81SFam Zheng_img_info 10734ceed81SFam Zheng 10834ceed81SFam Zhengecho 10910f08a0aSFam Zhengecho "=== Converting to streamOptimized from image with small cluster size===" 11010f08a0aSFam ZhengTEST_IMG="$TEST_IMG.qcow2" IMGFMT=qcow2 IMGOPTS="cluster_size=4096" _make_test_img 1G 111b89689f5SMax Reitz$QEMU_IO -f qcow2 -c "write -P 0xa 0 512" "$TEST_IMG.qcow2" | _filter_qemu_io 112b89689f5SMax Reitz$QEMU_IO -f qcow2 -c "write -P 0xb 10240 512" "$TEST_IMG.qcow2" | _filter_qemu_io 11310f08a0aSFam Zheng$QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2" "$TEST_IMG" 2>&1 11410f08a0aSFam Zheng 11510f08a0aSFam Zhengecho 116942764ccSMax Reitzecho "=== Testing monolithicFlat with internally generated JSON file name ===" 117942764ccSMax ReitzIMGOPTS="subformat=monolithicFlat" _make_test_img 64M 118942764ccSMax Reitz$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" 2>&1 \ 119942764ccSMax Reitz | _filter_testdir | _filter_imgfmt 12059fa68f3SKevin Wolf_cleanup_test_img 121942764ccSMax Reitz 122942764ccSMax Reitzecho 123981cbf59SFam Zhengecho "=== Testing version 3 ===" 124981cbf59SFam Zheng_use_sample_img iotest-version3.vmdk.bz2 125981cbf59SFam Zheng_img_info 126a8d8a1a0SFam Zhengfor i in {0..99}; do 127a8d8a1a0SFam Zheng $QEMU_IO -r -c "read -P $(( i % 10 + 0x30 )) $(( i * 64 * 1024 * 10 + i * 512 )) 512" $TEST_IMG \ 128a8d8a1a0SFam Zheng | _filter_qemu_io 129a8d8a1a0SFam Zhengdone 13059fa68f3SKevin Wolf_cleanup_test_img 131981cbf59SFam Zheng 132585ea0c8SFam Zhengecho 133585ea0c8SFam Zhengecho "=== Testing 4TB monolithicFlat creation and IO ===" 134585ea0c8SFam ZhengIMGOPTS="subformat=monolithicFlat" _make_test_img 4T 135585ea0c8SFam Zheng_img_info 136585ea0c8SFam Zheng$QEMU_IO -c "write -P 0xa 900G 512" "$TEST_IMG" | _filter_qemu_io 137585ea0c8SFam Zheng$QEMU_IO -c "read -v 900G 1024" "$TEST_IMG" | _filter_qemu_io 13859fa68f3SKevin Wolf_cleanup_test_img 139585ea0c8SFam Zheng 140b93bbf4eSFam Zhengecho 141c7fc50d3SFam Zhengecho "=== Testing qemu-img map on extents ===" 142c7fc50d3SFam Zhengfor fmt in monolithicSparse twoGbMaxExtentSparse; do 143c7fc50d3SFam Zheng IMGOPTS="subformat=$fmt" _make_test_img 31G 144c7fc50d3SFam Zheng $QEMU_IO -c "write 65024 1k" "$TEST_IMG" | _filter_qemu_io 145c7fc50d3SFam Zheng $QEMU_IO -c "write 2147483136 1k" "$TEST_IMG" | _filter_qemu_io 146c7fc50d3SFam Zheng $QEMU_IO -c "write 5G 1k" "$TEST_IMG" | _filter_qemu_io 147c7fc50d3SFam Zheng $QEMU_IMG map "$TEST_IMG" | _filter_testdir 14859fa68f3SKevin Wolf _cleanup_test_img 149c7fc50d3SFam Zhengdone 150c7fc50d3SFam Zheng 151c7fc50d3SFam Zhengecho 152b93bbf4eSFam Zhengecho "=== Testing afl image with a very large capacity ===" 153b93bbf4eSFam Zheng_use_sample_img afl9.vmdk.bz2 1540bfed484SFam Zheng_img_info | grep -q 'Cannot allocate memory' && _notrun "Insufficent memory, skipped test" 1550bfed484SFam Zheng_img_info 15659fa68f3SKevin Wolf_cleanup_test_img 157b93bbf4eSFam Zheng 158ca6cbb65SFam Zheng# success, all done 159ca6cbb65SFam Zhengecho "*** done" 160ca6cbb65SFam Zhengrm -f $seq.full 161ca6cbb65SFam Zhengstatus=0 162