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}_body() { \ 28 ${check_function} " "${@}" "; \ 29 }" 30 eval "${name}_cleanup() { \ 31 umount -f mnt ; \ 32 }" 33 } 34 35 # Used to declare the atf goop for a test expected to fail. 36 test_case_xfail() 37 { 38 local name="${1}"; shift 39 local reason="${1}"; shift 40 local check_function="${1}"; shift 41 42 atf_test_case "${name}" cleanup 43 eval "${name}_body() { \ 44 atf_expect_fail "${reason}" ; \ 45 ${check_function} " "${@}" "; \ 46 }" 47 eval "${name}_cleanup() { \ 48 umount -f mnt ; \ 49 }" 50 } 51 52 # copy_data requires the mount already done; makes one copy of the test data 53 copy_data () 54 { 55 uudecode -p ${TDBASE64} | (cd mnt; tar xzf - -s/testdata/TD$1/) 56 } 57 58 copy_multiple () 59 { 60 local i 61 for i in $(jot $1); do 62 copy_data $i 63 done 64 } 65 66 # remove_data removes one directory worth of test data; the purpose 67 # is to ensure data exists near the end of the fs under test. 68 remove_data () 69 { 70 rm -rf mnt/TD$1 71 } 72 73 remove_multiple () 74 { 75 local i 76 for i in $(jot $1); do 77 remove_data $i 78 done 79 } 80 81 # verify that the data in a particular directory is still OK 82 # generated md5 file doesn't need explicit cleanup thanks to ATF 83 check_data () 84 { 85 (cd mnt/TD$1 && md5 *) > TD$1.md5 86 atf_check diff -u ${GOODMD5} TD$1.md5 87 } 88 89 # supply begin and end arguments 90 check_data_range () 91 { 92 local i 93 for i in $(jot $(($2-$1+1)) $1); do 94 check_data $i 95 done 96 } 97