Home | History | Annotate | Line # | Download | only in resize_ffs
common.sh revision 1.8
      1 
      2 # Common settings and functions for the various resize_ffs tests.
      3 # 
      4 
      5 # called from atf_init_test_cases
      6 setupvars()
      7 {
      8 	IMG=fsimage
      9 	TDBASE64=$(atf_get_srcdir)/testdata.tar.gz.base64
     10 	GOODMD5=$(atf_get_srcdir)/testdata.md5
     11 	# set BYTESWAP to opposite-endian.
     12 	if [ $(sysctl -n hw.byteorder) = "1234" ]; then
     13 		BYTESWAP=be
     14 	else
     15 		BYTESWAP=le
     16 	fi
     17 }
     18 
     19 # test_case() taken from the tests/ipf/h_common.sh
     20 # Used to declare the atf goop for a test.
     21 test_case()
     22 {
     23 	local name="${1}"; shift
     24 	local check_function="${1}"; shift
     25 
     26 	atf_test_case "${name}" cleanup
     27 	eval "${name}_head() { \
     28 		atf_set "require.user" "root" ; \
     29 	}"
     30 	eval "${name}_body() { \
     31 		${check_function} " "${@}" "; \
     32 	}"
     33 	eval "${name}_cleanup() { \
     34 		umount -f mnt  ; \
     35 		: reset error ; \
     36 	}"
     37 }
     38 
     39 # Used to declare the atf goop for a test expected to fail.
     40 test_case_xfail()
     41 {
     42 	local name="${1}"; shift
     43 	local reason="${1}"; shift
     44 	local check_function="${1}"; shift
     45 
     46 	atf_test_case "${name}" cleanup
     47 	eval "${name}_body() { \
     48 		atf_expect_fail "${reason}" ; \
     49 		${check_function} " "${@}" "; \
     50 	}"
     51 	eval "${name}_cleanup() { \
     52 		umount -f mnt  ; \
     53 		: reset error ; \
     54 	}"
     55 }
     56 
     57 # copy_data requires the mount already done;  makes one copy of the test data
     58 copy_data ()
     59 {
     60 	uudecode -p ${TDBASE64} | (cd mnt; tar xzf - -s/testdata/TD$1/)
     61 }
     62 
     63 copy_multiple ()
     64 {
     65 	local i
     66 	for i in $(jot $1); do
     67 		copy_data $i
     68 	done
     69 }
     70 
     71 # remove_data removes one directory worth of test data; the purpose
     72 # is to ensure data exists near the end of the fs under test.
     73 remove_data ()
     74 {
     75 	rm -rf mnt/TD$1
     76 }
     77 
     78 remove_multiple ()
     79 {
     80 	local i
     81 	for i in $(jot $1); do
     82 		remove_data $i
     83 	done
     84 }
     85 
     86 # verify that the data in a particular directory is still OK
     87 # generated md5 file doesn't need explicit cleanup thanks to ATF
     88 check_data ()
     89 {
     90 	(cd mnt/TD$1 && md5 *) > TD$1.md5
     91 	atf_check diff -u ${GOODMD5} TD$1.md5
     92 }
     93 
     94 # supply begin and end arguments
     95 check_data_range ()
     96 {
     97 	local i
     98 	for i in $(jot $(($2-$1+1)) $1); do
     99 		check_data $i
    100 	done
    101 }
    102 
    103 
    104 resize_ffs()
    105 {
    106 	echo "in resize_ffs:" ${@}
    107 	local bs=$1
    108 	local fragsz=$2
    109 	local osize=$3
    110 	local nsize=$4
    111 	local fslevel=$5
    112 	local numdata=$6
    113 	local swap=$7
    114 	mkdir -p mnt
    115 	echo "bs is ${bs} numdata is ${numdata}"
    116 	echo "****resizing fs with blocksize ${bs}"
    117 
    118 	# we want no more than 16K/inode to allow test files to copy.
    119 	local fpi=$((fragsz * 4))
    120 	local i
    121 	if [ $fpi -gt 16384 ]; then
    122 		i="-i 16384"
    123 	fi
    124 	if [ x$swap != x ]; then
    125 		newfs -B ${BYTESWAP} -O${fslevel} -b ${bs} -f ${fragsz} \
    126 			-s ${osize} ${i} -F ${IMG}
    127 	else
    128 		newfs -O${fslevel} -b ${bs} -f ${fragsz} -s ${osize} ${i} \
    129 			-F ${IMG}
    130 	fi
    131 
    132 	# we're specifying relative paths, so rump_ffs warns - ignore.
    133 	atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt
    134 	copy_multiple ${numdata}
    135 
    136 	if [ ${nsize} -lt ${osize} ]; then
    137 	    # how much data to remove so fs can be shrunk
    138 	    local remove=$((numdata-numdata*nsize/osize))
    139 	    local dataleft=$((numdata-remove))
    140 	    echo remove is $remove dataleft is $dataleft
    141 	    remove_multiple ${remove}
    142 	fi
    143 
    144 	umount mnt
    145 	atf_check -s exit:0 -o ignore resize_ffs -y -s ${nsize} ${IMG}
    146 	atf_check -s exit:0 -o ignore fsck_ffs -f -n -F ${IMG}
    147 	atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt
    148 	if [ ${nsize} -lt ${osize} ]; then
    149 	    check_data_range $((remove + 1)) ${numdata}
    150 	else
    151 	    # checking everything because we don't delete on grow
    152 	    check_data_range 1 ${numdata}
    153 	fi
    154 	umount mnt
    155 }
    156