111be35a1SLionel Sambuc 211be35a1SLionel Sambuc# Common settings and functions for the various resize_ffs tests. 311be35a1SLionel Sambuc# 411be35a1SLionel Sambuc 511be35a1SLionel Sambuc# called from atf_init_test_cases 611be35a1SLionel Sambucsetupvars() 711be35a1SLionel Sambuc{ 811be35a1SLionel Sambuc IMG=fsimage 911be35a1SLionel Sambuc TDBASE64=$(atf_get_srcdir)/testdata.tar.gz.base64 1011be35a1SLionel Sambuc GOODMD5=$(atf_get_srcdir)/testdata.md5 1111be35a1SLionel Sambuc # set BYTESWAP to opposite-endian. 1211be35a1SLionel Sambuc if [ $(sysctl -n hw.byteorder) = "1234" ]; then 1311be35a1SLionel Sambuc BYTESWAP=be 1411be35a1SLionel Sambuc else 1511be35a1SLionel Sambuc BYTESWAP=le 1611be35a1SLionel Sambuc fi 1711be35a1SLionel Sambuc} 1811be35a1SLionel Sambuc 1911be35a1SLionel Sambuc# test_case() taken from the tests/ipf/h_common.sh 2011be35a1SLionel Sambuc# Used to declare the atf goop for a test. 2111be35a1SLionel Sambuctest_case() 2211be35a1SLionel Sambuc{ 2311be35a1SLionel Sambuc local name="${1}"; shift 2411be35a1SLionel Sambuc local check_function="${1}"; shift 2511be35a1SLionel Sambuc 2611be35a1SLionel Sambuc atf_test_case "${name}" cleanup 2711be35a1SLionel Sambuc eval "${name}_head() { \ 2811be35a1SLionel Sambuc atf_set "require.user" "root" ; \ 2911be35a1SLionel Sambuc atf_set "require.progs" "rump_ffs" ; \ 3011be35a1SLionel Sambuc }" 3111be35a1SLionel Sambuc eval "${name}_body() { \ 3211be35a1SLionel Sambuc ${check_function} " "${@}" "; \ 3311be35a1SLionel Sambuc }" 3411be35a1SLionel Sambuc eval "${name}_cleanup() { \ 3511be35a1SLionel Sambuc umount -f mnt ; \ 3611be35a1SLionel Sambuc : reset error ; \ 3711be35a1SLionel Sambuc }" 3811be35a1SLionel Sambuc} 3911be35a1SLionel Sambuc 4011be35a1SLionel Sambuc# Used to declare the atf goop for a test expected to fail. 4111be35a1SLionel Sambuctest_case_xfail() 4211be35a1SLionel Sambuc{ 4311be35a1SLionel Sambuc local name="${1}"; shift 4411be35a1SLionel Sambuc local reason="${1}"; shift 4511be35a1SLionel Sambuc local check_function="${1}"; shift 4611be35a1SLionel Sambuc 4711be35a1SLionel Sambuc atf_test_case "${name}" cleanup 4811be35a1SLionel Sambuc eval "${name}_head() { \ 4911be35a1SLionel Sambuc atf_set "require.user" "root" ; \ 5011be35a1SLionel Sambuc }" 5111be35a1SLionel Sambuc eval "${name}_body() { \ 5211be35a1SLionel Sambuc atf_expect_fail "${reason}" ; \ 5311be35a1SLionel Sambuc ${check_function} " "${@}" "; \ 5411be35a1SLionel Sambuc }" 5511be35a1SLionel Sambuc eval "${name}_cleanup() { \ 5611be35a1SLionel Sambuc umount -f mnt ; \ 5711be35a1SLionel Sambuc : reset error ; \ 5811be35a1SLionel Sambuc }" 5911be35a1SLionel Sambuc} 6011be35a1SLionel Sambuc 6111be35a1SLionel Sambuc# copy_data requires the mount already done; makes one copy of the test data 6211be35a1SLionel Sambuccopy_data () 6311be35a1SLionel Sambuc{ 6411be35a1SLionel Sambuc uudecode -p ${TDBASE64} | (cd mnt; tar xzf - -s/testdata/TD$1/) 6511be35a1SLionel Sambuc} 6611be35a1SLionel Sambuc 6711be35a1SLionel Sambuccopy_multiple () 6811be35a1SLionel Sambuc{ 6911be35a1SLionel Sambuc local i 7011be35a1SLionel Sambuc for i in $(seq $1); do 7111be35a1SLionel Sambuc copy_data $i 7211be35a1SLionel Sambuc done 7311be35a1SLionel Sambuc} 7411be35a1SLionel Sambuc 7511be35a1SLionel Sambuc# remove_data removes one directory worth of test data; the purpose 7611be35a1SLionel Sambuc# is to ensure data exists near the end of the fs under test. 7711be35a1SLionel Sambucremove_data () 7811be35a1SLionel Sambuc{ 7911be35a1SLionel Sambuc rm -rf mnt/TD$1 8011be35a1SLionel Sambuc} 8111be35a1SLionel Sambuc 8211be35a1SLionel Sambucremove_multiple () 8311be35a1SLionel Sambuc{ 8411be35a1SLionel Sambuc local i 8511be35a1SLionel Sambuc for i in $(seq $1); do 8611be35a1SLionel Sambuc remove_data $i 8711be35a1SLionel Sambuc done 8811be35a1SLionel Sambuc} 8911be35a1SLionel Sambuc 9011be35a1SLionel Sambuc# verify that the data in a particular directory is still OK 9111be35a1SLionel Sambuc# generated md5 file doesn't need explicit cleanup thanks to ATF 9211be35a1SLionel Sambuccheck_data () 9311be35a1SLionel Sambuc{ 9411be35a1SLionel Sambuc (cd mnt/TD$1 && md5 *) > TD$1.md5 9511be35a1SLionel Sambuc atf_check diff -u ${GOODMD5} TD$1.md5 9611be35a1SLionel Sambuc} 9711be35a1SLionel Sambuc 9811be35a1SLionel Sambuc# supply begin and end arguments 9911be35a1SLionel Sambuccheck_data_range () 10011be35a1SLionel Sambuc{ 10111be35a1SLionel Sambuc local i 10211be35a1SLionel Sambuc for i in $(seq $1 $2); do 10311be35a1SLionel Sambuc check_data $i 10411be35a1SLionel Sambuc done 10511be35a1SLionel Sambuc} 10611be35a1SLionel Sambuc 10711be35a1SLionel Sambuc 10811be35a1SLionel Sambucresize_ffs() 10911be35a1SLionel Sambuc{ 11011be35a1SLionel Sambuc echo "in resize_ffs:" ${@} 11111be35a1SLionel Sambuc local bs=$1 11211be35a1SLionel Sambuc local fragsz=$2 11311be35a1SLionel Sambuc local osize=$3 11411be35a1SLionel Sambuc local nsize=$4 11511be35a1SLionel Sambuc local fslevel=$5 11611be35a1SLionel Sambuc local numdata=$6 11711be35a1SLionel Sambuc local swap=$7 11811be35a1SLionel Sambuc mkdir -p mnt 11911be35a1SLionel Sambuc echo "bs is ${bs} numdata is ${numdata}" 12011be35a1SLionel Sambuc echo "****resizing fs with blocksize ${bs}" 12111be35a1SLionel Sambuc 12211be35a1SLionel Sambuc # we want no more than 16K/inode to allow test files to copy. 12311be35a1SLionel Sambuc local fpi=$((fragsz * 4)) 12411be35a1SLionel Sambuc local i 12511be35a1SLionel Sambuc if [ $fpi -gt 16384 ]; then 12611be35a1SLionel Sambuc i="-i 16384" 12711be35a1SLionel Sambuc fi 12811be35a1SLionel Sambuc if [ x$swap != x ]; then 12911be35a1SLionel Sambuc newfs -B ${BYTESWAP} -O${fslevel} -b ${bs} -f ${fragsz} \ 13011be35a1SLionel Sambuc -s ${osize} ${i} -F ${IMG} 13111be35a1SLionel Sambuc else 13211be35a1SLionel Sambuc newfs -O${fslevel} -b ${bs} -f ${fragsz} -s ${osize} ${i} \ 13311be35a1SLionel Sambuc -F ${IMG} 13411be35a1SLionel Sambuc fi 13511be35a1SLionel Sambuc 13611be35a1SLionel Sambuc # we're specifying relative paths, so rump_ffs warns - ignore. 13711be35a1SLionel Sambuc atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt 13811be35a1SLionel Sambuc copy_multiple ${numdata} 13911be35a1SLionel Sambuc 14011be35a1SLionel Sambuc if [ ${nsize} -lt ${osize} ]; then 14111be35a1SLionel Sambuc # how much data to remove so fs can be shrunk 14211be35a1SLionel Sambuc local remove=$((numdata-numdata*nsize/osize)) 14311be35a1SLionel Sambuc local dataleft=$((numdata-remove)) 14411be35a1SLionel Sambuc echo remove is $remove dataleft is $dataleft 14511be35a1SLionel Sambuc remove_multiple ${remove} 14611be35a1SLionel Sambuc fi 14711be35a1SLionel Sambuc 14811be35a1SLionel Sambuc umount mnt 149*0a6a1f1dSLionel Sambuc # Check that resize needed 150*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore resize_ffs -c -y -s ${nsize} ${IMG} 15111be35a1SLionel Sambuc atf_check -s exit:0 -o ignore resize_ffs -y -s ${nsize} ${IMG} 15211be35a1SLionel Sambuc atf_check -s exit:0 -o ignore fsck_ffs -f -n -F ${IMG} 15311be35a1SLionel Sambuc atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt 15411be35a1SLionel Sambuc if [ ${nsize} -lt ${osize} ]; then 15511be35a1SLionel Sambuc check_data_range $((remove + 1)) ${numdata} 15611be35a1SLionel Sambuc else 15711be35a1SLionel Sambuc # checking everything because we don't delete on grow 15811be35a1SLionel Sambuc check_data_range 1 ${numdata} 15911be35a1SLionel Sambuc fi 160*0a6a1f1dSLionel Sambuc # Check that no resize needed 161*0a6a1f1dSLionel Sambuc atf_check -s exit:1 -o ignore resize_ffs -c -y -s ${nsize} ${IMG} 16211be35a1SLionel Sambuc umount mnt 16311be35a1SLionel Sambuc} 164