3 # run test suite for mdadm
5 if [ " $user" != " root" ]
6 then echo >&2 "test: testing can only be done as 'root'."
19 echo >&2 "test: $mdadm isn't usable."
22 # assume md0, md1, md2 exist in /dev
23 md0
=/dev
/md0 md1
=/dev
/md1 md2
=/dev
/md2
25 # We test mdadm on loop-back block devices.
26 # dir for storing files should be settable by command line maybe
36 for d
in 0 1 2 3 4 5 6 7
38 losetup
-d /dev
/loop
$d ; # rm -f $targetdir/mdtest$d
42 trap cleanup
0 1 2 3 15
45 for d
in 0 1 2 3 4 5 6 7
47 [ -f $targetdir/mdtest
$d ] ||
dd if=/dev
/zero of
=$targetdir/mdtest
$d count
=$size bs
=1K
> /dev
/null
2>&1
48 [ -b /dev
/loop
$d ] || mknod
/dev
/loop
$d b
7 $d
51 losetup
/dev
/loop
$d $targetdir/mdtest6
# for multipath use
53 losetup
/dev
/loop
$d $targetdir/mdtest
$d
55 eval dev
$d=/dev
/loop
$d
56 eval file$d=$targetdir/mdtest
$d
57 eval devlist
=\"\
$devlist \
$dev$d\"
62 if [ " $1" = " setup" ]
66 # mdadm always adds --quiet, and we want to see any unexpected messages
68 rm -f $targetdir/stderr
70 *-C* ) $mdadm 2> $targetdir/stderr
--quiet "$@" --auto=yes;;
71 * ) $mdadm 2> $targetdir/stderr
--quiet "$@"
73 cat >&2 $targetdir/stderr
76 # check various things
80 spares
=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
83 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
87 grep -s "active $1 " /proc
/mdstat
> /dev
/null ||
{
88 echo >&2 "ERROR active $1 not found" ; cat /proc
/mdstat
; exit 1;}
92 grep -s $1 /proc
/mdstat
> /dev
/null ||
{
93 echo >&2 ERROR no
$1 happening
; cat /proc
/mdstat
; exit 1; }
98 if grep -s 're[synccovery]* =' > /dev
/null
/proc
/mdstat
; then
99 echo >&2 "ERROR resync or recovery is happening!"; cat /proc
/mdstat
; exit 1;
105 while grep 're[synccovery]* =' > /dev
/null
/proc
/mdstat
111 grep -s "blocks.*\[$2\]\$" /proc
/mdstat
> /dev
/null ||
{
112 echo >&2 "ERROR state $2 not found!"; cat /proc
/mdstat
; exit 1; }
117 grep -s bitmap
> /dev
/null
/proc
/mdstat ||
{
118 echo >&2 ERROR no bitmap
; cat /proc
/mdstat
; exit 1; }
121 if grep -s "bitmap" > /dev
/null
/proc
/mdstat
123 echo >&2 ERROR bitmap present
; cat /proc
/mdstat
; exit 1;
127 * ) echo >&2 ERROR unknown check
$1 ; exit 1;
132 if [ -s $targetdir/stderr
]
133 then echo Bad errors from mdadm
: ; cat $targetdir/stderr
; exit 2;
143 mkfs
-j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
144 dsize
=$
[dvsize
/chunk
]
146 rasize
=$
[dsize
*2*cnt
]
147 if [ $rasize -ne `/sbin/blockdev --getsize $dev` ]
149 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize $dev`"
161 for script in tests
/$prefix tests
/$prefix*[^~
]
165 rm -f $targetdir/stderr
166 # source script in a subshell, so it has access to our
167 # namespace, but cannot change it.
168 if ( set -ex ; .
$script ) 2> $targetdir/log
169 then echo "$script succeeded"
170 else cat $targetdir/log
; cat $targetdir/stderr
171 echo "$script failed"