etc/protocols - sync with NetBSD-8
[minix.git] / tests / sbin / resize_ffs / common.sh
blob80ebc65512530e826ea4823a367dbae73985e35d
2 # Common settings and functions for the various resize_ffs tests.
3 #
5 # called from atf_init_test_cases
6 setupvars()
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
19 # test_case() taken from the tests/ipf/h_common.sh
20 # Used to declare the atf goop for a test.
21 test_case()
23 local name="${1}"; shift
24 local check_function="${1}"; shift
26 atf_test_case "${name}" cleanup
27 eval "${name}_head() { \
28 atf_set "require.user" "root" ; \
29 atf_set "require.progs" "rump_ffs" ; \
31 eval "${name}_body() { \
32 ${check_function} " "${@}" "; \
34 eval "${name}_cleanup() { \
35 umount -f mnt ; \
36 : reset error ; \
40 # Used to declare the atf goop for a test expected to fail.
41 test_case_xfail()
43 local name="${1}"; shift
44 local reason="${1}"; shift
45 local check_function="${1}"; shift
47 atf_test_case "${name}" cleanup
48 eval "${name}_head() { \
49 atf_set "require.user" "root" ; \
51 eval "${name}_body() { \
52 atf_expect_fail "${reason}" ; \
53 ${check_function} " "${@}" "; \
55 eval "${name}_cleanup() { \
56 umount -f mnt ; \
57 : reset error ; \
61 # copy_data requires the mount already done; makes one copy of the test data
62 copy_data ()
64 uudecode -p ${TDBASE64} | (cd mnt; tar xzf - -s/testdata/TD$1/)
67 copy_multiple ()
69 local i
70 for i in $(seq $1); do
71 copy_data $i
72 done
75 # remove_data removes one directory worth of test data; the purpose
76 # is to ensure data exists near the end of the fs under test.
77 remove_data ()
79 rm -rf mnt/TD$1
82 remove_multiple ()
84 local i
85 for i in $(seq $1); do
86 remove_data $i
87 done
90 # verify that the data in a particular directory is still OK
91 # generated md5 file doesn't need explicit cleanup thanks to ATF
92 check_data ()
94 (cd mnt/TD$1 && md5 *) > TD$1.md5
95 atf_check diff -u ${GOODMD5} TD$1.md5
98 # supply begin and end arguments
99 check_data_range ()
101 local i
102 for i in $(seq $1 $2); do
103 check_data $i
104 done
108 resize_ffs()
110 echo "in resize_ffs:" ${@}
111 local bs=$1
112 local fragsz=$2
113 local osize=$3
114 local nsize=$4
115 local fslevel=$5
116 local numdata=$6
117 local swap=$7
118 mkdir -p mnt
119 echo "bs is ${bs} numdata is ${numdata}"
120 echo "****resizing fs with blocksize ${bs}"
122 # we want no more than 16K/inode to allow test files to copy.
123 local fpi=$((fragsz * 4))
124 local i
125 if [ $fpi -gt 16384 ]; then
126 i="-i 16384"
128 if [ x$swap != x ]; then
129 newfs -B ${BYTESWAP} -O${fslevel} -b ${bs} -f ${fragsz} \
130 -s ${osize} ${i} -F ${IMG}
131 else
132 newfs -O${fslevel} -b ${bs} -f ${fragsz} -s ${osize} ${i} \
133 -F ${IMG}
136 # we're specifying relative paths, so rump_ffs warns - ignore.
137 atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt
138 copy_multiple ${numdata}
140 if [ ${nsize} -lt ${osize} ]; then
141 # how much data to remove so fs can be shrunk
142 local remove=$((numdata-numdata*nsize/osize))
143 local dataleft=$((numdata-remove))
144 echo remove is $remove dataleft is $dataleft
145 remove_multiple ${remove}
148 umount mnt
149 # Check that resize needed
150 atf_check -s exit:0 -o ignore resize_ffs -c -y -s ${nsize} ${IMG}
151 atf_check -s exit:0 -o ignore resize_ffs -y -s ${nsize} ${IMG}
152 atf_check -s exit:0 -o ignore fsck_ffs -f -n -F ${IMG}
153 atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt
154 if [ ${nsize} -lt ${osize} ]; then
155 check_data_range $((remove + 1)) ${numdata}
156 else
157 # checking everything because we don't delete on grow
158 check_data_range 1 ${numdata}
160 # Check that no resize needed
161 atf_check -s exit:1 -o ignore resize_ffs -c -y -s ${nsize} ${IMG}
162 umount mnt