111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 26f993f3fSNir Soffer# 36f993f3fSNir Soffer# Test creating raw image preallocation mode 46f993f3fSNir Soffer# 56f993f3fSNir Soffer# Copyright (C) 2017 Nir Soffer <nirsof@gmail.com> 66f993f3fSNir Soffer# 76f993f3fSNir Soffer# This program is free software; you can redistribute it and/or modify 86f993f3fSNir Soffer# it under the terms of the GNU General Public License as published by 96f993f3fSNir Soffer# the Free Software Foundation; either version 2 of the License, or 106f993f3fSNir Soffer# (at your option) any later version. 116f993f3fSNir Soffer# 126f993f3fSNir Soffer# This program is distributed in the hope that it will be useful, 136f993f3fSNir Soffer# but WITHOUT ANY WARRANTY; without even the implied warranty of 146f993f3fSNir Soffer# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 156f993f3fSNir Soffer# GNU General Public License for more details. 166f993f3fSNir Soffer# 176f993f3fSNir Soffer# You should have received a copy of the GNU General Public License 186f993f3fSNir Soffer# along with this program. If not, see <http://www.gnu.org/licenses/>. 196f993f3fSNir Soffer# 206f993f3fSNir Soffer 216f993f3fSNir Soffer# creator 226f993f3fSNir Sofferowner=nirsof@gmail.com 236f993f3fSNir Soffer 246f993f3fSNir Sofferseq=`basename $0` 256f993f3fSNir Sofferecho "QA output created by $seq" 266f993f3fSNir Soffer 276f993f3fSNir Sofferstatus=1 # failure is the default! 286f993f3fSNir Soffer 296f993f3fSNir Soffer_cleanup() 306f993f3fSNir Soffer{ 316f993f3fSNir Soffer _cleanup_test_img 32*a3bd71b5SMax Reitz rm -f "$TEST_DIR/empty" 336f993f3fSNir Soffer} 346f993f3fSNir Soffertrap "_cleanup; exit \$status" 0 1 2 3 15 356f993f3fSNir Soffer 36*a3bd71b5SMax Reitz# Some file systems sometimes allocate extra blocks independently of 37*a3bd71b5SMax Reitz# the file size. This function hides the resulting difference in the 38*a3bd71b5SMax Reitz# stat -c '%b' output. 39*a3bd71b5SMax Reitz# Parameter 1: Number of blocks an empty file occupies 40*a3bd71b5SMax Reitz# Parameter 2: Image size in bytes 41*a3bd71b5SMax Reitz_filter_blocks() 42*a3bd71b5SMax Reitz{ 43*a3bd71b5SMax Reitz extra_blocks=$1 44*a3bd71b5SMax Reitz img_size=$2 45*a3bd71b5SMax Reitz 46*a3bd71b5SMax Reitz sed -e "s/blocks=$extra_blocks\\(\$\\|[^0-9]\\)/nothing allocated/" \ 47*a3bd71b5SMax Reitz -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/everything allocated/" 48*a3bd71b5SMax Reitz} 49*a3bd71b5SMax Reitz 506f993f3fSNir Soffer# get standard environment, filters and checks 516f993f3fSNir Soffer. ./common.rc 526f993f3fSNir Soffer. ./common.filter 536f993f3fSNir Soffer 546f993f3fSNir Soffer_supported_fmt raw 556f993f3fSNir Soffer_supported_proto file 566f993f3fSNir Soffer_supported_os Linux 576f993f3fSNir Soffer 58*a3bd71b5SMax Reitzsize=$((1 * 1024 * 1024)) 59*a3bd71b5SMax Reitz 60*a3bd71b5SMax Reitztouch "$TEST_DIR/empty" 61*a3bd71b5SMax Reitzextra_blocks=$(stat -c '%b' "$TEST_DIR/empty") 626f993f3fSNir Soffer 636f993f3fSNir Sofferecho 646f993f3fSNir Sofferecho "== creating image with default preallocation ==" 656f993f3fSNir Soffer_make_test_img $size | _filter_imgfmt 66*a3bd71b5SMax Reitzstat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size 676f993f3fSNir Soffer 686f993f3fSNir Sofferfor mode in off full falloc; do 696f993f3fSNir Soffer echo 706f993f3fSNir Soffer echo "== creating image with preallocation $mode ==" 716f993f3fSNir Soffer IMGOPTS=preallocation=$mode _make_test_img $size | _filter_imgfmt 72*a3bd71b5SMax Reitz stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size 736f993f3fSNir Sofferdone 746f993f3fSNir Soffer 756f993f3fSNir Soffer# success, all done 766f993f3fSNir Sofferecho "*** done" 776f993f3fSNir Sofferrm -f $seq.full 786f993f3fSNir Sofferstatus=0 79