1#!/usr/bin/env bash 2# group: quick 3# 4# qemu-img measure tests for LUKS images 5# 6# Copyright (C) 2020 Red Hat, Inc. 7# 8# This program is free software; you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation; either version 2 of the License, or 11# (at your option) any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program. If not, see <http://www.gnu.org/licenses/>. 20# 21 22# creator 23owner=stefanha@redhat.com 24 25seq=`basename $0` 26echo "QA output created by $seq" 27 28status=1 # failure is the default! 29 30_cleanup() 31{ 32 _cleanup_test_img 33 rm -f "$TEST_IMG.converted" 34} 35trap "_cleanup; exit \$status" 0 1 2 3 15 36 37# get standard environment, filters and checks 38. ./common.rc 39. ./common.filter 40. ./common.pattern 41 42_supported_fmt luks 43_supported_proto file 44_supported_os Linux 45 46SECRET=secret,id=sec0,data=passphrase 47 48echo "== measure 1G image file ==" 49echo 50 51$QEMU_IMG measure --object "$SECRET" \ 52 -O "$IMGFMT" \ 53 -o key-secret=sec0,iter-time=10 \ 54 --size 1G 55 56echo 57echo "== create 1G image file (size should be no greater than measured) ==" 58echo 59 60_make_test_img 1G 61stat -c "image file size in bytes: %s" "$TEST_IMG_FILE" 62 63echo 64echo "== modified 1G image file (size should be no greater than measured) ==" 65echo 66 67$QEMU_IO --object "$SECRET" --image-opts "$TEST_IMG" -c "write -P 0x51 0x10000 0x400" | _filter_qemu_io | _filter_testdir 68stat -c "image file size in bytes: %s" "$TEST_IMG_FILE" 69 70echo 71echo "== measure preallocation=falloc 1G image file ==" 72echo 73 74$QEMU_IMG measure --object "$SECRET" \ 75 -O "$IMGFMT" \ 76 -o key-secret=sec0,iter-time=10,preallocation=falloc \ 77 --size 1G 78 79echo 80echo "== measure with input image file ==" 81echo 82 83IMGFMT=raw IMGKEYSECRET= IMGOPTS= _make_test_img 1G | _filter_imgfmt 84QEMU_IO_OPTIONS= IMGOPTSSYNTAX= $QEMU_IO -f raw -c "write -P 0x51 0x10000 0x400" "$TEST_IMG_FILE" | _filter_qemu_io | _filter_testdir 85$QEMU_IMG measure --object "$SECRET" \ 86 -O "$IMGFMT" \ 87 -o key-secret=sec0,iter-time=10 \ 88 -f raw \ 89 "$TEST_IMG_FILE" 90 91# success, all done 92echo "*** done" 93rm -f $seq.full 94status=0 95