Annotation of src/tests/sbin/resize_ffs/common.sh, Revision 1.14
1.1 riz 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
1.7 riz 27: eval "${name}_head() { \
1.11 riz 28: atf_set "require.user" "root" ; \
1.13 joerg 29: atf_set "require.progs" "rump_ffs" ; \
1.7 riz 30: }"
1.1 riz 31: eval "${name}_body() { \
32: ${check_function} " "${@}" "; \
33: }"
34: eval "${name}_cleanup() { \
1.11 riz 35: umount -f mnt ; \
36: : reset error ; \
1.1 riz 37: }"
38: }
39:
40: # Used to declare the atf goop for a test expected to fail.
41: test_case_xfail()
42: {
43: local name="${1}"; shift
44: local reason="${1}"; shift
45: local check_function="${1}"; shift
46:
47: atf_test_case "${name}" cleanup
1.12 njoly 48: eval "${name}_head() { \
49: atf_set "require.user" "root" ; \
50: }"
1.1 riz 51: eval "${name}_body() { \
52: atf_expect_fail "${reason}" ; \
53: ${check_function} " "${@}" "; \
54: }"
55: eval "${name}_cleanup() { \
1.3 pooka 56: umount -f mnt ; \
1.4 pooka 57: : reset error ; \
1.1 riz 58: }"
59: }
60:
61: # copy_data requires the mount already done; makes one copy of the test data
62: copy_data ()
63: {
1.11 riz 64: uudecode -p ${TDBASE64} | (cd mnt; tar xzf - -s/testdata/TD$1/)
1.1 riz 65: }
66:
67: copy_multiple ()
68: {
69: local i
1.9 riz 70: for i in $(seq $1); do
1.1 riz 71: copy_data $i
72: done
73: }
74:
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 ()
78: {
1.11 riz 79: rm -rf mnt/TD$1
1.1 riz 80: }
81:
82: remove_multiple ()
83: {
84: local i
1.9 riz 85: for i in $(seq $1); do
1.1 riz 86: remove_data $i
87: done
88: }
89:
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 ()
93: {
1.11 riz 94: (cd mnt/TD$1 && md5 *) > TD$1.md5
95: atf_check diff -u ${GOODMD5} TD$1.md5
1.1 riz 96: }
97:
98: # supply begin and end arguments
99: check_data_range ()
100: {
101: local i
1.9 riz 102: for i in $(seq $1 $2); do
1.1 riz 103: check_data $i
104: done
105: }
1.5 riz 106:
107:
108: resize_ffs()
109: {
1.6 riz 110: echo "in resize_ffs:" ${@}
1.5 riz 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
1.11 riz 118: mkdir -p mnt
1.5 riz 119: echo "bs is ${bs} numdata is ${numdata}"
1.6 riz 120: echo "****resizing fs with blocksize ${bs}"
1.5 riz 121:
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"
127: fi
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}
134: fi
135:
136: # we're specifying relative paths, so rump_ffs warns - ignore.
1.11 riz 137: atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt
1.5 riz 138: copy_multiple ${numdata}
139:
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}
146: fi
147:
1.11 riz 148: umount mnt
1.14 ! chopps 149: # Check that resize needed
! 150: atf_check -s exit:0 -o ignore resize_ffs -c -y -s ${nsize} ${IMG}
1.5 riz 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}
1.11 riz 153: atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt
1.5 riz 154: if [ ${nsize} -lt ${osize} ]; then
1.8 riz 155: check_data_range $((remove + 1)) ${numdata}
156: else
1.5 riz 157: # checking everything because we don't delete on grow
1.8 riz 158: check_data_range 1 ${numdata}
1.5 riz 159: fi
1.14 ! chopps 160: # Check that no resize needed
! 161: atf_check -s exit:1 -o ignore resize_ffs -c -y -s ${nsize} ${IMG}
1.11 riz 162: umount mnt
1.5 riz 163: }
CVSweb <webmaster@jp.NetBSD.org>