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