3 # run test suite for mdadm
5 if [ " $user" != " root" ]
6 then echo >&2 "test: testing can only be done as 'root'."
16 echo >&2 "test: $mdadm isn't usable."
20 logdir
="$testdir/logs"
24 # Check whether to run multipath tests
25 modprobe multipath
2> /dev
/null
26 if grep -s 'Personalities : .*multipath' > /dev
/null
/proc
/mdstat
; then
30 # assume md0, md1, md2 exist in /dev
31 md0
=/dev
/md0 md1
=/dev
/md1 md2
=/dev
/md2
35 # We test mdadm on loop-back block devices.
36 # dir for storing files should be settable by command line maybe
39 # super0, round down to multiple of 64 and substract 64
41 # super00 is nested, subtract 128
43 # super1.0 round down to multiple of 2, subtract 8
47 # super1.2 for linear: round to multiple of 2, subtract 4
50 # subtract another 4 for bitmaps
56 # ddf needs bigger devices as 32Meg is reserved!
59 config
=/tmp
/mdadm.conf
63 $mdadm -Ssq 2> /dev
/null
64 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12
66 losetup
-d /dev
/loop
$d ; # rm -f $targetdir/mdtest$d
67 rm -f /dev
/disk
/by-path
/loop
*
80 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12
83 if [ $d -gt 7 ]; then sz
=$ddfsize ; fi
84 [ -f $targetdir/mdtest
$d ] ||
dd if=/dev
/zero of
=$targetdir/mdtest
$d count
=$sz bs
=1K
> /dev
/null
2>&1
85 [ -b /dev
/loop
$d ] || mknod
/dev
/loop
$d b
7 $d
88 losetup
/dev
/loop
$d $targetdir/mdtest6
# for multipath use
90 losetup
/dev
/loop
$d $targetdir/mdtest
$d
92 eval dev
$d=/dev
/loop
$d
93 eval file$d=$targetdir/mdtest
$d
94 eval devlist
=\"\
$devlist \
$dev$d\"
95 #" <-- add this quote to un-confuse vim syntax highlighting
101 [ -f /proc
/mdstat
] || modprobe md_mod
102 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
103 echo 0 > /sys
/module
/md_mod
/parameters
/start_ro
106 # mdadm always adds --quiet, and we want to see any unexpected messages
108 rm -f $targetdir/stderr
110 *-S* ) udevadm settle
;;
113 *-C* ) $mdadm 2> $targetdir/stderr
--quiet "$@" --auto=yes;;
114 * ) $mdadm 2> $targetdir/stderr
--quiet "$@"
118 *-S* ) udevadm settle
;;
120 cat >&2 $targetdir/stderr
124 # check various things
128 spares
=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
129 if [ $spares -ne $2 ]
131 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
135 grep -s "active $1 " /proc
/mdstat
> /dev
/null ||
{
136 echo >&2 "ERROR active $1 not found" ; cat /proc
/mdstat
; exit 1;}
138 resync | recovery | reshape
)
140 grep -s $1 /proc
/mdstat
> /dev
/null ||
{
141 echo >&2 ERROR no
$1 happening
; cat /proc
/mdstat
; exit 1; }
146 if grep -s -E '(resync|recovery|reshape) *=' > /dev
/null
/proc
/mdstat
; then
147 echo >&2 "ERROR resync or recovery is happening!"; cat /proc
/mdstat
; exit 1;
153 while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev
/null
/proc
/mdstat
159 grep -s "blocks.*\[$2\]\$" /proc
/mdstat
> /dev
/null ||
{
160 echo >&2 "ERROR state $2 not found!"; cat /proc
/mdstat
; exit 1; }
165 grep -s bitmap
> /dev
/null
/proc
/mdstat ||
{
166 echo >&2 ERROR no bitmap
; cat /proc
/mdstat
; exit 1; }
169 if grep -s "bitmap" > /dev
/null
/proc
/mdstat
171 echo >&2 ERROR bitmap present
; cat /proc
/mdstat
; exit 1;
175 * ) echo >&2 ERROR unknown check
$1 ; exit 1;
180 if [ -s $targetdir/stderr
]
181 then echo Bad errors from mdadm
: ; cat $targetdir/stderr
; exit 2;
193 mkfs
-j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
195 dsize
=$
[dvsize
/chunk
]
197 rasize
=$
[dsize
*2*cnt
]
198 # rasize is in sectors
199 if [ -n "$DEV_ROUND_K" ]; then
200 rasize
=$
[rasize
/DEV_ROUND_K
/2]
201 rasize
=$
[rasize
*DEV_ROUND_K
*2]
203 if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
204 _sz
=`/sbin/blockdev --getsize $dev`
205 if [ $rasize -lt $_sz -o $
[rasize
*4/5] -gt $_sz ]
207 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
219 _basename
=`basename $_script`
222 rm -f $targetdir/stderr
223 # stop all arrays, just incase some script left an array active.
224 $mdadm -Ssq 2> /dev
/null
225 mdadm
--zero $devlist 2> /dev
/null
226 mdadm
--zero $devlist 2> /dev
/null
227 # source script in a subshell, so it has access to our
228 # namespace, but cannot change it.
229 echo -ne "$_script... "
230 if ( set -ex ; .
$_script ) &> $targetdir/log
236 if [ $exitonerror == 0 ]; then
237 log
=log-
`basename $_script`
238 mv $targetdir/log
$targetdir/$log
240 echo "FAILED - see $targetdir/$log for details"
243 if [ "$savelogs" == "1" ]; then
244 cp $targetdir/log
$logdir/$_basename.log
246 if [ "$_fail" == "1" -a "$exitonerror" == "1" ]; then
253 echo "Usage: $0 [options]"
255 echo " --tests=<test1,test2,..> Comma separated list of tests to run"
256 echo " --disable-multipath Disable any tests involving multipath"
257 echo " --logdir=<directory> Directory to save logfiles in"
258 echo " --save-logs Save all logs in <logdir>"
259 echo " --keep-going Don't stop on error, ie. run all tests"
260 echo " setup Setup test environment and exit"
261 echo " cleanup Cleanup test environment"
262 echo " <prefix> Run tests with <prefix>"
273 echo "mdadm test environment setup"
282 TESTLIST
=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
285 logdir
=`expr "x$i" : 'x[^=]*=\(.*\)'`
289 if [ ! -d $logdir ] ; then
291 if [ $?
-ne 0 ] ; then
296 --keep-going |
--no-error)
307 echo " $0: Unknown argument: $i"
319 if [ "$savelogs" == "1" ]; then
320 echo "Saving logs to $logdir"
323 if [ "x$TESTLIST" != "x" ]; then
324 for script in $TESTLIST
326 do_test
$testdir/$script
329 for script in $testdir/$prefix $testdir/$prefix*[^~
]