]> git.ipfire.org Git - thirdparty/mdadm.git/blob - test
Increase minimum chunk size in testsuite to 64kB
[thirdparty/mdadm.git] / test
1 #!/bin/sh
2 #
3 # run test suite for mdadm
4 user=`id -un`
5 if [ " $user" != " root" ]
6 then echo >&2 "test: testing can only be done as 'root'."
7 exit 1;
8 fi
9
10 prefix='[0-9][0-9]'
11
12 dir=`pwd`
13 mdadm=$dir/mdadm
14 if [ \! -x $mdadm ]
15 then
16 echo >&2 "test: $mdadm isn't usable."
17 fi
18
19 # Check whether to run multipath tests
20 modprobe multipath 2> /dev/null
21 if grep -s 'Personalities : .*multipath' > /dev/null /proc/mdstat ; then
22 MULTIPATH="yes"
23 fi
24
25 # assume md0, md1, md2 exist in /dev
26 md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
27 mdp0=/dev/md_d0
28 mdp1=/dev/md_d1
29
30 # We test mdadm on loop-back block devices.
31 # dir for storing files should be settable by command line maybe
32 targetdir=/var/tmp
33 size=20000
34 # super0, round down to multiple of 64 and substract 64
35 mdsize0=19904
36 # super00 is nested, subtract 128
37 mdsize00=19840
38 # super1.0 round down to multiple of 2, subtract 8
39 mdsize1=19992
40 mdsize1a=19988
41 mdsize12=19988
42 # super1.2 for linear: round to multiple of 2, subtract 4
43 mdsize1_l=19996
44 mdsize2_l=19996
45 # subtract another 4 for bitmaps
46 mdsize1b=19988
47 mdsize11=19992
48 mdsize11a=19456
49 mdsize12=19988
50
51 # ddf needs bigger devices as 32Meg is reserved!
52 ddfsize=65536
53
54 config=/tmp/mdadm.conf
55
56 cleanup() {
57 udevadm settle
58 $mdadm -Ssq 2> /dev/null
59 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
60 do
61 losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
62 rm -f /dev/disk/by-path/loop*
63 done
64 }
65
66 trap cleanup 0 1 2 3 15
67
68 devlist=
69 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
70 do
71 sz=$size
72 if [ $d -gt 7 ]; then sz=$ddfsize ; fi
73 [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
74 [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
75 if [ $d -eq 7 ]
76 then
77 losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
78 else
79 losetup /dev/loop$d $targetdir/mdtest$d
80 fi
81 eval dev$d=/dev/loop$d
82 eval file$d=$targetdir/mdtest$d
83 eval devlist=\"\$devlist \$dev$d\"
84 #" <-- add this quote to un-confuse vim syntax highlighting
85 done
86 path0=$dev6
87 path1=$dev7
88
89 ulimit -c unlimited
90 [ -f /proc/mdstat ] || modprobe md_mod
91 echo 2000 > /proc/sys/dev/raid/speed_limit_max
92 echo 0 > /sys/module/md_mod/parameters/start_ro
93
94 # mdadm always adds --quiet, and we want to see any unexpected messages
95 mdadm() {
96 rm -f $targetdir/stderr
97 case $* in
98 *-S* ) udevadm settle;;
99 esac
100 case $* in
101 *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
102 * ) $mdadm 2> $targetdir/stderr --quiet "$@"
103 esac
104 rv=$?
105 case $* in
106 *-S* ) udevadm settle;;
107 esac
108 cat >&2 $targetdir/stderr
109 return $rv
110 }
111
112 # check various things
113 check() {
114 case $1 in
115 spares )
116 spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
117 if [ $spares -ne $2 ]
118 then
119 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
120 fi
121 ;;
122 raid* | linear )
123 grep -s "active $1 " /proc/mdstat > /dev/null || {
124 echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
125 ;;
126 resync | recovery | reshape)
127 sleep 0.5
128 grep -s $1 /proc/mdstat > /dev/null || {
129 echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
130 ;;
131
132 nosync )
133 sleep 0.5
134 if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then
135 echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
136 fi
137 ;;
138
139 wait )
140 sleep 0.1
141 while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat
142 do sleep 2;
143 done
144 ;;
145
146 state )
147 grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
148 echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
149 sleep 0.5
150 ;;
151
152 bitmap )
153 grep -s bitmap > /dev/null /proc/mdstat || {
154 echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
155 ;;
156 nobitmap )
157 if grep -s "bitmap" > /dev/null /proc/mdstat
158 then
159 echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
160 fi
161 ;;
162
163 * ) echo >&2 ERROR unknown check $1 ; exit 1;
164 esac
165 }
166
167 no_errors() {
168 if [ -s $targetdir/stderr ]
169 then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2;
170 fi
171 }
172 # basic device test
173
174 testdev() {
175 udevadm settle
176 dev=$1
177 cnt=$2
178 dvsize=$3
179 chunk=$4
180 if [ -z "$5" ]; then
181 mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
182 fi
183 dsize=$[dvsize/chunk]
184 dsize=$[dsize*chunk]
185 rasize=$[dsize*2*cnt]
186 # rasize is in sectors
187 if [ -n "$DEV_ROUND_K" ]; then
188 rasize=$[rasize/DEV_ROUND_K/2]
189 rasize=$[rasize*DEV_ROUND_K*2]
190 fi
191 if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
192 _sz=`/sbin/blockdev --getsize $dev`
193 if [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ]
194 then
195 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
196 exit 1
197 fi
198 }
199
200 rotest() {
201 dev=$1
202 fsck -fn $dev >&2
203 }
204
205 do_test() {
206 _script=$1
207 if [ -f "$_script" ]
208 then
209 rm -f $targetdir/stderr
210 # stop all arrays, just incase some script left an array active.
211 $mdadm -Ssq 2> /dev/null
212 mdadm --zero $devlist 2> /dev/null
213 mdadm --zero $devlist 2> /dev/null
214 # source script in a subshell, so it has access to our
215 # namespace, but cannot change it.
216 echo -ne "$_script... "
217 if ( set -ex ; . $_script ) 2> $targetdir/log
218 then echo "succeeded"
219 else echo "FAILED - see $targetdir/log for details"
220 exit 1
221 fi
222 fi
223 }
224
225 do_help() {
226 echo "Usage: "
227 echo " $0 [--tests=<test1,test2,..>] [--disable-multipath] [setup] [prefix]"
228 }
229
230 parse_args() {
231 for i in $*
232 do
233 case $i in
234 [0-9]*)
235 prefix=$i
236 ;;
237 setup)
238 echo "mdadm test environment setup"
239 trap 0; exit 0
240 ;;
241 --tests=*)
242 TESTLIST=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
243 ;;
244 --disable-multipath)
245 unset MULTIPATH
246 ;;
247 --help)
248 do_help
249 exit 0;
250 ;;
251 -*)
252 echo " $0: Unknown argument: $i"
253 do_help
254 exit 0;
255 ;;
256 esac
257 done
258 }
259
260 parse_args $@
261
262 if [ "x$TESTLIST" != "x" ]; then
263 for script in $TESTLIST
264 do
265 do_test tests/$script
266 done
267 else
268 for script in tests/$prefix tests/$prefix*[^~]
269 do
270 do_test $script
271 done
272 fi
273 exit 0