]> git.ipfire.org Git - thirdparty/mdadm.git/blob - test
managemon: fix typo affecting incrmental assembly.
[thirdparty/mdadm.git] / test
1 #!/bin/bash
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 testdir="tests"
20 logdir="$testdir/logs"
21 logsave=0
22 exitonerror=1
23
24 echo "Testing on linux-$(uname -r) kernel"
25
26 # Check whether to run multipath tests
27 modprobe multipath 2> /dev/null
28 if grep -s 'Personalities : .*multipath' > /dev/null /proc/mdstat ; then
29 MULTIPATH="yes"
30 fi
31 INTEGRITY=yes
32
33 # assume md0, md1, md2 exist in /dev
34 md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
35 mdp0=/dev/md_d0
36 mdp1=/dev/md_d1
37
38 # We test mdadm on loop-back block devices.
39 # dir for storing files should be settable by command line maybe
40 targetdir=/var/tmp
41 size=20000
42 # super0, round down to multiple of 64 and substract 64
43 mdsize0=19904
44 # super00 is nested, subtract 128
45 mdsize00=19840
46 # super1.0 round down to multiple of 2, subtract 8
47 mdsize1=19992
48 mdsize1a=19988
49 mdsize12=19988
50 # super1.2 for linear: round to multiple of 2, subtract 4
51 mdsize1_l=19996
52 mdsize2_l=19996
53 # subtract another 4 for bitmaps
54 mdsize1b=19988
55 mdsize11=19992
56 mdsize11a=19456
57 mdsize12=19988
58
59 # ddf needs bigger devices as 32Meg is reserved!
60 ddfsize=65536
61
62 config=/tmp/mdadm.conf
63
64 cleanup() {
65 udevadm settle
66 $mdadm -Ssq 2> /dev/null
67 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
68 do
69 losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
70 rm -f /dev/disk/by-path/loop*
71 done
72 }
73
74 ctrl_c() {
75 exitonerror=1
76 }
77
78 do_setup() {
79 trap cleanup 0 1 3 15
80 trap ctrl_c 2
81
82 devlist=
83 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
84 do
85 sz=$size
86 if [ $d -gt 7 ]; then sz=$ddfsize ; fi
87 [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
88 [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
89 if [ $d -eq 7 ]
90 then
91 losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
92 else
93 losetup /dev/loop$d $targetdir/mdtest$d
94 fi
95 eval dev$d=/dev/loop$d
96 eval file$d=$targetdir/mdtest$d
97 eval devlist=\"\$devlist \$dev$d\"
98 eval devlist$d=\"\$devlist\"
99 #" <-- add this quote to un-confuse vim syntax highlighting
100 done
101 path0=$dev6
102 path1=$dev7
103
104 ulimit -c unlimited
105 [ -f /proc/mdstat ] || modprobe md_mod
106 echo 2000 > /proc/sys/dev/raid/speed_limit_max
107 echo 0 > /sys/module/md_mod/parameters/start_ro
108 }
109
110 # mdadm always adds --quiet, and we want to see any unexpected messages
111 mdadm() {
112 rm -f $targetdir/stderr
113 case $* in
114 *-S* ) udevadm settle;;
115 esac
116 case $* in
117 *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
118 * ) $mdadm 2> $targetdir/stderr --quiet "$@"
119 esac
120 rv=$?
121 case $* in
122 *-S* ) udevadm settle;;
123 esac
124 cat >&2 $targetdir/stderr
125 return $rv
126 }
127
128 # check various things
129 check() {
130 case $1 in
131 spares )
132 spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
133 if [ $spares -ne $2 ]
134 then
135 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
136 fi
137 ;;
138 raid* | linear )
139 grep -s "active $1 " /proc/mdstat > /dev/null || {
140 echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
141 ;;
142 algorithm )
143 grep -s " algorithm $2 " /proc/mdstat > /dev/null || {
144 echo >&2 "ERROR algorithm $2 not found"; cat /proc/mdstat; exit 1;}
145 ;;
146 resync | recovery | reshape)
147 sleep 0.5
148 grep -s $1 /proc/mdstat > /dev/null || {
149 echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
150 ;;
151
152 nosync )
153 sleep 0.5
154 if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then
155 echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
156 fi
157 ;;
158
159 wait )
160 p=`cat /proc/sys/dev/raid/speed_limit_max`
161 echo 2000000 > /proc/sys/dev/raid/speed_limit_max
162 sleep 0.1
163 while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat
164 do sleep 0.5;
165 done
166 echo $p > /proc/sys/dev/raid/speed_limit_max
167 ;;
168
169 state )
170 grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
171 echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
172 sleep 0.5
173 ;;
174
175 bitmap )
176 grep -s bitmap > /dev/null /proc/mdstat || {
177 echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
178 ;;
179 nobitmap )
180 if grep -s "bitmap" > /dev/null /proc/mdstat
181 then
182 echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
183 fi
184 ;;
185
186 * ) echo >&2 ERROR unknown check $1 ; exit 1;
187 esac
188 }
189
190 no_errors() {
191 if [ -s $targetdir/stderr ]
192 then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2;
193 fi
194 }
195 # basic device test
196
197 testdev() {
198 udevadm settle
199 dev=$1
200 cnt=$2
201 dvsize=$3
202 chunk=$4
203 if [ -z "$5" ]; then
204 mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
205 fi
206 dsize=$[dvsize/chunk]
207 dsize=$[dsize*chunk]
208 rasize=$[dsize*2*cnt]
209 # rasize is in sectors
210 if [ -n "$DEV_ROUND_K" ]; then
211 rasize=$[rasize/DEV_ROUND_K/2]
212 rasize=$[rasize*DEV_ROUND_K*2]
213 fi
214 if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
215 _sz=`/sbin/blockdev --getsize $dev`
216 if [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ]
217 then
218 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
219 exit 1
220 fi
221 }
222
223 fast_sync() {
224 echo 200000 > /proc/sys/dev/raid/speed_limit_max
225 }
226
227 rotest() {
228 dev=$1
229 fsck -fn $dev >&2
230 }
231
232 do_test() {
233 _script=$1
234 _basename=`basename $_script`
235 if [ -f "$_script" ]
236 then
237 rm -f $targetdir/stderr
238 # stop all arrays, just incase some script left an array active.
239 $mdadm -Ssq 2> /dev/null
240 mdadm --zero $devlist 2> /dev/null
241 mdadm --zero $devlist 2> /dev/null
242 # this might have been reset: restore the default.
243 echo 2000 > /proc/sys/dev/raid/speed_limit_max
244 # source script in a subshell, so it has access to our
245 # namespace, but cannot change it.
246 echo -ne "$_script... "
247 if ( set -ex ; . $_script ) &> $targetdir/log
248 then
249 echo "succeeded"
250 _fail=0
251 else
252 log=log
253 cat $targetdir/stderr >> $targetdir/log
254 if [ $exitonerror == 0 ]; then
255 log=log-`basename $_script`
256 mv $targetdir/log $targetdir/$log
257 fi
258 echo "FAILED - see $targetdir/$log for details"
259 _fail=1
260 fi
261 if [ "$savelogs" == "1" ]; then
262 cp $targetdir/log $logdir/$_basename.log
263 fi
264 if [ "$_fail" == "1" -a "$exitonerror" == "1" ]; then
265 exit 1
266 fi
267 fi
268 }
269
270 do_help() {
271 echo "Usage: $0 [options]"
272 echo " Options:"
273 echo " --tests=<test1,test2,..> Comma separated list of tests to run"
274 echo " --disable-multipath Disable any tests involving multipath"
275 echo " --disable-integrity Disable slow tests of RAID[56] consistency"
276 echo " --logdir=<directory> Directory to save logfiles in"
277 echo " --save-logs Save all logs in <logdir>"
278 echo " --keep-going Don't stop on error, ie. run all tests"
279 echo " setup Setup test environment and exit"
280 echo " cleanup Cleanup test environment"
281 echo " <prefix> Run tests with <prefix>"
282 }
283
284 parse_args() {
285 for i in $*
286 do
287 case $i in
288 [0-9]*)
289 prefix=$i
290 ;;
291 setup)
292 echo "mdadm test environment setup"
293 do_setup
294 trap 0; exit 0
295 ;;
296 cleanup)
297 cleanup
298 exit 0
299 ;;
300 --tests=*)
301 TESTLIST=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
302 ;;
303 --logdir=*)
304 logdir=`expr "x$i" : 'x[^=]*=\(.*\)'`
305 ;;
306 --save-logs)
307 savelogs=1
308 if [ ! -d $logdir ] ; then
309 mkdir $logdir
310 if [ $? -ne 0 ] ; then
311 exit 1;
312 fi
313 fi
314 ;;
315 --keep-going | --no-error)
316 exitonerror=0
317 ;;
318 --disable-multipath)
319 unset MULTIPATH
320 ;;
321 --disable-integrity)
322 unset INTEGRITY
323 ;;
324 --help)
325 do_help
326 exit 0;
327 ;;
328 -*)
329 echo " $0: Unknown argument: $i"
330 do_help
331 exit 0;
332 ;;
333 esac
334 done
335 }
336
337 parse_args $@
338
339 do_setup
340
341 if [ "$savelogs" == "1" ]; then
342 echo "Saving logs to $logdir"
343 fi
344
345 if [ "x$TESTLIST" != "x" ]; then
346 for script in $TESTLIST
347 do
348 do_test $testdir/$script
349 done
350 else
351 for script in $testdir/$prefix $testdir/$prefix*[^~]
352 do
353 do_test $script
354 done
355 fi
356 exit 0