]> git.ipfire.org Git - thirdparty/mdadm.git/blame - test
Skip clustered devices in incremental
[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
dd0468af
N
97 # make sure there are no loop devices remaining.
98 # udev started things can sometimes prevent them being stopped
99 # immediately
100 while grep loop /proc/partitions > /dev/null 2>&1
101 do
102 losetup -d /dev/loop[0-9]* 2> /dev/null
103 sleep 1
104 done
572d7091 105 devlist=
840ad583 106 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
572d7091
JS
107 do
108 sz=$size
109 if [ $d -gt 7 ]; then sz=$ddfsize ; fi
7d8a70bf 110 case $DEVTYPE in
111 loop)
112 [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
113 [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
114 if [ $d -eq 7 ]
115 then
116 losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
117 else
118 losetup /dev/loop$d $targetdir/mdtest$d
119 fi
120 eval dev$d=/dev/loop$d
121 eval file$d=$targetdir/mdtest$d
122 ;;
123 lvm)
124 unset MULTIPATH
125 eval dev$d=/dev/mapper/${LVM_VOLGROUP}-mdtest$d
126 if ! lvcreate --quiet -L ${sz}K -n mdtest$d $LVM_VOLGROUP; then
127 trap '' 0 # make sure lvremove is not called
128 eval echo error creating \$dev$d
129 exit 129
130 fi
131 ;;
132 ram)
133 unset MULTIPATH
134 eval dev$d=/dev/ram$d
135 ;;
136 esac
572d7091 137 eval devlist=\"\$devlist \$dev$d\"
aef14b9e 138 eval devlist$d=\"\$devlist\"
4b7a9ee3 139 #" <-- add this quote to un-confuse vim syntax highlighting
572d7091
JS
140 done
141 path0=$dev6
142 path1=$dev7
c13c45e9 143
572d7091
JS
144 ulimit -c unlimited
145 [ -f /proc/mdstat ] || modprobe md_mod
146 echo 2000 > /proc/sys/dev/raid/speed_limit_max
147 echo 0 > /sys/module/md_mod/parameters/start_ro
148}
0aa389dc 149
dab6685f
NB
150# mdadm always adds --quiet, and we want to see any unexpected messages
151mdadm() {
beae1dfe 152 rm -f $targetdir/stderr
045495a3 153 case $* in
ddaf4ce2 154 *-S* ) udevadm settle;;
045495a3 155 esac
9860f271 156 case $* in
bf4fb153
NB
157 *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
158 * ) $mdadm 2> $targetdir/stderr --quiet "$@"
9860f271 159 esac
dd4ae23a 160 rv=$?
019ca1e1
N
161 case $* in
162 *-S* ) udevadm settle;;
163 esac
bf4fb153 164 cat >&2 $targetdir/stderr
dd4ae23a 165 return $rv
dab6685f
NB
166}
167
168# check various things
169check() {
170 case $1 in
308e1801
NB
171 spares )
172 spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
173 if [ $spares -ne $2 ]
174 then
175 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
176 fi
177 ;;
dab6685f
NB
178 raid* | linear )
179 grep -s "active $1 " /proc/mdstat > /dev/null || {
4f8a3e5b 180 echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
dab6685f 181 ;;
35698c6e
N
182 algorithm )
183 grep -s " algorithm $2 " /proc/mdstat > /dev/null || {
184 echo >&2 "ERROR algorithm $2 not found"; cat /proc/mdstat; exit 1;}
185 ;;
0aa389dc 186 resync | recovery | reshape)
0ba1565f 187 sleep 0.5
dab6685f 188 grep -s $1 /proc/mdstat > /dev/null || {
4f8a3e5b 189 echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
dab6685f 190 ;;
4f8a3e5b 191
dab6685f
NB
192 nosync )
193 sleep 0.5
0d711ba4 194 if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then
4f8a3e5b 195 echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
dab6685f
NB
196 fi
197 ;;
4f8a3e5b 198
dab6685f 199 wait )
6fd2a36f
N
200 p=`cat /proc/sys/dev/raid/speed_limit_max`
201 echo 2000000 > /proc/sys/dev/raid/speed_limit_max
dab6685f 202 sleep 0.1
4a859abd 203 while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat /sys/block/md*/md/sync_action
6fd2a36f 204 do sleep 0.5;
dab6685f 205 done
6fd2a36f 206 echo $p > /proc/sys/dev/raid/speed_limit_max
dab6685f 207 ;;
4f8a3e5b 208
dab6685f
NB
209 state )
210 grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
4f8a3e5b 211 echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
dab6685f
NB
212 sleep 0.5
213 ;;
fe80f49b
NB
214
215 bitmap )
216 grep -s bitmap > /dev/null /proc/mdstat || {
4f8a3e5b 217 echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
fe80f49b
NB
218 ;;
219 nobitmap )
4f8a3e5b 220 if grep -s "bitmap" > /dev/null /proc/mdstat
fe80f49b 221 then
4f8a3e5b 222 echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
fe80f49b
NB
223 fi
224 ;;
4f8a3e5b 225
dab6685f
NB
226 * ) echo >&2 ERROR unknown check $1 ; exit 1;
227 esac
228}
229
bf4fb153
NB
230no_errors() {
231 if [ -s $targetdir/stderr ]
232 then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2;
233 fi
234}
dab6685f
NB
235# basic device test
236
237testdev() {
ba624124 238 udevadm settle
dab6685f
NB
239 dev=$1
240 cnt=$2
241 dvsize=$3
242 chunk=$4
487e48af
N
243 if [ -z "$5" ]; then
244 mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
245 fi
dab6685f
NB
246 dsize=$[dvsize/chunk]
247 dsize=$[dsize*chunk]
81074c9f 248 rasize=$[dsize*2*cnt]
6636f0ef
N
249 # rasize is in sectors
250 if [ -n "$DEV_ROUND_K" ]; then
251 rasize=$[rasize/DEV_ROUND_K/2]
252 rasize=$[rasize*DEV_ROUND_K*2]
253 fi
7801ac20 254 if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
974e0395
N
255 _sz=`/sbin/blockdev --getsize $dev`
256 if [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ]
dab6685f 257 then
974e0395 258 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
dab6685f
NB
259 exit 1
260 fi
261}
262
6fd2a36f
N
263fast_sync() {
264 echo 200000 > /proc/sys/dev/raid/speed_limit_max
265}
266
c13c45e9
NB
267rotest() {
268 dev=$1
269 fsck -fn $dev >&2
270}
271
4e5ce543
JS
272do_test() {
273 _script=$1
60381555 274 _basename=`basename $_script`
4e5ce543 275 if [ -f "$_script" ]
34163fc7 276 then
4e5ce543
JS
277 rm -f $targetdir/stderr
278 # stop all arrays, just incase some script left an array active.
279 $mdadm -Ssq 2> /dev/null
280 mdadm --zero $devlist 2> /dev/null
281 mdadm --zero $devlist 2> /dev/null
6fd2a36f
N
282 # this might have been reset: restore the default.
283 echo 2000 > /proc/sys/dev/raid/speed_limit_max
4e5ce543
JS
284 # source script in a subshell, so it has access to our
285 # namespace, but cannot change it.
286 echo -ne "$_script... "
45e34015 287 if ( set -ex ; . $_script ) &> $targetdir/log
60381555
JS
288 then
289 echo "succeeded"
290 _fail=0
291 else
1dc837e4 292 log=log
855a3539 293 cat $targetdir/stderr >> $targetdir/log
1dc837e4
N
294 if [ $exitonerror == 0 ]; then
295 log=log-`basename $_script`
296 mv $targetdir/log $targetdir/$log
297 fi
298 echo "FAILED - see $targetdir/$log for details"
60381555
JS
299 _fail=1
300 fi
301 if [ "$savelogs" == "1" ]; then
302 cp $targetdir/log $logdir/$_basename.log
303 fi
b8e91a32 304 if [ "$_fail" == "1" -a "$exitonerror" == "1" ]; then
4e5ce543
JS
305 exit 1
306 fi
34163fc7 307 fi
4e5ce543
JS
308}
309
310do_help() {
0aaecb43
JS
311 echo "Usage: $0 [options]"
312 echo " Options:"
313 echo " --tests=<test1,test2,..> Comma separated list of tests to run"
314 echo " --disable-multipath Disable any tests involving multipath"
bde085f4 315 echo " --disable-integrity Disable slow tests of RAID[56] consistency"
0aaecb43
JS
316 echo " --logdir=<directory> Directory to save logfiles in"
317 echo " --save-logs Save all logs in <logdir>"
4d327173 318 echo " --keep-going Don't stop on error, ie. run all tests"
7d8a70bf 319 echo " --dev=[loop|lvm|ram] Use loop devices (default), LVM, or RAM disk"
320 echo " --volgroup=<name> LVM volume group for LVM test"
0aaecb43 321 echo " setup Setup test environment and exit"
572d7091 322 echo " cleanup Cleanup test environment"
0aaecb43 323 echo " <prefix> Run tests with <prefix>"
4e5ce543
JS
324}
325
326parse_args() {
327 for i in $*
328 do
329 case $i in
330 [0-9]*)
331 prefix=$i
332 ;;
333 setup)
334 echo "mdadm test environment setup"
572d7091 335 do_setup
4e5ce543
JS
336 trap 0; exit 0
337 ;;
572d7091
JS
338 cleanup)
339 cleanup
340 exit 0
341 ;;
4e5ce543
JS
342 --tests=*)
343 TESTLIST=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
344 ;;
60381555
JS
345 --logdir=*)
346 logdir=`expr "x$i" : 'x[^=]*=\(.*\)'`
347 ;;
348 --save-logs)
349 savelogs=1
350 if [ ! -d $logdir ] ; then
351 mkdir $logdir
352 if [ $? -ne 0 ] ; then
353 exit 1;
354 fi
355 fi
356 ;;
4d327173 357 --keep-going | --no-error)
fc092254 358 exitonerror=0
b8e91a32 359 ;;
4e5ce543
JS
360 --disable-multipath)
361 unset MULTIPATH
362 ;;
bde085f4
N
363 --disable-integrity)
364 unset INTEGRITY
365 ;;
7d8a70bf 366 --dev=loop)
367 DEVTYPE=loop
368 ;;
369 --dev=lvm)
370 DEVTYPE=lvm
371 ;;
372 --dev=ram)
373 DEVTYPE=ram
374 ;;
375 --volgroup=*)
376 LVM_VOLGROUP=`expr "x$i" : 'x[^=]*=\(.*\)'`
377 ;;
4e5ce543
JS
378 --help)
379 do_help
380 exit 0;
381 ;;
382 -*)
383 echo " $0: Unknown argument: $i"
384 do_help
385 exit 0;
386 ;;
387 esac
5e7519fa 388done
4e5ce543
JS
389}
390
391parse_args $@
392
572d7091
JS
393do_setup
394
60381555
JS
395if [ "$savelogs" == "1" ]; then
396 echo "Saving logs to $logdir"
397fi
398
4e5ce543
JS
399if [ "x$TESTLIST" != "x" ]; then
400 for script in $TESTLIST
401 do
60381555 402 do_test $testdir/$script
4e5ce543
JS
403 done
404else
60381555 405 for script in $testdir/$prefix $testdir/$prefix*[^~]
4e5ce543
JS
406 do
407 do_test $script
408 done
409fi
5e7519fa 410exit 0